Skip to content

Commit bd8f7e5

Browse files
minadsjaeckel
authored andcommitted
introduce MP_PRIVATE to hide symbols (opt-in for now)
1 parent 2829007 commit bd8f7e5

File tree

1 file changed

+55
-35
lines changed

1 file changed

+55
-35
lines changed

tommath_private.h

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@
77
#include "tommath.h"
88
#include "tommath_class.h"
99

10+
/*
11+
* Private symbols
12+
* ---------------
13+
*
14+
* On Unix symbols can be marked as hidden if libtommath is compiled
15+
* as a shared object. By default, symbols are visible.
16+
* As of now, this feature is opt-in via the MP_PRIVATE_SYMBOLS define.
17+
*
18+
* On Win32 a .def file must be used to specify the exported symbols.
19+
*/
20+
#if defined (MP_PRIVATE_SYMBOLS) && __GNUC__ >= 4
21+
# define MP_PRIVATE __attribute__ ((visibility ("hidden")))
22+
#else
23+
# define MP_PRIVATE
24+
#endif
25+
1026
/* Hardening libtommath
1127
* --------------------
1228
*
@@ -143,44 +159,44 @@ typedef private_mp_word mp_word;
143159
#define MP_SIZEOF_BITS(type) (CHAR_BIT * sizeof(type))
144160
#define MP_MAXFAST (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
145161

146-
/* random number source */
147-
extern mp_err(*s_mp_rand_source)(void *out, size_t size);
148-
149162
/* Minimum number of available digits in mp_int, MP_PREC >= MP_MIN_PREC */
150163
#define MP_MIN_PREC ((((CHAR_BIT * (int)sizeof(long long)) + MP_DIGIT_BIT) - 1) / MP_DIGIT_BIT)
151164

165+
/* random number source */
166+
extern MP_PRIVATE mp_err(*s_mp_rand_source)(void *out, size_t size);
167+
152168
/* lowlevel functions, do not call! */
153-
mp_bool s_mp_get_bit(const mp_int *a, unsigned int b);
154-
mp_err s_mp_add(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
155-
mp_err s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
156-
mp_err s_mp_mul_digs_fast(const mp_int *a, const mp_int *b, mp_int *c, int digs) MP_WUR;
157-
mp_err s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) MP_WUR;
158-
mp_err s_mp_mul_high_digs_fast(const mp_int *a, const mp_int *b, mp_int *c, int digs) MP_WUR;
159-
mp_err s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) MP_WUR;
160-
mp_err s_mp_sqr_fast(const mp_int *a, mp_int *b) MP_WUR;
161-
mp_err s_mp_sqr(const mp_int *a, mp_int *b) MP_WUR;
162-
mp_err s_mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
163-
mp_err s_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
164-
mp_err s_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
165-
mp_err s_mp_karatsuba_sqr(const mp_int *a, mp_int *b) MP_WUR;
166-
mp_err s_mp_toom_sqr(const mp_int *a, mp_int *b) MP_WUR;
167-
mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
168-
mp_err s_mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
169-
mp_err s_mp_montgomery_reduce_fast(mp_int *x, const mp_int *n, mp_digit rho) MP_WUR;
170-
mp_err s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode) MP_WUR;
171-
mp_err s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode) MP_WUR;
172-
mp_err s_mp_rand_platform(void *p, size_t n) MP_WUR;
173-
mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat);
174-
mp_err s_mp_jacobi(const mp_int *a, const mp_int *n, int *c);
175-
void s_mp_reverse(unsigned char *s, int len);
169+
MP_PRIVATE mp_bool s_mp_get_bit(const mp_int *a, unsigned int b);
170+
MP_PRIVATE mp_err s_mp_add(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
171+
MP_PRIVATE mp_err s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
172+
MP_PRIVATE mp_err s_mp_mul_digs_fast(const mp_int *a, const mp_int *b, mp_int *c, int digs) MP_WUR;
173+
MP_PRIVATE mp_err s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) MP_WUR;
174+
MP_PRIVATE mp_err s_mp_mul_high_digs_fast(const mp_int *a, const mp_int *b, mp_int *c, int digs) MP_WUR;
175+
MP_PRIVATE mp_err s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) MP_WUR;
176+
MP_PRIVATE mp_err s_mp_sqr_fast(const mp_int *a, mp_int *b) MP_WUR;
177+
MP_PRIVATE mp_err s_mp_sqr(const mp_int *a, mp_int *b) MP_WUR;
178+
MP_PRIVATE mp_err s_mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
179+
MP_PRIVATE mp_err s_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
180+
MP_PRIVATE mp_err s_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
181+
MP_PRIVATE mp_err s_mp_karatsuba_sqr(const mp_int *a, mp_int *b) MP_WUR;
182+
MP_PRIVATE mp_err s_mp_toom_sqr(const mp_int *a, mp_int *b) MP_WUR;
183+
MP_PRIVATE mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
184+
MP_PRIVATE mp_err s_mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
185+
MP_PRIVATE mp_err s_mp_montgomery_reduce_fast(mp_int *x, const mp_int *n, mp_digit rho) MP_WUR;
186+
MP_PRIVATE mp_err s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode) MP_WUR;
187+
MP_PRIVATE mp_err s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode) MP_WUR;
188+
MP_PRIVATE mp_err s_mp_rand_platform(void *p, size_t n) MP_WUR;
189+
MP_PRIVATE mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat);
190+
MP_PRIVATE mp_err s_mp_jacobi(const mp_int *a, const mp_int *n, int *c);
191+
MP_PRIVATE void s_mp_reverse(unsigned char *s, int len);
176192

