Skip to content

Commit 6823d3b

Browse files
Introduce internal API for setting SHA256 midstates
1 parent fb25ee6 commit 6823d3b

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/hash.h

+6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ typedef struct {
1616
uint64_t bytes;
1717
} secp256k1_sha256;
1818

19+
20+
static const secp256k1_sha256 secp256k1_sha256_initial_state = {
21+
{UINT32_C(0x6a09e667), UINT32_C(0xbb67ae85), UINT32_C(0x3c6ef372), UINT32_C(0xa54ff53a), UINT32_C(0x510e527f), UINT32_C(0x9b05688c), UINT32_C(0x1f83d9ab), UINT32_C(0x5be0cd19)},
22+
{0x00}, 0};
23+
1924
static void secp256k1_sha256_initialize(secp256k1_sha256 *hash);
25+
static void secp256k1_sha256_initialize_midstate(secp256k1_sha256 *hash, const secp256k1_sha256 *state);
2026
static void secp256k1_sha256_write(secp256k1_sha256 *hash, const unsigned char *data, size_t size);
2127
static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out32);
2228

src/hash_impl.h

+5-9
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,11 @@
3434
#endif
3535

3636
static void secp256k1_sha256_initialize(secp256k1_sha256 *hash) {
37-
hash->s[0] = 0x6a09e667ul;
38-
hash->s[1] = 0xbb67ae85ul;
39-
hash->s[2] = 0x3c6ef372ul;
40-
hash->s[3] = 0xa54ff53aul;
41-
hash->s[4] = 0x510e527ful;
42-
hash->s[5] = 0x9b05688cul;
43-
hash->s[6] = 0x1f83d9abul;
44-
hash->s[7] = 0x5be0cd19ul;
45-
hash->bytes = 0;
37+
*hash = secp256k1_sha256_initial_state;
38+
}
39+
40+
static void secp256k1_sha256_initialize_midstate(secp256k1_sha256 *hash, const secp256k1_sha256 *state) {
41+
*hash = *state;
4642
}
4743

4844
/** Perform one SHA-256 transformation, processing 16 big endian 32-bit words. */

0 commit comments

Comments
 (0)