Skip to content

Commit 7a7494e

Browse files
committed
introduce MP_PRIVATE to hide symbols (opt-in for now)
1 parent b31a108 commit 7a7494e

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
@@ -10,6 +10,22 @@
1010
extern "C" {
1111
#endif
1212

13+
/*
14+
* Private symbols
15+
* ---------------
16+
*
17+
* On Unix symbols can be marked as hidden if libtommath is compiled
18+
* as a shared object. By default, symbols are visible.
19+
* As of now, this feature is opt-in via the MP_PRIVATE_SYMBOLS define.
20+
*
21+
* On Win32 a .def file must be used to specify the exported symbols.
22+
*/
23+
#if defined (MP_PRIVATE_SYMBOLS) && __GNUC__ >= 4
24+
# define MP_PRIVATE __attribute__ ((visibility ("hidden")))
25+
#else
26+
# define MP_PRIVATE
27+
#endif
28+
1329
/* Hardening libtommath
1430
* --------------------
1531
*
@@ -142,44 +158,44 @@ extern void MP_FREE(void *mem, size_t size);
142158
#define MP_SIZEOF_BITS(type) (CHAR_BIT * sizeof(type))
143159
#define MP_MAXFAST (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
144160

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

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

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

180-
extern const char *const mp_s_rmap;
181-
extern const uint8_t mp_s_rmap_reverse[];
182-
extern const size_t mp_s_rmap_reverse_sz;
196+
extern MP_PRIVATE const char *const mp_s_rmap;
197+
extern MP_PRIVATE const uint8_t mp_s_rmap_reverse[];
198+
extern MP_PRIVATE const size_t mp_s_rmap_reverse_sz;
183199

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

204220
/* deprecated functions */
205221
MP_DEPRECATED(s_mp_invmod_fast) mp_err fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c);
206-
MP_DEPRECATED(s_mp_montgomery_reduce_fast) mp_err fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho);
207-
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);
208-
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,
222+
MP_DEPRECATED(s_mp_montgomery_reduce_fast) mp_err fast_mp_montgomery_reduce(mp_int *x, const mp_int *n,
223+
mp_digit rho);
224+
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,
225+
int digs);
226+
MP_DEPRECATED(s_mp_mul_high_digs_fast) mp_err fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b,
227+
mp_int *c,
209228
int digs);
210229
MP_DEPRECATED(s_mp_sqr_fast) mp_err fast_s_mp_sqr(const mp_int *a, mp_int *b);
211230
MP_DEPRECATED(s_mp_balance_mul) mp_err mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c);
212-
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,
231+
MP_DEPRECATED(s_mp_exptmod_fast) mp_err mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P,
232+
mp_int *Y,
213233
int redmode);
214234
MP_DEPRECATED(s_mp_invmod_slow) mp_err mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c);
215235
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)