mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 06:18:07 +00:00
Groestl hash: do it twice and truncate to 256 bits
This commit is contained in:
parent
2fdcebfbb6
commit
08512053c4
12
groestl.c
12
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)
|
||||
|
@ -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
|
||||
|
12
hasher.c
12
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user