Skip to content

Commit a2a1b2c

Browse files
committed
Add initialize_tagged to sha256 which initializes and writes the 64 byte string SHA256(tag)||SHA256(tag) into it.
1 parent 1771840 commit a2a1b2c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/hash_impl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,19 @@ static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out
163163
memcpy(out32, (const unsigned char*)out, 32);
164164
}
165165

166+
/* Initializes a sha256 struct and writes the 64 byte string
167+
* SHA256(tag)||SHA256(tag) into it. */
168+
static void secp256k1_sha256_initialize_tagged(secp256k1_sha256 *hash, const unsigned char *tag, size_t taglen) {
169+
unsigned char buf[32];
170+
secp256k1_sha256_initialize(hash);
171+
secp256k1_sha256_write(hash, tag, taglen);
172+
secp256k1_sha256_finalize(hash, buf);
173+
174+
secp256k1_sha256_initialize(hash);
175+
secp256k1_sha256_write(hash, buf, 32);
176+
secp256k1_sha256_write(hash, buf, 32);
177+
}
178+
166179
static void secp256k1_hmac_sha256_initialize(secp256k1_hmac_sha256 *hash, const unsigned char *key, size_t keylen) {
167180
size_t n;
168181
unsigned char rkey[64];

0 commit comments

Comments
 (0)