bench: improve context creation in ECDH benchmark
What changed, and why it matters
This is a small cleanup in a benchmark test file for the ECDH module. It replaces a dynamically created cryptographic context with a pre-built static one and removes the matching cleanup call. The change is about making the benchmark follow the intended API more cleanly; it does not fix an exploitable vulnerability in production code.
No security action required. Treat as a normal code-quality / benchmark maintenance patch.
Security signals we found
API compliance cleanup in benchmark code
Removal of non-compliant context creation flag usage
No change to cryptographic operations or validation logic
No change to production library code
Evidence from the diff
The patch modifies src/modules/ecdh/bench_impl.h. It changes the benchmark’s context pointer from mutable (secp256k1_context ) to const (const secp256k1_context ), assigns secp256k1_context_static instead of calling secp256k1_context_create(SECP256K1_FLAGS_TYPE_CONTEXT), and removes the secp256k1_context_destroy() call. The commit message notes that SECP256K1_FLAGS_TYPE_CONTEXT is not strictly API-compliant as a context-creation flag and that the static context is sufficient for benchmarking ECDH. This is a benchmark-only, non-functional change.
Changed components
src/modules/ecdh/bench_impl.hInspect captured patch +2 / −5
diff --git a/src/modules/ecdh/bench_impl.h b/src/modules/ecdh/bench_impl.h
index c23aaa9..8924e1f 100644
--- a/src/modules/ecdh/bench_impl.h
+++ b/src/modules/ecdh/bench_impl.h
@@ -10,7 +10,7 @@
#include "../../../include/secp256k1_ecdh.h"
typedef struct {
- secp256k1_context *ctx;
+ const secp256k1_context *ctx;
secp256k1_pubkey point;
unsigned char scalar[32];
} bench_ecdh_data;
@@ -46,12 +46,9 @@ static void run_ecdh_bench(int iters, int argc, char** argv) {
bench_ecdh_data data;
int d = argc == 1;
- /* create a context with no capabilities */
- data.ctx = secp256k1_context_create(SECP256K1_FLAGS_TYPE_CONTEXT);
+ data.ctx = secp256k1_context_static;
if (d || have_flag(argc, argv, "ecdh")) run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, iters);
-
- secp256k1_context_destroy(data.ctx);
}
#endif /* SECP256K1_MODULE_ECDH_BENCH_H */
Why this scored 17/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.