Merge BlockstreamResearch/secp256k1-zkp#365: tests: Port hash context tests to zkp modules
72867fd682 tests: Port hash context tests to zkp modules (mllwchrry)
Pull request description:
Ports the hash context tests from bitcoin-core/secp256k1#1777 to the zkp-specific modules.
ACKs for top commit:
apoelstra:
ACK 72867fd682279ff2c79cf13f4f8d8484048d2527; successfully ran local tests
Tree-SHA512: 1714a4c5fd793b32a0f00a92670a48709e4d01917bb81739428601c6e88e89f871cdc1294024e6df7272d6c16e681309d9b3448adcd07ce37bfa2be2dc3f4172
This commit is contained in:
@@ -664,6 +664,34 @@ static void norm_arg_test_all(void) {
|
||||
norm_arg_test(64, 64);
|
||||
}
|
||||
|
||||
DEFINE_SHA256_TRANSFORM_PROBE(sha256_bppp)
|
||||
static void test_bppp_ctx_sha256(void) {
|
||||
/* Check ctx-provided SHA256 compression override takes effect */
|
||||
secp256k1_context *ctx = secp256k1_context_clone(CTX);
|
||||
unsigned char out_default[66], out_custom[66];
|
||||
secp256k1_bppp_generators *gens;
|
||||
size_t len = sizeof(out_default);
|
||||
|
||||
/* Default behavior. No ctx-provided SHA256 compression */
|
||||
gens = secp256k1_bppp_generators_create(ctx, 2);
|
||||
CHECK(gens != NULL);
|
||||
CHECK(secp256k1_bppp_generators_serialize(ctx, gens, out_default, &len));
|
||||
secp256k1_bppp_generators_destroy(ctx, gens);
|
||||
CHECK(!sha256_bppp_called);
|
||||
|
||||
/* Override SHA256 compression directly, bypassing the ctx setter sanity checks */
|
||||
ctx->hash_ctx.fn_sha256_compression = sha256_bppp;
|
||||
gens = secp256k1_bppp_generators_create(ctx, 2);
|
||||
CHECK(gens != NULL);
|
||||
CHECK(secp256k1_bppp_generators_serialize(ctx, gens, out_custom, &len));
|
||||
secp256k1_bppp_generators_destroy(ctx, gens);
|
||||
CHECK(sha256_bppp_called);
|
||||
/* Outputs must differ if custom compression was used */
|
||||
CHECK(secp256k1_memcmp_var(out_default, out_custom, 66) != 0);
|
||||
|
||||
secp256k1_context_destroy(ctx);
|
||||
}
|
||||
|
||||
/* --- Test registry --- */
|
||||
static const struct tf_test_entry tests_bppp[] = {
|
||||
CASE1(test_log_exp),
|
||||
@@ -676,6 +704,7 @@ static const struct tf_test_entry tests_bppp[] = {
|
||||
CASE1(norm_arg_test_all),
|
||||
CASE1(norm_arg_verify_vectors),
|
||||
CASE1(norm_arg_prove_vectors),
|
||||
CASE1(test_bppp_ctx_sha256),
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user