refactor: move 'gettime_i64()' to tests_common.h
What changed, and why it matters
This commit is a simple code cleanup: it moves a small helper function that reads the system clock from one internal test/benchmark header file to a new shared test header file. There is no change to the cryptographic library, no change to how Bitcoin transactions or keys are handled, and no security fix or vulnerability introduced.
No security action needed. This is a non-functional refactor of test/benchmark infrastructure.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change relocates gettime_i64() from src/bench.h to the newly created src/tests_common.h, and makes bench.h include tests_common.h. Makefile.am is updated to list the new header. The function body, platform-specific includes, and behavior are identical. The commit message explicitly frames this as a refactor to support future unit tests.
Changed components
src/bench.hsrc/tests_common.hMakefile.amInspect captured patch +44 / −21
diff --git a/Makefile.am b/Makefile.am
index d511853..4cc97ba 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -45,6 +45,7 @@ noinst_HEADERS += src/precomputed_ecmult.h
noinst_HEADERS += src/precomputed_ecmult_gen.h
noinst_HEADERS += src/assumptions.h
noinst_HEADERS += src/checkmem.h
+noinst_HEADERS += src/tests_common.h
noinst_HEADERS += src/testutil.h
noinst_HEADERS += src/util.h
noinst_HEADERS += src/util_local_visibility.h
diff --git a/src/bench.h b/src/bench.h
index 232fb35..4e8e961 100644
--- a/src/bench.h
+++ b/src/bench.h
@@ -12,27 +12,7 @@
#include <stdio.h>
#include <string.h>
-#if (defined(_MSC_VER) && _MSC_VER >= 1900)
-# include <time.h>
-#else
-# include <sys/time.h>
-#endif
-
-static int64_t gettime_i64(void) {
-#if (defined(_MSC_VER) && _MSC_VER >= 1900)
- /* C11 way to get wallclock time */
- struct timespec tv;
- if (!timespec_get(&tv, TIME_UTC)) {
- fputs("timespec_get failed!", stderr);
- exit(EXIT_FAILURE);
- }
- return (int64_t)tv.tv_nsec / 1000 + (int64_t)tv.tv_sec * 1000000LL;
-#else
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (int64_t)tv.tv_usec + (int64_t)tv.tv_sec * 1000000LL;
-#endif
-}
+#include "tests_common.h"
#define FP_EXP (6)
#define FP_MULT (1000000LL)
diff --git a/src/tests_common.h b/src/tests_common.h
new file mode 100644
index 0000000..a341633
--- /dev/null
+++ b/src/tests_common.h
@@ -0,0 +1,42 @@
+/***********************************************************************
+ * Distributed under the MIT software license, see the accompanying *
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
+ ***********************************************************************/
+
+#ifndef SECP256K1_TESTS_COMMON_H
+#define SECP256K1_TESTS_COMMON_H
+
+/***********************************************************************
+ * Test Support Utilities
+ *
+ * This file provides general-purpose functions for tests and benchmark
+ * programs. Unlike testutil.h, this file is not linked to the library,
+ * allowing each program to choose whether to run against the production
+ * API or access library internals directly.
+ ***********************************************************************/
+
+#include <stdint.h>
+
+#if (defined(_MSC_VER) && _MSC_VER >= 1900)
+# include <time.h>
+#else
+# include <sys/time.h>
+#endif
+
+static int64_t gettime_i64(void) {
+#if (defined(_MSC_VER) && _MSC_VER >= 1900)
+ /* C11 way to get wallclock time */
+ struct timespec tv;
+ if (!timespec_get(&tv, TIME_UTC)) {
+ fputs("timespec_get failed!", stderr);
+ exit(EXIT_FAILURE);
+ }
+ return (int64_t)tv.tv_nsec / 1000 + (int64_t)tv.tv_sec * 1000000LL;
+#else
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return (int64_t)tv.tv_usec + (int64_t)tv.tv_sec * 1000000LL;
+#endif
+}
+
+#endif /* SECP256K1_TESTS_COMMON_H */
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.