177193
/* TODO: jenkins prng is not thread safe as of now */
178-
mp_err s_mp_rand_jenkins(void *p, size_t n) MP_WUR;
179-
void s_mp_rand_jenkins_init(uint64_t seed);
194+
MP_PRIVATE mp_err s_mp_rand_jenkins(void *p, size_t n) MP_WUR;
195+
MP_PRIVATE void s_mp_rand_jenkins_init(uint64_t seed);
180196

181-
extern const char *const mp_s_rmap;
182-
extern const uint8_t mp_s_rmap_reverse[];
183-
extern const size_t mp_s_rmap_reverse_sz;
197+
extern MP_PRIVATE const char *const mp_s_rmap;
198+
extern MP_PRIVATE const uint8_t mp_s_rmap_reverse[];
199+
extern MP_PRIVATE const size_t mp_s_rmap_reverse_sz;
184200

185201
/* Fancy macro to set an MPI from another type.
186202
* There are several things assumed:
@@ -204,13 +220,17 @@ mp_err func_name (mp_int * a, type b) \
204220

205221
/* deprecated functions */
206222
MP_DEPRECATED(s_mp_invmod_fast) mp_err fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c);
207-
MP_DEPRECATED(s_mp_montgomery_reduce_fast) mp_err fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho);
208-
MP_DEPRECATED(s_mp_mul_digs_fast) mp_err fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs);
209-
MP_DEPRECATED(s_mp_mul_high_digs_fast) mp_err fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c,
223+
MP_DEPRECATED(s_mp_montgomery_reduce_fast) mp_err fast_mp_montgomery_reduce(mp_int *x, const mp_int *n,
224+
mp_digit rho);
225+
MP_DEPRECATED(s_mp_mul_digs_fast) mp_err fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c,
226+
int digs);
227+
MP_DEPRECATED(s_mp_mul_high_digs_fast) mp_err fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b,
228+
mp_int *c,
210229
int digs);
211230
MP_DEPRECATED(s_mp_sqr_fast) mp_err fast_s_mp_sqr(const mp_int *a, mp_int *b);
212231
MP_DEPRECATED(s_mp_balance_mul) mp_err mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c);
213-
MP_DEPRECATED(s_mp_exptmod_fast) mp_err mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y,
232+
MP_DEPRECATED(s_mp_exptmod_fast) mp_err mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P,
233+
mp_int *Y,
214234
int redmode);
215235
MP_DEPRECATED(s_mp_invmod_slow) mp_err mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c);
216236
MP_DEPRECATED(s_mp_karatsuba_mul) mp_err mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c);

0 commit comments

Comments
 (0)