From 1f4573905f19d9449fcf0a393d744c370dfbd9c4 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Wed, 10 Nov 2021 12:42:22 +0100 Subject: [PATCH] feat(crypto): Add TapSigHash to Hasher. --- crypto/hasher.c | 10 ++++++++++ crypto/hasher.h | 1 + 2 files changed, 11 insertions(+) diff --git a/crypto/hasher.c b/crypto/hasher.c index c12ad35e0..d82a6acc2 100644 --- a/crypto/hasher.c +++ b/crypto/hasher.c @@ -23,6 +23,11 @@ #include "hasher.h" #include "ripemd160.h" +const uint32_t sha256_initial_tapsighash_state[8] = { + 0xf504a425UL, 0xd7f8783bUL, 0x1363868aUL, 0xe3e55658UL, + 0x6eee945dUL, 0xbc7888ddUL, 0x02a6e2c3UL, 0x1873fe9fUL, +}; + void hasher_InitParam(Hasher *hasher, HasherType type, const void *param, uint32_t param_size) { hasher->type = type; @@ -35,6 +40,9 @@ void hasher_InitParam(Hasher *hasher, HasherType type, const void *param, case HASHER_SHA2_RIPEMD: sha256_Init(&hasher->ctx.sha2); break; + case HASHER_SHA2_TAPSIGHASH: + sha256_Init_ex(&hasher->ctx.sha2, sha256_initial_tapsighash_state, 512); + break; case HASHER_SHA3: #if USE_KECCAK case HASHER_SHA3K: @@ -72,6 +80,7 @@ void hasher_Update(Hasher *hasher, const uint8_t *data, size_t length) { case HASHER_SHA2: case HASHER_SHA2D: case HASHER_SHA2_RIPEMD: + case HASHER_SHA2_TAPSIGHASH: sha256_Update(&hasher->ctx.sha2, data, length); break; case HASHER_SHA3: @@ -98,6 +107,7 @@ void hasher_Update(Hasher *hasher, const uint8_t *data, size_t length) { void hasher_Final(Hasher *hasher, uint8_t hash[HASHER_DIGEST_LENGTH]) { switch (hasher->type) { case HASHER_SHA2: + case HASHER_SHA2_TAPSIGHASH: sha256_Final(&hasher->ctx.sha2, hash); break; case HASHER_SHA2D: diff --git a/crypto/hasher.h b/crypto/hasher.h index 8d9c20364..e58e74bae 100644 --- a/crypto/hasher.h +++ b/crypto/hasher.h @@ -38,6 +38,7 @@ typedef enum { HASHER_SHA2, HASHER_SHA2D, HASHER_SHA2_RIPEMD, + HASHER_SHA2_TAPSIGHASH, HASHER_SHA3, #if USE_KECCAK