1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 15:28:10 +00:00

hasher: add HASHER_SAPLING_PREIMAGE

This commit is contained in:
Pavol Rusnak 2018-10-16 11:29:45 +02:00
parent 2b7d9bd579
commit 60b5b7032c
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 8 additions and 2 deletions

View File

@ -56,7 +56,10 @@ void hasher_Init(Hasher *hasher, HasherType type) {
blake2b_InitPersonal(&hasher->ctx.blake2b, 32, "ZcashOutputsHash", 16);
break;
case HASHER_OVERWINTER_PREIMAGE:
blake2b_InitPersonal(&hasher->ctx.blake2b, 32, "ZcashSigHash\x19\x1b\xa8\x5b", 16); // BRANCH_ID = 0x5ba81b19
blake2b_InitPersonal(&hasher->ctx.blake2b, 32, "ZcashSigHash\x19\x1b\xa8\x5b", 16); // BRANCH_ID = 0x5ba81b19 / Overwinter
break;
case HASHER_SAPLING_PREIMAGE:
blake2b_InitPersonal(&hasher->ctx.blake2b, 32, "ZcashSigHash\xbb\x09\xb8\x76", 16); // BRANCH_ID = 0x76b809bb / Sapling
break;
}
}
@ -90,6 +93,7 @@ void hasher_Update(Hasher *hasher, const uint8_t *data, size_t length) {
case HASHER_OVERWINTER_SEQUENCE:
case HASHER_OVERWINTER_OUTPUTS:
case HASHER_OVERWINTER_PREIMAGE:
case HASHER_SAPLING_PREIMAGE:
blake2b_Update(&hasher->ctx.blake2b, data, length);
break;
}
@ -134,6 +138,7 @@ void hasher_Final(Hasher *hasher, uint8_t hash[HASHER_DIGEST_LENGTH]) {
case HASHER_OVERWINTER_SEQUENCE:
case HASHER_OVERWINTER_OUTPUTS:
case HASHER_OVERWINTER_PREIMAGE:
case HASHER_SAPLING_PREIMAGE:
blake2b_Final(&hasher->ctx.blake2b, hash, 32);
break;
}

View File

@ -54,6 +54,7 @@ typedef enum {
HASHER_OVERWINTER_SEQUENCE,
HASHER_OVERWINTER_OUTPUTS,
HASHER_OVERWINTER_PREIMAGE,
HASHER_SAPLING_PREIMAGE,
} HasherType;
typedef struct {
@ -64,7 +65,7 @@ typedef struct {
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_*
BLAKE2B_CTX blake2b; // for HASHER_OVERWINTER_*, HASHER_SAPLING_*
} ctx;
} Hasher;