From eabd9bc46a31c0da6db6d88840eadbe9006447b1 Mon Sep 17 00:00:00 2001 From: Jonas Nick Date: Thu, 14 Nov 2019 13:53:46 +0000 Subject: [PATCH] Allow initializing tagged sha256 This will be used by the schnorrsig module --- src/hash_impl.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/hash_impl.h b/src/hash_impl.h index 1985a07836daf..409772587bebb 100644 --- a/src/hash_impl.h +++ b/src/hash_impl.h @@ -164,6 +164,19 @@ static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out memcpy(out32, (const unsigned char*)out, 32); } +/* Initializes a sha256 struct and writes the 64 byte string + * SHA256(tag)||SHA256(tag) into it. */ +static void secp256k1_sha256_initialize_tagged(secp256k1_sha256 *hash, const unsigned char *tag, size_t taglen) { + unsigned char buf[32]; + secp256k1_sha256_initialize(hash); + secp256k1_sha256_write(hash, tag, taglen); + secp256k1_sha256_finalize(hash, buf); + + secp256k1_sha256_initialize(hash); + secp256k1_sha256_write(hash, buf, 32); + secp256k1_sha256_write(hash, buf, 32); +} + static void secp256k1_hmac_sha256_initialize(secp256k1_hmac_sha256 *hash, const unsigned char *key, size_t keylen) { size_t n; unsigned char rkey[64];