1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

hasher: Add HASHER_BLAKE

This commit is contained in:
Saleem Rashid 2017-12-10 11:10:59 +00:00 committed by Pavol Rusnak
parent 7cdbec2d11
commit 6b813bc473
2 changed files with 12 additions and 0 deletions

View File

@ -29,6 +29,9 @@ void hasher_Init(Hasher *hasher, HasherType type) {
case HASHER_SHA2:
sha256_Init(&hasher->ctx.sha2);
break;
case HASHER_BLAKE:
blake256_Init(&hasher->ctx.blake);
break;
}
}
@ -41,6 +44,9 @@ void hasher_Update(Hasher *hasher, const uint8_t *data, size_t length) {
case HASHER_SHA2:
sha256_Update(&hasher->ctx.sha2, data, length);
break;
case HASHER_BLAKE:
blake256_Update(&hasher->ctx.blake, data, length);
break;
}
}
@ -49,6 +55,9 @@ void hasher_Final(Hasher *hasher, uint8_t hash[HASHER_DIGEST_LENGTH]) {
case HASHER_SHA2:
sha256_Final(&hasher->ctx.sha2, hash);
break;
case HASHER_BLAKE:
blake256_Final(&hasher->ctx.blake, hash);
break;
}
}

View File

@ -27,11 +27,13 @@
#include <stdint.h>
#include "sha2.h"
#include "blake256.h"
#define HASHER_DIGEST_LENGTH 32
typedef enum {
HASHER_SHA2,
HASHER_BLAKE,
} HasherType;
typedef struct {
@ -39,6 +41,7 @@ typedef struct {
union {
SHA256_CTX sha2;
BLAKE256_CTX blake;
} ctx;
} Hasher;