diff --git a/src/modules/bppp/bppp_transcript_impl.h b/src/modules/bppp/bppp_transcript_impl.h index d53e9023..5e212231 100644 --- a/src/modules/bppp/bppp_transcript_impl.h +++ b/src/modules/bppp/bppp_transcript_impl.h @@ -14,17 +14,11 @@ * SHA256 to SHA256("Bulletproofs_pp/v0/commitment")||SHA256("Bulletproofs_pp/v0/commitment"). */ static void secp256k1_bppp_sha256_tagged_commitment_init(secp256k1_sha256 *sha) { - secp256k1_sha256_initialize(sha); - sha->s[0] = 0x52fc8185ul; - sha->s[1] = 0x0e7debf0ul; - sha->s[2] = 0xb0967270ul; - sha->s[3] = 0x6f5abfe1ul; - sha->s[4] = 0x822bdec0ul; - sha->s[5] = 0x36db8beful; - sha->s[6] = 0x03d9e1f1ul; - sha->s[7] = 0x8a5cef6ful; - - sha->bytes = 64; + static const uint32_t midstate[8] = { + 0x52fc8185ul, 0x0e7debf0ul, 0xb0967270ul, 0x6f5abfe1ul, + 0x822bdec0ul, 0x36db8beful, 0x03d9e1f1ul, 0x8a5cef6ful + }; + secp256k1_sha256_initialize_midstate(sha, 64, midstate); } /* Obtain a challenge scalar from the current transcript.*/ diff --git a/src/modules/ecdsa_adaptor/dleq_impl.h b/src/modules/ecdsa_adaptor/dleq_impl.h index 60e63a34..63642dc8 100644 --- a/src/modules/ecdsa_adaptor/dleq_impl.h +++ b/src/modules/ecdsa_adaptor/dleq_impl.h @@ -4,17 +4,11 @@ /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("DLEQ")||SHA256("DLEQ"). */ static void secp256k1_nonce_function_dleq_sha256_tagged(secp256k1_sha256 *sha) { - secp256k1_sha256_initialize(sha); - sha->s[0] = 0x8cc4beacul; - sha->s[1] = 0x2e011f3ful; - sha->s[2] = 0x355c75fbul; - sha->s[3] = 0x3ba6a2c5ul; - sha->s[4] = 0xe96f3aeful; - sha->s[5] = 0x180530fdul; - sha->s[6] = 0x94582499ul; - sha->s[7] = 0x577fd564ul; - - sha->bytes = 64; + static const uint32_t midstate[8] = { + 0x8cc4beacul, 0x2e011f3ful, 0x355c75fbul, 0x3ba6a2c5ul, + 0xe96f3aeful, 0x180530fdul, 0x94582499ul, 0x577fd564ul + }; + secp256k1_sha256_initialize_midstate(sha, 64, midstate); } /* algo argument for nonce_function_ecdsa_adaptor to derive the nonce using a tagged hash function. */ diff --git a/src/modules/ecdsa_adaptor/main_impl.h b/src/modules/ecdsa_adaptor/main_impl.h index e43a4222..ea10207f 100644 --- a/src/modules/ecdsa_adaptor/main_impl.h +++ b/src/modules/ecdsa_adaptor/main_impl.h @@ -60,33 +60,21 @@ static int secp256k1_ecdsa_adaptor_sig_deserialize(secp256k1_ge *r, secp256k1_sc /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("ECDSAadaptor/non")||SHA256("ECDSAadaptor/non"). */ static void secp256k1_nonce_function_ecdsa_adaptor_sha256_tagged(secp256k1_sha256 *sha) { - secp256k1_sha256_initialize(sha); - sha->s[0] = 0x791dae43ul; - sha->s[1] = 0xe52d3b44ul; - sha->s[2] = 0x37f9edeaul; - sha->s[3] = 0x9bfd2ab1ul; - sha->s[4] = 0xcfb0f44dul; - sha->s[5] = 0xccf1d880ul; - sha->s[6] = 0xd18f2c13ul; - sha->s[7] = 0xa37b9024ul; - - sha->bytes = 64; + static const uint32_t midstate[8] = { + 0x791dae43ul, 0xe52d3b44ul, 0x37f9edeaul, 0x9bfd2ab1ul, + 0xcfb0f44dul, 0xccf1d880ul, 0xd18f2c13ul, 0xa37b9024ul + }; + secp256k1_sha256_initialize_midstate(sha, 64, midstate); } /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("ECDSAadaptor/aux")||SHA256("ECDSAadaptor/aux"). */ static void secp256k1_nonce_function_ecdsa_adaptor_sha256_tagged_aux(secp256k1_sha256 *sha) { - secp256k1_sha256_initialize(sha); - sha->s[0] = 0xd14c7bd9ul; - sha->s[1] = 0x095d35e6ul; - sha->s[2] = 0xb8490a88ul; - sha->s[3] = 0xfb00ef74ul; - sha->s[4] = 0x0baa488ful; - sha->s[5] = 0x69366693ul; - sha->s[6] = 0x1c81c5baul; - sha->s[7] = 0xc33b296aul; - - sha->bytes = 64; + static const uint32_t midstate[8] = { + 0xd14c7bd9ul, 0x095d35e6ul, 0xb8490a88ul, 0xfb00ef74ul, + 0x0baa488ful, 0x69366693ul, 0x1c81c5baul, 0xc33b296aul + }; + secp256k1_sha256_initialize_midstate(sha, 64, midstate); } /* algo argument for nonce_function_ecdsa_adaptor to derive the nonce using a tagged hash function. */ diff --git a/src/modules/ecdsa_s2c/main_impl.h b/src/modules/ecdsa_s2c/main_impl.h index 59a4cdfa..cdc54737 100644 --- a/src/modules/ecdsa_s2c/main_impl.h +++ b/src/modules/ecdsa_s2c/main_impl.h @@ -36,33 +36,21 @@ int secp256k1_ecdsa_s2c_opening_serialize(const secp256k1_context* ctx, unsigned /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("s2c/ecdsa/point")||SHA256("s2c/ecdsa/point"). */ static void secp256k1_s2c_ecdsa_point_sha256_tagged(secp256k1_sha256 *sha) { - secp256k1_sha256_initialize(sha); - sha->s[0] = 0xa9b21c7bul; - sha->s[1] = 0x358c3e3eul; - sha->s[2] = 0x0b6863d1ul; - sha->s[3] = 0xc62b2035ul; - sha->s[4] = 0xb44b40ceul; - sha->s[5] = 0x254a8912ul; - sha->s[6] = 0x0f85d0d4ul; - sha->s[7] = 0x8a5bf91cul; - - sha->bytes = 64; + static const uint32_t midstate[8] = { + 0xa9b21c7bul, 0x358c3e3eul, 0x0b6863d1ul, 0xc62b2035ul, + 0xb44b40ceul, 0x254a8912ul, 0x0f85d0d4ul, 0x8a5bf91cul + }; + secp256k1_sha256_initialize_midstate(sha, 64, midstate); } /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("s2c/ecdsa/data")||SHA256("s2c/ecdsa/data"). */ static void secp256k1_s2c_ecdsa_data_sha256_tagged(secp256k1_sha256 *sha) { - secp256k1_sha256_initialize(sha); - sha->s[0] = 0xfeefd675ul; - sha->s[1] = 0x73166c99ul; - sha->s[2] = 0xe2309cb8ul; - sha->s[3] = 0x6d458113ul; - sha->s[4] = 0x01d3a512ul; - sha->s[5] = 0x00e18112ul; - sha->s[6] = 0x37ee0874ul; - sha->s[7] = 0x421fc55ful; - - sha->bytes = 64; + static const uint32_t midstate[8] = { + 0xfeefd675ul, 0x73166c99ul, 0xe2309cb8ul, 0x6d458113ul, + 0x01d3a512ul, 0x00e18112ul, 0x37ee0874ul, 0x421fc55ful + }; + secp256k1_sha256_initialize_midstate(sha, 64, midstate); } int secp256k1_ecdsa_s2c_sign(const secp256k1_context* ctx, secp256k1_ecdsa_signature* signature, secp256k1_ecdsa_s2c_opening* s2c_opening, const unsigned char diff --git a/src/modules/schnorrsig_halfagg/main_impl.h b/src/modules/schnorrsig_halfagg/main_impl.h index af612195..5d424a38 100644 --- a/src/modules/schnorrsig_halfagg/main_impl.h +++ b/src/modules/schnorrsig_halfagg/main_impl.h @@ -9,17 +9,11 @@ /* Initializes SHA256 with fixed midstate. This midstate was computed by applying * SHA256 to SHA256("HalfAgg/randomizer")||SHA256("HalfAgg/randomizer"). */ static void secp256k1_schnorrsig_sha256_tagged_aggregation(secp256k1_sha256 *sha) { - secp256k1_sha256_initialize(sha); - sha->s[0] = 0xd11f5532ul; - sha->s[1] = 0xfa57f70ful; - sha->s[2] = 0x5db0d728ul; - sha->s[3] = 0xf806ffe1ul; - sha->s[4] = 0x1d4db069ul; - sha->s[5] = 0xb4d587e1ul; - sha->s[6] = 0x50451c2aul; - sha->s[7] = 0x10fb63e9ul; - - sha->bytes = 64; + static const uint32_t midstate[8] = { + 0xd11f5532ul, 0xfa57f70ful, 0x5db0d728ul, 0xf806ffe1ul, + 0x1d4db069ul, 0xb4d587e1ul, 0x50451c2aul, 0x10fb63e9ul + }; + secp256k1_sha256_initialize_midstate(sha, 64, midstate); } int secp256k1_schnorrsig_inc_aggregate(const secp256k1_context *ctx, unsigned char *aggsig, size_t *aggsig_len, const secp256k1_xonly_pubkey *all_pubkeys, const unsigned char *all_msgs32, const unsigned char *new_sigs64, size_t n_before, size_t n_new) {