Skip to content

Commit 118cd82

Browse files
committed
Use explicit symbol visibility.
The use of static makes this somewhat redundant currently, though if we later have multiple compilation units it will be needed. This also sets the dllexport needed for shared libraries on win32.
1 parent 4e64608 commit 118cd82

File tree

5 files changed

+55
-33
lines changed

5 files changed

+55
-33
lines changed

configure.ac

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
7474
CFLAGS="$saved_CFLAGS"
7575
])
7676

77+
saved_CFLAGS="$CFLAGS"
78+
CFLAGS="$CFLAGS -fvisibility=hidden"
79+
AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden])
80+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
81+
[ AC_MSG_RESULT([yes]) ],
82+
[ AC_MSG_RESULT([no])
83+
CFLAGS="$saved_CFLAGS"
84+
])
7785

7886
AC_ARG_ENABLE(benchmark,
7987
AS_HELP_STRING([--enable-benchmark],[compile benchmark (default is no)]),

include/secp256k1.h

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ typedef int (*secp256k1_nonce_function)(
119119
# define SECP256K1_INLINE inline
120120
# endif
121121

122+
#ifndef SECP256K1_API
123+
# if defined(_WIN32)
124+
# ifdef SECP256K1_BUILD
125+
# define SECP256K1_API __declspec(dllexport)
126+
# else
127+
# define SECP256K1_API
128+
# endif
129+
# elif defined(__GNUC__) && defined(SECP256K1_BUILD)
130+
# define SECP256K1_API __attribute__ ((visibility ("default")))
131+
# else
132+
# define SECP256K1_API
133+
# endif
134+
#endif
135+
122136
/**Warning attributes
123137
* NONNULL is not used if SECP256K1_BUILD is set to avoid the compiler optimizing out
124138
* some paranoid null checks. */
@@ -145,7 +159,7 @@ typedef int (*secp256k1_nonce_function)(
145159
* Returns: a newly created context object.
146160
* In: flags: which parts of the context to initialize.
147161
*/
148-
secp256k1_context* secp256k1_context_create(
162+
SECP256K1_API secp256k1_context* secp256k1_context_create(
149163
unsigned int flags
150164
) SECP256K1_WARN_UNUSED_RESULT;
151165

@@ -154,7 +168,7 @@ secp256k1_context* secp256k1_context_create(
154168
* Returns: a newly created context object.
155169
* Args: ctx: an existing context to copy (cannot be NULL)
156170
*/
157-
secp256k1_context* secp256k1_context_clone(
171+
SECP256K1_API secp256k1_context* secp256k1_context_clone(
158172
const secp256k1_context* ctx
159173
) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
160174

@@ -163,7 +177,7 @@ secp256k1_context* secp256k1_context_clone(
163177
* The context pointer may not be used afterwards.
164178
* Args: ctx: an existing context to destroy (cannot be NULL)
165179
*/
166-
void secp256k1_context_destroy(
180+
SECP256K1_API void secp256k1_context_destroy(
167181
secp256k1_context* ctx
168182
);
169183

@@ -187,7 +201,7 @@ void secp256k1_context_destroy(
187201
* (NULL restores a default handler that calls abort).
188202
* data: the opaque pointer to pass to fun above.
189203
*/
190-
void secp256k1_context_set_illegal_callback(
204+
SECP256K1_API void secp256k1_context_set_illegal_callback(
191205
secp256k1_context* ctx,
192206
void (*fun)(const char* message, void* data),
193207
const void* data
@@ -209,7 +223,7 @@ void secp256k1_context_set_illegal_callback(
209223
* handler that calls abort).
210224
* data: the opaque pointer to pass to fun above.
211225
*/
212-
void secp256k1_context_set_error_callback(
226+
SECP256K1_API void secp256k1_context_set_error_callback(
213227
secp256k1_context* ctx,
214228
void (*fun)(const char* message, void* data),
215229
const void* data
@@ -229,7 +243,7 @@ void secp256k1_context_set_error_callback(
229243
* 0x03), uncompressed (65 bytes, header byte 0x04), or hybrid (65 bytes, header
230244
* byte 0x06 or 0x07) format public keys.
231245
*/
232-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(
246+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(
233247
const secp256k1_context* ctx,
234248
secp256k1_pubkey* pubkey,
235249
const unsigned char *input,
@@ -249,7 +263,7 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(
249263
* flags: SECP256K1_EC_COMPRESSED if serialization should be in
250264
* compressed format.
251265
*/
252-
int secp256k1_ec_pubkey_serialize(
266+
SECP256K1_API int secp256k1_ec_pubkey_serialize(
253267
const secp256k1_context* ctx,
254268
unsigned char *output,
255269
size_t *outputlen,
@@ -267,7 +281,7 @@ int secp256k1_ec_pubkey_serialize(
267281
*
268282
* Note that this function also supports some violations of DER and even BER.
269283
*/
270-
int secp256k1_ecdsa_signature_parse_der(
284+
SECP256K1_API int secp256k1_ecdsa_signature_parse_der(
271285
const secp256k1_context* ctx,
272286
secp256k1_ecdsa_signature* sig,
273287
const unsigned char *input,
@@ -285,7 +299,7 @@ int secp256k1_ecdsa_signature_parse_der(
285299
* if 0 was returned).
286300
* In: sig: a pointer to an initialized signature object
287301
*/
288-
int secp256k1_ecdsa_signature_serialize_der(
302+
SECP256K1_API int secp256k1_ecdsa_signature_serialize_der(
289303
const secp256k1_context* ctx,
290304
unsigned char *output,
291305
size_t *outputlen,
@@ -301,7 +315,7 @@ int secp256k1_ecdsa_signature_serialize_der(
301315
* msg32: the 32-byte message hash being verified (cannot be NULL)
302316
* pubkey: pointer to an initialized public key to verify with (cannot be NULL)
303317
*/
304-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify(
318+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify(
305319
const secp256k1_context* ctx,
306320
const secp256k1_ecdsa_signature *sig,
307321
const unsigned char *msg32,
@@ -355,7 +369,7 @@ extern const secp256k1_nonce_function secp256k1_nonce_function_default;
355369
* schemes will also accept various non-unique encodings, so care should
356370
* be taken when this property is required for an application.
357371
*/
358-
int secp256k1_ecdsa_sign(
372+
SECP256K1_API int secp256k1_ecdsa_sign(
359373
const secp256k1_context* ctx,
360374
secp256k1_ecdsa_signature *sig,
361375
const unsigned char *msg32,
@@ -371,7 +385,7 @@ int secp256k1_ecdsa_sign(
371385
* Args: ctx: pointer to a context object (cannot be NULL)
372386
* In: seckey: pointer to a 32-byte secret key (cannot be NULL)
373387
*/
374-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_verify(
388+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_verify(
375389
const secp256k1_context* ctx,
376390
const unsigned char *seckey
377391
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
@@ -384,7 +398,7 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_verify(
384398
* Out: pubkey: pointer to the created public key (cannot be NULL)
385399
* In: seckey: pointer to a 32-byte private key (cannot be NULL)
386400
*/
387-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(
401+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(
388402
const secp256k1_context* ctx,
389403
secp256k1_pubkey *pubkey,
390404
const unsigned char *seckey
@@ -410,7 +424,7 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(
410424
* Note that this function does not guarantee correct DER output. It is
411425
* guaranteed to be parsable by secp256k1_ec_privkey_import.
412426
*/
413-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_export(
427+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_export(
414428
const secp256k1_context* ctx,
415429
unsigned char *privkey,
416430
size_t *privkeylen,
@@ -432,7 +446,7 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_export(
432446
* only if you know in advance it is supposed to contain a secp256k1 private
433447
* key.
434448
*/
435-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_import(
449+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_import(
436450
const secp256k1_context* ctx,
437451
unsigned char *seckey,
438452
const unsigned char *privkey,
@@ -448,7 +462,7 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_import(
448462
* In/Out: seckey: pointer to a 32-byte private key.
449463
* In: tweak: pointer to a 32-byte tweak.
450464
*/
451-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_add(
465+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_add(
452466
const secp256k1_context* ctx,
453467
unsigned char *seckey,
454468
const unsigned char *tweak
@@ -464,7 +478,7 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_add(
464478
* In/Out: pubkey: pointer to a public key object.
465479
* In: tweak: pointer to a 32-byte tweak.
466480
*/
467-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add(
481+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add(
468482
const secp256k1_context* ctx,
469483
secp256k1_pubkey *pubkey,
470484
const unsigned char *tweak
@@ -477,7 +491,7 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add(
477491
* In/Out: seckey: pointer to a 32-byte private key.
478492
* In: tweak: pointer to a 32-byte tweak.
479493
*/
480-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_mul(
494+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_mul(
481495
const secp256k1_context* ctx,
482496
unsigned char *seckey,
483497
const unsigned char *tweak
@@ -491,7 +505,7 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_mul(
491505
* In/Out: pubkey: pointer to a public key obkect.
492506
* In: tweak: pointer to a 32-byte tweak.
493507
*/
494-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_mul(
508+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_mul(
495509
const secp256k1_context* ctx,
496510
secp256k1_pubkey *pubkey,
497511
const unsigned char *tweak
@@ -503,7 +517,7 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_mul(
503517
* Args: ctx: pointer to a context object (cannot be NULL)
504518
* In: seed32: pointer to a 32-byte random seed (NULL resets to initial state)
505519
*/
506-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(
520+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(
507521
secp256k1_context* ctx,
508522
const unsigned char *seed32
509523
) SECP256K1_ARG_NONNULL(1);
@@ -519,7 +533,7 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(
519533
* Use secp256k1_ec_pubkey_compress and secp256k1_ec_pubkey_decompress if the
520534
* uncompressed format is needed.
521535
*/
522-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_combine(
536+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_combine(
523537
const secp256k1_context* ctx,
524538
secp256k1_pubkey *out,
525539
const secp256k1_pubkey * const * ins,

include/secp256k1_ecdh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extern "C" {
1616
* In: point: pointer to a public point
1717
* scalar: a 32-byte scalar with which to multiply the point
1818
*/
19-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh(
19+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh(
2020
const secp256k1_context* ctx,
2121
unsigned char *result,
2222
const secp256k1_pubkey *point,

include/secp256k1_recovery.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef struct {
3333
* In: input64: a pointer to a 64-byte compact signature
3434
* recid: the recovery id (0, 1, 2 or 3)
3535
*/
36-
int secp256k1_ecdsa_recoverable_signature_parse_compact(
36+
SECP256K1_API int secp256k1_ecdsa_recoverable_signature_parse_compact(
3737
const secp256k1_context* ctx,
3838
secp256k1_ecdsa_recoverable_signature* sig,
3939
const unsigned char *input64,
@@ -46,7 +46,7 @@ int secp256k1_ecdsa_recoverable_signature_parse_compact(
4646
* Out: sig: a pointer to a normal signature (cannot be NULL).
4747
* In: sigin: a pointer to a recoverable signature (cannot be NULL).
4848
*/
49-
int secp256k1_ecdsa_recoverable_signature_convert(
49+
SECP256K1_API int secp256k1_ecdsa_recoverable_signature_convert(
5050
const secp256k1_context* ctx,
5151
secp256k1_ecdsa_signature* sig,
5252
const secp256k1_ecdsa_recoverable_signature* sigin
@@ -60,7 +60,7 @@ int secp256k1_ecdsa_recoverable_signature_convert(
6060
* recid: a pointer to an integer to hold the recovery id (can be NULL).
6161
* In: sig: a pointer to an initialized signature object (cannot be NULL)
6262
*/
63-
int secp256k1_ecdsa_recoverable_signature_serialize_compact(
63+
SECP256K1_API int secp256k1_ecdsa_recoverable_signature_serialize_compact(
6464
const secp256k1_context* ctx,
6565
unsigned char *output64,
6666
int *recid,
@@ -78,7 +78,7 @@ int secp256k1_ecdsa_recoverable_signature_serialize_compact(
7878
* noncefp:pointer to a nonce generation function. If NULL, secp256k1_nonce_function_default is used
7979
* ndata: pointer to arbitrary data used by the nonce generation function (can be NULL)
8080
*/
81-
int secp256k1_ecdsa_sign_recoverable(
81+
SECP256K1_API int secp256k1_ecdsa_sign_recoverable(
8282
const secp256k1_context* ctx,
8383
secp256k1_ecdsa_recoverable_signature *sig,
8484
const unsigned char *msg32,
@@ -96,7 +96,7 @@ int secp256k1_ecdsa_sign_recoverable(
9696
* In: sig: pointer to initialized signature that supports pubkey recovery (cannot be NULL)
9797
* msg32: the 32-byte message hash assumed to be signed (cannot be NULL)
9898
*/
99-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover(
99+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover(
100100
const secp256k1_context* ctx,
101101
secp256k1_pubkey *pubkey,
102102
const secp256k1_ecdsa_recoverable_signature *sig,

include/secp256k1_schnorr.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern "C" {
2424
* ndata: pointer to arbitrary data used by the nonce generation
2525
* function (can be NULL)
2626
*/
27-
int secp256k1_schnorr_sign(
27+
SECP256K1_API int secp256k1_schnorr_sign(
2828
const secp256k1_context* ctx,
2929
unsigned char *sig64,
3030
const unsigned char *msg32,
@@ -41,7 +41,7 @@ int secp256k1_schnorr_sign(
4141
* msg32: the 32-byte message hash being verified (cannot be NULL)
4242
* pubkey: the public key to verify with (cannot be NULL)
4343
*/
44-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_verify(
44+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_verify(
4545
const secp256k1_context* ctx,
4646
const unsigned char *sig64,
4747
const unsigned char *msg32,
@@ -61,7 +61,7 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_verify(
6161
* msg32: the 32-byte message hash assumed to be signed (cannot
6262
* be NULL)
6363
*/
64-
int secp256k1_schnorr_recover(
64+
SECP256K1_API int secp256k1_schnorr_recover(
6565
const secp256k1_context* ctx,
6666
secp256k1_pubkey *pubkey,
6767
const unsigned char *sig64,
@@ -86,7 +86,7 @@ int secp256k1_schnorr_recover(
8686
*
8787
* Do not use the output as a private/public key pair for signing/validation.
8888
*/
89-
int secp256k1_schnorr_generate_nonce_pair(
89+
SECP256K1_API int secp256k1_schnorr_generate_nonce_pair(
9090
const secp256k1_context* ctx,
9191
secp256k1_pubkey *pubnonce,
9292
unsigned char *privnonce32,
@@ -138,7 +138,7 @@ int secp256k1_schnorr_generate_nonce_pair(
138138
* pre-combine several inputs already with one call, and add more inputs later
139139
* by calling the function again (they are commutative and associative).
140140
*/
141-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_partial_sign(
141+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_partial_sign(
142142
const secp256k1_context* ctx,
143143
unsigned char *sig64,
144144
const unsigned char *msg32,
@@ -159,7 +159,7 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_partial_sign(
159159
* signatures
160160
* n: the number of signatures to combine (at least 1)
161161
*/
162-
SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_partial_combine(
162+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_partial_combine(
163163
const secp256k1_context* ctx,
164164
unsigned char *sig64,
165165
const unsigned char * const * sig64sin,

0 commit comments

Comments
 (0)