Merge bitcoin-core/secp256k1#1837: tests: Fix function pointer initialization C89 error in ellswift tests

b84635ed3b tests: Fix C89 function pointer initialization in ellswift tests (mllwchrry)

Pull request description:

  Fixes a C89 pedantic compliance error in `src/modules/ellswift/tests_impl.h` where function pointer array initialization is not allowed at declaration time.

  This error was exposed while I was testing the improved test coverage in CI. The initial plan was to simplify the configuration of modules in CI by enabling all modules by default and testing the disabling of each module independently.

  Error: src/modules/ellswift/tests_impl.h:442:110: error: initializer element is not computable at load time [-Wpedantic].

  The error occurred when running the `x86_64_debian` GitHub Actions CI job, which uses GCC 16 (snapshot) with strict flags (-std=c89 -pedantic -pedantic-errors -Werror). See this action run for reference: https://github.com/mllwchrry/secp256k1/actions/runs/23301905657/job/67769464566.

  The fix uses `if/else` to assign function pointers after declaration, matching the pattern already used in the same file.

  While this is a minor C89 compliance issue, it blocks the potential CI simplification.

ACKs for top commit:
  real-or-random:
    utACK b84635ed3b
  theStack:
    ACK b84635ed3b

Tree-SHA512: 61e42afe9c3a215f817b1bf475ea66c103b4af6c598a9d7ee9e1a97789ac6f4e025260b4cd0e2ec219bd73706c7aa2799c58ab904916d9594626cf3c07e4b983
This commit is contained in:
merge-script
2026-03-25 13:06:25 +01:00

View File

@@ -439,14 +439,18 @@ void ellswift_xdh_ctx_sha256_tests(void) {
unsigned char out_default[65], out_custom[65];
const unsigned char skA[32] = {1}, skB[32] = {2};
unsigned char keyA[64], keyB[64], data[64] = {0};
const secp256k1_ellswift_xdh_hash_function hash_funcs[2] = {secp256k1_ellswift_xdh_hash_function_bip324, secp256k1_ellswift_xdh_hash_function_prefix};
secp256k1_ellswift_xdh_hash_function hash_fn;
int i;
CHECK(secp256k1_ellswift_create(ctx, keyA, skA, NULL));
CHECK(secp256k1_ellswift_create(ctx, keyB, skB, NULL));
for (i = 0; i < 2; i++) {
const secp256k1_ellswift_xdh_hash_function hash_fn = hash_funcs[i];
if (i == 0) {
hash_fn = secp256k1_ellswift_xdh_hash_function_bip324;
} else {
hash_fn = secp256k1_ellswift_xdh_hash_function_prefix;
}
/* Default behavior. No ctx-provided SHA256 compression */
CHECK(secp256k1_ellswift_xdh(ctx, out_default, keyA, keyB, skA, 0, hash_fn, data));
CHECK(!sha256_ellswift_xdh_called);