Skip to content

Commit 7012a18

Browse files
committedMay 2, 2021
Merge bitcoin#928: Define SECP256K1_BUILD in secp256k1.c directly.
ae9e648 Define SECP256K1_BUILD in secp256k1.c directly. (Gregory Maxwell) Pull request description: This avoids building without it and makes it safer to use a custom building environment. Test harnesses need to #include secp256k1.c first now. Fixes bitcoin#927 ACKs for top commit: sipa: utACK ae9e648 real-or-random: ACK ae9e648 Tree-SHA512: 65ccc15c18f111ba926db1bb25f06c2beb2997c6f42c6d3ebc371ca84f4b5918379efd25c30556cedfd2e4275758bd79d733e80a11159c6ec013dd4707a683ad
2 parents efad350 + ae9e648 commit 7012a18

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed
 

‎Makefile.am

+6-6
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ endif
6868
endif
6969

7070
libsecp256k1_la_SOURCES = src/secp256k1.c
71-
libsecp256k1_la_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
71+
libsecp256k1_la_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
7272
libsecp256k1_la_LIBADD = $(SECP_LIBS) $(COMMON_LIB)
7373

7474
if VALGRIND_ENABLED
@@ -81,22 +81,22 @@ noinst_PROGRAMS += bench_verify bench_sign bench_internal bench_ecmult
8181
bench_verify_SOURCES = src/bench_verify.c
8282
bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
8383
# SECP_TEST_INCLUDES are only used here for CRYPTO_CPPFLAGS
84-
bench_verify_CPPFLAGS = -DSECP256K1_BUILD $(SECP_TEST_INCLUDES)
84+
bench_verify_CPPFLAGS = $(SECP_TEST_INCLUDES)
8585
bench_sign_SOURCES = src/bench_sign.c
8686
bench_sign_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
8787
bench_internal_SOURCES = src/bench_internal.c
8888
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB)
89-
bench_internal_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
89+
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
9090
bench_ecmult_SOURCES = src/bench_ecmult.c
9191
bench_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB)
92-
bench_ecmult_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
92+
bench_ecmult_CPPFLAGS = $(SECP_INCLUDES)
9393
endif
9494

9595
TESTS =
9696
if USE_TESTS
9797
noinst_PROGRAMS += tests
9898
tests_SOURCES = src/tests.c
99-
tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
99+
tests_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
100100
if VALGRIND_ENABLED
101101
tests_CPPFLAGS += -DVALGRIND
102102
noinst_PROGRAMS += valgrind_ctime_test
@@ -114,7 +114,7 @@ endif
114114
if USE_EXHAUSTIVE_TESTS
115115
noinst_PROGRAMS += exhaustive_tests
116116
exhaustive_tests_SOURCES = src/tests_exhaustive.c
117-
exhaustive_tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src $(SECP_INCLUDES)
117+
exhaustive_tests_CPPFLAGS = -I$(top_srcdir)/src $(SECP_INCLUDES)
118118
if !ENABLE_COVERAGE
119119
exhaustive_tests_CPPFLAGS += -DVERIFY
120120
endif

‎include/secp256k1.h

+11
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ typedef int (*secp256k1_nonce_function)(
127127
# define SECP256K1_INLINE inline
128128
# endif
129129

130+
/** When this header is used at build-time the SECP256K1_BUILD define needs to be set
131+
* to correctly setup export attributes and nullness checks. This is normally done
132+
* by secp256k1.c but to guard against this header being included before secp256k1.c
133+
* has had a chance to set the define (e.g. via test harnesses that just includes
134+
* secp256k1.c) we set SECP256K1_NO_BUILD when this header is processed without the
135+
* BUILD define so this condition can be caught.
136+
*/
137+
#ifndef SECP256K1_BUILD
138+
# define SECP256K1_NO_BUILD
139+
#endif
140+
130141
#ifndef SECP256K1_API
131142
# if defined(_WIN32)
132143
# ifdef SECP256K1_BUILD

‎src/bench_ecmult.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
***********************************************************************/
66
#include <stdio.h>
77

8-
#include "include/secp256k1.h"
8+
#include "secp256k1.c"
99

10+
#include "include/secp256k1.h"
1011
#include "util.h"
1112
#include "hash_impl.h"
1213
#include "field_impl.h"
1314
#include "group_impl.h"
1415
#include "scalar_impl.h"
1516
#include "ecmult_impl.h"
1617
#include "bench.h"
17-
#include "secp256k1.c"
1818

1919
#define POINTS 32768
2020

‎src/bench_internal.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
***********************************************************************/
66
#include <stdio.h>
77

8-
#include "include/secp256k1.h"
8+
#include "secp256k1.c"
99

10+
#include "include/secp256k1.h"
1011
#include "assumptions.h"
1112
#include "util.h"
1213
#include "hash_impl.h"
@@ -16,7 +17,6 @@
1617
#include "ecmult_const_impl.h"
1718
#include "ecmult_impl.h"
1819
#include "bench.h"
19-
#include "secp256k1.c"
2020

2121
typedef struct {
2222
secp256k1_scalar scalar[2];

‎src/secp256k1.c

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
55
***********************************************************************/
66

7+
#define SECP256K1_BUILD
8+
79
#include "include/secp256k1.h"
810
#include "include/secp256k1_preallocated.h"
911

@@ -21,6 +23,10 @@
2123
#include "scratch_impl.h"
2224
#include "selftest.h"
2325

26+
#ifdef SECP256K1_NO_BUILD
27+
# error "secp256k1.h processed without SECP256K1_BUILD defined while building secp256k1.c"
28+
#endif
29+
2430
#if defined(VALGRIND)
2531
# include <valgrind/memcheck.h>
2632
#endif

‎src/tests_exhaustive.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#define EXHAUSTIVE_TEST_ORDER 13
2121
#endif
2222

23+
#include "secp256k1.c"
2324
#include "include/secp256k1.h"
2425
#include "assumptions.h"
2526
#include "group.h"
26-
#include "secp256k1.c"
2727
#include "testrand_impl.h"
2828

2929
static int count = 2;

0 commit comments

Comments
 (0)