1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-21 23:18:13 +00:00

Groestl hash: do it twice and truncate to 256 bits

This commit is contained in:
Yura Pakhuchiy 2018-04-04 18:34:07 +07:00 committed by Pavol Rusnak
parent 2fdcebfbb6
commit 08512053c4
4 changed files with 21 additions and 8 deletions

View File

@ -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)

View File

@ -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

View File

@ -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;
}

View File

@ -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 {