mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-26 18:02:35 +00:00
hasher: Add HASHER_BLAKE
This commit is contained in:
parent
7cdbec2d11
commit
6b813bc473
9
hasher.c
9
hasher.c
@ -29,6 +29,9 @@ void hasher_Init(Hasher *hasher, HasherType type) {
|
|||||||
case HASHER_SHA2:
|
case HASHER_SHA2:
|
||||||
sha256_Init(&hasher->ctx.sha2);
|
sha256_Init(&hasher->ctx.sha2);
|
||||||
break;
|
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:
|
case HASHER_SHA2:
|
||||||
sha256_Update(&hasher->ctx.sha2, data, length);
|
sha256_Update(&hasher->ctx.sha2, data, length);
|
||||||
break;
|
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:
|
case HASHER_SHA2:
|
||||||
sha256_Final(&hasher->ctx.sha2, hash);
|
sha256_Final(&hasher->ctx.sha2, hash);
|
||||||
break;
|
break;
|
||||||
|
case HASHER_BLAKE:
|
||||||
|
blake256_Final(&hasher->ctx.blake, hash);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
hasher.h
3
hasher.h
@ -27,11 +27,13 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "sha2.h"
|
#include "sha2.h"
|
||||||
|
#include "blake256.h"
|
||||||
|
|
||||||
#define HASHER_DIGEST_LENGTH 32
|
#define HASHER_DIGEST_LENGTH 32
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HASHER_SHA2,
|
HASHER_SHA2,
|
||||||
|
HASHER_BLAKE,
|
||||||
} HasherType;
|
} HasherType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -39,6 +41,7 @@ typedef struct {
|
|||||||
|
|
||||||
union {
|
union {
|
||||||
SHA256_CTX sha2;
|
SHA256_CTX sha2;
|
||||||
|
BLAKE256_CTX blake;
|
||||||
} ctx;
|
} ctx;
|
||||||
} Hasher;
|
} Hasher;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user