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

hasher: add HASHER_SHA3{,K}

This commit is contained in:
Pavol Rusnak 2018-07-31 14:20:18 +02:00
parent f481530aea
commit 456037599f
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 40 additions and 7 deletions

View File

@ -29,8 +29,9 @@ CFLAGS += -I.
CFLAGS += -DVALGRIND=$(VALGRIND) CFLAGS += -DVALGRIND=$(VALGRIND)
CFLAGS += -DUSE_ETHEREUM=1 CFLAGS += -DUSE_ETHEREUM=1
CFLAGS += -DUSE_GRAPHENE=1 CFLAGS += -DUSE_GRAPHENE=1
CFLAGS += -DUSE_NEM=1 CFLAGS += -DUSE_KECCAK=1
CFLAGS += -DUSE_MONERO=1 CFLAGS += -DUSE_MONERO=1
CFLAGS += -DUSE_NEM=1
CFLAGS += -DUSE_CARDANO=1 CFLAGS += -DUSE_CARDANO=1
CFLAGS += $(shell pkg-config --cflags openssl) CFLAGS += $(shell pkg-config --cflags openssl)

View File

@ -8,6 +8,9 @@
Bo-Yin Yang Bo-Yin Yang
*/ */
#ifndef ED25519_DONNA_H
#define ED25519_DONNA_H
#include "ed25519-donna-portable.h" #include "ed25519-donna-portable.h"
#include "curve25519-donna-32bit.h" #include "curve25519-donna-32bit.h"
@ -45,3 +48,5 @@ typedef struct ge25519_pniels_t {
#include "ed25519-donna-32bit-tables.h" #include "ed25519-donna-32bit-tables.h"
#include "ed25519-donna-impl-base.h" #include "ed25519-donna-impl-base.h"
#endif

View File

@ -30,6 +30,12 @@ void hasher_Init(Hasher *hasher, HasherType type) {
case HASHER_SHA2D: case HASHER_SHA2D:
sha256_Init(&hasher->ctx.sha2); sha256_Init(&hasher->ctx.sha2);
break; break;
case HASHER_SHA3:
#if USE_KECCAK
case HASHER_SHA3K:
#endif
sha3_256_Init(&hasher->ctx.sha3);
break;
case HASHER_BLAKE: case HASHER_BLAKE:
case HASHER_BLAKED: case HASHER_BLAKED:
blake256_Init(&hasher->ctx.blake); blake256_Init(&hasher->ctx.blake);
@ -62,6 +68,12 @@ void hasher_Update(Hasher *hasher, const uint8_t *data, size_t length) {
case HASHER_SHA2D: case HASHER_SHA2D:
sha256_Update(&hasher->ctx.sha2, data, length); sha256_Update(&hasher->ctx.sha2, data, length);
break; break;
case HASHER_SHA3:
#if USE_KECCAK
case HASHER_SHA3K:
#endif
sha3_Update(&hasher->ctx.sha3, data, length);
break;
case HASHER_BLAKE: case HASHER_BLAKE:
case HASHER_BLAKED: case HASHER_BLAKED:
blake256_Update(&hasher->ctx.blake, data, length); blake256_Update(&hasher->ctx.blake, data, length);
@ -87,6 +99,14 @@ void hasher_Final(Hasher *hasher, uint8_t hash[HASHER_DIGEST_LENGTH]) {
sha256_Final(&hasher->ctx.sha2, hash); sha256_Final(&hasher->ctx.sha2, hash);
hasher_Raw(HASHER_SHA2, hash, HASHER_DIGEST_LENGTH, hash); hasher_Raw(HASHER_SHA2, hash, HASHER_DIGEST_LENGTH, hash);
break; break;
case HASHER_SHA3:
sha3_Final(&hasher->ctx.sha3, hash);
break;
#if USE_KECCAK
case HASHER_SHA3K:
keccak_Final(&hasher->ctx.sha3, hash);
break;
#endif
case HASHER_BLAKE: case HASHER_BLAKE:
blake256_Final(&hasher->ctx.blake, hash); blake256_Final(&hasher->ctx.blake, hash);
break; break;

View File

@ -27,6 +27,7 @@
#include <stdint.h> #include <stdint.h>
#include "sha2.h" #include "sha2.h"
#include "sha3.h"
#include "blake256.h" #include "blake256.h"
#include "groestl.h" #include "groestl.h"
#include "blake2b.h" #include "blake2b.h"
@ -35,9 +36,14 @@
typedef enum { typedef enum {
HASHER_SHA2, HASHER_SHA2,
HASHER_BLAKE,
HASHER_SHA2D, HASHER_SHA2D,
HASHER_SHA3,
#if USE_KECCAK
HASHER_SHA3K,
#endif
HASHER_BLAKE,
HASHER_BLAKED, HASHER_BLAKED,
HASHER_GROESTLD_TRUNC, /* Double Groestl512 hasher truncated to 256 bits */ HASHER_GROESTLD_TRUNC, /* Double Groestl512 hasher truncated to 256 bits */
@ -52,10 +58,11 @@ typedef struct {
HasherType type; HasherType type;
union { union {
SHA256_CTX sha2; SHA256_CTX sha2; // for HASHER_SHA2{,D}
BLAKE256_CTX blake; SHA3_CTX sha3; // for HASHER_SHA3{,K}
GROESTL512_CTX groestl; BLAKE256_CTX blake; // for HASHER_BLAKE{,D}
BLAKE2B_CTX blake2b; GROESTL512_CTX groestl; // for HASHER_GROESTLD_TRUNC
BLAKE2B_CTX blake2b; // for HASHER_OVERWINTER_*
} ctx; } ctx;
} Hasher; } Hasher;