tests: Fix C89 function pointer initialization in ellswift tests
What changed, and why it matters
This is a minor test-code change that rewrites how two hash functions are selected inside a loop so the code complies with the older C89 standard. It does not change what the tests actually do, and it is not a security fix.
No security action needed. Treat as a normal portability/coding-standard fix to test code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch removes an array initialization of function pointers (const secp256k1_ellswift_xdh_hash_function hash_funcs[2] = {...}) and instead assigns the desired function pointer inside an if/else within the loop. The commit message explicitly states the purpose is to fix C89 function pointer initialization in ellswift tests. The behavior of the test loop is unchanged: it still calls secp256k1_ellswift_xdh_hash_function_bip324 on the first iteration and secp256k1_ellswift_xdh_hash_function_prefix on the second.
Changed components
src/modules/ellswift/tests_impl.hInspect captured patch +6 / −2
diff --git a/src/modules/ellswift/tests_impl.h b/src/modules/ellswift/tests_impl.h
index 2472157..7da08d5 100644
--- a/src/modules/ellswift/tests_impl.h
+++ b/src/modules/ellswift/tests_impl.h
@@ -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);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.