diff --git a/groestl.c b/groestl.c index a0c986fbc3..260863e29f 100644 --- a/groestl.c +++ b/groestl.c @@ -3105,6 +3105,18 @@ groestl512_Final(void *cc, void *dst) groestl_big_close((sph_groestl_big_context *)cc, 0, 0, dst, 64); } +void +groestl512_DoubleTrunc(void *cc, void *dst) +{ + char buf[64]; + + groestl512_Final(cc, buf); + groestl512_Init(cc); + groestl512_Update(cc, buf, sizeof(buf)); + groestl512_Final(cc, buf); + memcpy(dst, buf, 32); +} + /* see sph_groestl.h */ void sph_groestl512_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst) diff --git a/groestl.h b/groestl.h index 49506622d4..08263f3daa 100644 --- a/groestl.h +++ b/groestl.h @@ -302,6 +302,9 @@ void groestl512_Update(void *cc, const void *data, size_t len); */ void groestl512_Final(void *cc, void *dst); + +void groestl512_DoubleTrunc(void *cc, void *dst); + /** * Add a few additional bits (0 to 7) to the current computation, then * terminate it and output the result in the provided buffer, which must diff --git a/hasher.c b/hasher.c index 93881be611..b8d0b919ba 100644 --- a/hasher.c +++ b/hasher.c @@ -34,7 +34,7 @@ void hasher_Init(Hasher *hasher, HasherType type) { case HASHER_BLAKED: blake256_Init(&hasher->ctx.blake); break; - case HASHER_GROESTL: + case HASHER_GROESTLD_TRUNC: groestl512_Init(&hasher->ctx.groestl); break; } @@ -54,7 +54,7 @@ void hasher_Update(Hasher *hasher, const uint8_t *data, size_t length) { case HASHER_BLAKED: blake256_Update(&hasher->ctx.blake, data, length); break; - case HASHER_GROESTL: + case HASHER_GROESTLD_TRUNC: groestl512_Update(&hasher->ctx.groestl, data, length); break; } @@ -70,20 +70,18 @@ void hasher_Final(Hasher *hasher, uint8_t hash[HASHER_DIGEST_LENGTH]) { case HASHER_BLAKED: blake256_Final(&hasher->ctx.blake, hash); break; - case HASHER_GROESTL: - groestl512_Final(&hasher->ctx.groestl, hash); - break; + case HASHER_GROESTLD_TRUNC: + groestl512_DoubleTrunc(&hasher->ctx.groestl, hash); + return; } switch (hasher->type) { case HASHER_SHA2D: hasher_Raw(HASHER_SHA2, hash, HASHER_DIGEST_LENGTH, hash); break; - case HASHER_BLAKED: hasher_Raw(HASHER_BLAKE, hash, HASHER_DIGEST_LENGTH, hash); break; - default: break; } diff --git a/hasher.h b/hasher.h index 4fa722f50e..673cf9fa79 100644 --- a/hasher.h +++ b/hasher.h @@ -39,7 +39,7 @@ typedef enum { HASHER_SHA2D, HASHER_BLAKED, - HASHER_GROESTL, + HASHER_GROESTLD_TRUNC, /* Double Groestl512 hasher truncated to 256 bits */ } HasherType; typedef struct {