From 456037599f1b694597e2bcccbac1cbcb23c33942 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 31 Jul 2018 14:20:18 +0200 Subject: [PATCH] hasher: add HASHER_SHA3{,K} --- Makefile | 3 ++- ed25519-donna/ed25519-donna.h | 5 +++++ hasher.c | 20 ++++++++++++++++++++ hasher.h | 19 +++++++++++++------ 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index a5e3deb880..837e0ecd01 100644 --- a/Makefile +++ b/Makefile @@ -29,8 +29,9 @@ CFLAGS += -I. CFLAGS += -DVALGRIND=$(VALGRIND) CFLAGS += -DUSE_ETHEREUM=1 CFLAGS += -DUSE_GRAPHENE=1 -CFLAGS += -DUSE_NEM=1 +CFLAGS += -DUSE_KECCAK=1 CFLAGS += -DUSE_MONERO=1 +CFLAGS += -DUSE_NEM=1 CFLAGS += -DUSE_CARDANO=1 CFLAGS += $(shell pkg-config --cflags openssl) diff --git a/ed25519-donna/ed25519-donna.h b/ed25519-donna/ed25519-donna.h index 1cf3186e29..d3c3402270 100644 --- a/ed25519-donna/ed25519-donna.h +++ b/ed25519-donna/ed25519-donna.h @@ -8,6 +8,9 @@ Bo-Yin Yang */ +#ifndef ED25519_DONNA_H +#define ED25519_DONNA_H + #include "ed25519-donna-portable.h" #include "curve25519-donna-32bit.h" @@ -45,3 +48,5 @@ typedef struct ge25519_pniels_t { #include "ed25519-donna-32bit-tables.h" #include "ed25519-donna-impl-base.h" + +#endif diff --git a/hasher.c b/hasher.c index a52eefdd34..762bc321af 100644 --- a/hasher.c +++ b/hasher.c @@ -30,6 +30,12 @@ void hasher_Init(Hasher *hasher, HasherType type) { case HASHER_SHA2D: sha256_Init(&hasher->ctx.sha2); break; + case HASHER_SHA3: +#if USE_KECCAK + case HASHER_SHA3K: +#endif + sha3_256_Init(&hasher->ctx.sha3); + break; case HASHER_BLAKE: case HASHER_BLAKED: blake256_Init(&hasher->ctx.blake); @@ -62,6 +68,12 @@ void hasher_Update(Hasher *hasher, const uint8_t *data, size_t length) { case HASHER_SHA2D: sha256_Update(&hasher->ctx.sha2, data, length); break; + case HASHER_SHA3: +#if USE_KECCAK + case HASHER_SHA3K: +#endif + sha3_Update(&hasher->ctx.sha3, data, length); + break; case HASHER_BLAKE: case HASHER_BLAKED: 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); hasher_Raw(HASHER_SHA2, hash, HASHER_DIGEST_LENGTH, hash); 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: blake256_Final(&hasher->ctx.blake, hash); break; diff --git a/hasher.h b/hasher.h index 3a561673cb..fe4f5f7b19 100644 --- a/hasher.h +++ b/hasher.h @@ -27,6 +27,7 @@ #include #include "sha2.h" +#include "sha3.h" #include "blake256.h" #include "groestl.h" #include "blake2b.h" @@ -35,9 +36,14 @@ typedef enum { HASHER_SHA2, - HASHER_BLAKE, - HASHER_SHA2D, + + HASHER_SHA3, +#if USE_KECCAK + HASHER_SHA3K, +#endif + + HASHER_BLAKE, HASHER_BLAKED, HASHER_GROESTLD_TRUNC, /* Double Groestl512 hasher truncated to 256 bits */ @@ -52,10 +58,11 @@ typedef struct { HasherType type; union { - SHA256_CTX sha2; - BLAKE256_CTX blake; - GROESTL512_CTX groestl; - BLAKE2B_CTX blake2b; + SHA256_CTX sha2; // for HASHER_SHA2{,D} + SHA3_CTX sha3; // for HASHER_SHA3{,K} + BLAKE256_CTX blake; // for HASHER_BLAKE{,D} + GROESTL512_CTX groestl; // for HASHER_GROESTLD_TRUNC + BLAKE2B_CTX blake2b; // for HASHER_OVERWINTER_* } ctx; } Hasher;