comparison libtommath/tommath.h @ 1436:60fc6476e044

Update to libtommath v1.0
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jun 2017 22:37:14 +0800
parents 5ff8218bcee9
children 8bba51a55704
comparison
equal deleted inserted replaced
1435:f849a5ca2efc 1436:60fc6476e044
8 * additional optimizations in place. 8 * additional optimizations in place.
9 * 9 *
10 * The library is free for all purposes without any express 10 * The library is free for all purposes without any express
11 * guarantee it works. 11 * guarantee it works.
12 * 12 *
13 * Tom St Denis, [email protected], http://math.libtomcrypt.com 13 * Tom St Denis, [email protected], http://math.libtomcrypt.com
14 */ 14 */
15 #ifndef BN_H_ 15 #ifndef BN_H_
16 #define BN_H_ 16 #define BN_H_
17 17
18 #include <stdio.h> 18 #include <stdio.h>
19 #include <string.h>
20 #include <stdlib.h> 19 #include <stdlib.h>
21 #include <ctype.h> 20 #include <stdint.h>
22 #include <limits.h> 21 #include <limits.h>
23 22
24 #include "tommath_class.h" 23 #include "tommath_class.h"
25
26 #ifndef MIN
27 #define MIN(x,y) ((x)<(y)?(x):(y))
28 #endif
29
30 #ifndef MAX
31 #define MAX(x,y) ((x)>(y)?(x):(y))
32 #endif
33 24
34 #ifdef __cplusplus 25 #ifdef __cplusplus
35 extern "C" { 26 extern "C" {
36 27 #endif
37 /* C++ compilers don't like assigning void * to mp_digit * */
38 #define OPT_CAST(x) (x *)
39
40 #else
41
42 /* C on the other hand doesn't care */
43 #define OPT_CAST(x)
44
45 #endif
46
47 28
48 /* detect 64-bit mode if possible */ 29 /* detect 64-bit mode if possible */
49 #if defined(__x86_64__) 30 #if defined(__x86_64__)
50 #if !(defined(MP_64BIT) && defined(MP_16BIT) && defined(MP_8BIT)) 31 #if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
51 #define MP_64BIT 32 #define MP_64BIT
52 #endif 33 #endif
53 #endif 34 #endif
54 35
55 /* some default configurations. 36 /* some default configurations.
59 * 40 *
60 * At the very least a mp_digit must be able to hold 7 bits 41 * At the very least a mp_digit must be able to hold 7 bits
61 * [any size beyond that is ok provided it doesn't overflow the data type] 42 * [any size beyond that is ok provided it doesn't overflow the data type]
62 */ 43 */
63 #ifdef MP_8BIT 44 #ifdef MP_8BIT
64 typedef unsigned char mp_digit; 45 typedef uint8_t mp_digit;
65 typedef unsigned short mp_word; 46 typedef uint16_t mp_word;
47 #define MP_SIZEOF_MP_DIGIT 1
48 #ifdef DIGIT_BIT
49 #error You must not define DIGIT_BIT when using MP_8BIT
50 #endif
66 #elif defined(MP_16BIT) 51 #elif defined(MP_16BIT)
67 typedef unsigned short mp_digit; 52 typedef uint16_t mp_digit;
68 typedef unsigned long mp_word; 53 typedef uint32_t mp_word;
54 #define MP_SIZEOF_MP_DIGIT 2
55 #ifdef DIGIT_BIT
56 #error You must not define DIGIT_BIT when using MP_16BIT
57 #endif
69 #elif defined(MP_64BIT) 58 #elif defined(MP_64BIT)
70 /* for GCC only on supported platforms */ 59 /* for GCC only on supported platforms */
71 #ifndef CRYPT 60 typedef uint64_t mp_digit;
72 typedef unsigned long long ulong64; 61 #if defined(_WIN32)
73 typedef signed long long long64; 62 typedef unsigned __int128 mp_word;
74 #endif 63 #elif defined(__GNUC__)
75 64 typedef unsigned long mp_word __attribute__ ((mode(TI)));
76 typedef unsigned long mp_digit; 65 #else
77 typedef unsigned long mp_word __attribute__ ((mode(TI))); 66 /* it seems you have a problem
78 67 * but we assume you can somewhere define your own uint128_t */
79 #define DIGIT_BIT 60 68 typedef uint128_t mp_word;
69 #endif
70
71 #define DIGIT_BIT 60
80 #else 72 #else
81 /* this is the default case, 28-bit digits */ 73 /* this is the default case, 28-bit digits */
82 74
83 /* this is to make porting into LibTomCrypt easier :-) */ 75 /* this is to make porting into LibTomCrypt easier :-) */
84 #ifndef CRYPT 76 typedef uint32_t mp_digit;
85 #if defined(_MSC_VER) || defined(__BORLANDC__) 77 typedef uint64_t mp_word;
86 typedef unsigned __int64 ulong64; 78
87 typedef signed __int64 long64; 79 #ifdef MP_31BIT
88 #else
89 typedef unsigned long long ulong64;
90 typedef signed long long long64;
91 #endif
92 #endif
93
94 typedef unsigned long mp_digit;
95 typedef ulong64 mp_word;
96
97 #ifdef MP_31BIT
98 /* this is an extension that uses 31-bit digits */ 80 /* this is an extension that uses 31-bit digits */
99 #define DIGIT_BIT 31 81 #define DIGIT_BIT 31
100 #else 82 #else
101 /* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */ 83 /* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */
102 #define DIGIT_BIT 28 84 #define DIGIT_BIT 28
103 #define MP_28BIT 85 #define MP_28BIT
104 #endif 86 #endif
105 #endif 87 #endif
106
107 /* define heap macros */
108 #ifndef CRYPT
109 /* default to libc stuff */
110 #ifndef XMALLOC
111 #define XMALLOC malloc
112 #define XFREE free
113 #define XREALLOC realloc
114 #define XCALLOC calloc
115 #else
116 /* prototypes for our heap functions */
117 extern void *XMALLOC(size_t n);
118 extern void *XREALLOC(void *p, size_t n);
119 extern void *XCALLOC(size_t n, size_t s);
120 extern void XFREE(void *p);
121 #endif
122 #endif
123
124 88
125 /* otherwise the bits per digit is calculated automatically from the size of a mp_digit */ 89 /* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
126 #ifndef DIGIT_BIT 90 #ifndef DIGIT_BIT
127 #define DIGIT_BIT ((int)((CHAR_BIT * sizeof(mp_digit) - 1))) /* bits per digit */ 91 #define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */
92 typedef uint_least32_t mp_min_u32;
93 #else
94 typedef mp_digit mp_min_u32;
95 #endif
96
97 /* platforms that can use a better rand function */
98 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
99 #define MP_USE_ALT_RAND 1
100 #endif
101
102 /* use arc4random on platforms that support it */
103 #ifdef MP_USE_ALT_RAND
104 #define MP_GEN_RANDOM() arc4random()
105 #else
106 #define MP_GEN_RANDOM() rand()
128 #endif 107 #endif
129 108
130 #define MP_DIGIT_BIT DIGIT_BIT 109 #define MP_DIGIT_BIT DIGIT_BIT
131 #define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1)) 110 #define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
132 #define MP_DIGIT_MAX MP_MASK 111 #define MP_DIGIT_MAX MP_MASK
167 #ifndef MP_PREC 146 #ifndef MP_PREC
168 #ifndef MP_LOW_MEM 147 #ifndef MP_LOW_MEM
169 #define MP_PREC 32 /* default digits of precision */ 148 #define MP_PREC 32 /* default digits of precision */
170 #else 149 #else
171 #define MP_PREC 8 /* default digits of precision */ 150 #define MP_PREC 8 /* default digits of precision */
172 #endif 151 #endif
173 #endif 152 #endif
174 153
175 /* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */ 154 /* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
176 #define MP_WARRAY (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1)) 155 #define MP_WARRAY (1 << (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT)) + 1))
177 156
178 /* the infamous mp_int structure */ 157 /* the infamous mp_int structure */
179 typedef struct { 158 typedef struct {
180 int used, alloc, sign; 159 int used, alloc, sign;
181 mp_digit *dp; 160 mp_digit *dp;
188 #define USED(m) ((m)->used) 167 #define USED(m) ((m)->used)
189 #define DIGIT(m,k) ((m)->dp[(k)]) 168 #define DIGIT(m,k) ((m)->dp[(k)])
190 #define SIGN(m) ((m)->sign) 169 #define SIGN(m) ((m)->sign)
191 170
192 /* error code to char* string */ 171 /* error code to char* string */
193 char *mp_error_to_string(int code); 172 const char *mp_error_to_string(int code);
194 173
195 /* ---> init and deinit bignum functions <--- */ 174 /* ---> init and deinit bignum functions <--- */
196 /* init a bignum */ 175 /* init a bignum */
197 int mp_init(mp_int *a); 176 int mp_init(mp_int *a);
198 177
217 /* init to a given number of digits */ 196 /* init to a given number of digits */
218 int mp_init_size(mp_int *a, int size); 197 int mp_init_size(mp_int *a, int size);
219 198
220 /* ---> Basic Manipulations <--- */ 199 /* ---> Basic Manipulations <--- */
221 #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO) 200 #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
222 #define mp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO) 201 #define mp_iseven(a) ((((a)->used > 0) && (((a)->dp[0] & 1u) == 0u)) ? MP_YES : MP_NO)
223 #define mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO) 202 #define mp_isodd(a) ((((a)->used > 0) && (((a)->dp[0] & 1u) == 1u)) ? MP_YES : MP_NO)
203 #define mp_isneg(a) (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO)
224 204
225 /* set to zero */ 205 /* set to zero */
226 void mp_zero(mp_int *a); 206 void mp_zero(mp_int *a);
227 207
228 /* set to a digit */ 208 /* set to a digit */
229 void mp_set(mp_int *a, mp_digit b); 209 void mp_set(mp_int *a, mp_digit b);
230 210
231 /* set a 32-bit const */ 211 /* set a 32-bit const */
232 int mp_set_int(mp_int *a, unsigned long b); 212 int mp_set_int(mp_int *a, unsigned long b);
233 213
214 /* set a platform dependent unsigned long value */
215 int mp_set_long(mp_int *a, unsigned long b);
216
217 /* set a platform dependent unsigned long long value */
218 int mp_set_long_long(mp_int *a, unsigned long long b);
219
234 /* get a 32-bit value */ 220 /* get a 32-bit value */
235 unsigned long mp_get_int(mp_int * a); 221 unsigned long mp_get_int(mp_int * a);
236 222
223 /* get a platform dependent unsigned long value */
224 unsigned long mp_get_long(mp_int * a);
225
226 /* get a platform dependent unsigned long long value */
227 unsigned long long mp_get_long_long(mp_int * a);
228
237 /* initialize and set a digit */ 229 /* initialize and set a digit */
238 int mp_init_set (mp_int * a, mp_digit b); 230 int mp_init_set (mp_int * a, mp_digit b);
239 231
240 /* initialize and set 32-bit value */ 232 /* initialize and set 32-bit value */
241 int mp_init_set_int (mp_int * a, unsigned long b); 233 int mp_init_set_int (mp_int * a, unsigned long b);
247 int mp_init_copy(mp_int *a, mp_int *b); 239 int mp_init_copy(mp_int *a, mp_int *b);
248 240
249 /* trim unused digits */ 241 /* trim unused digits */
250 void mp_clamp(mp_int *a); 242 void mp_clamp(mp_int *a);
251 243
244 /* import binary data */
245 int mp_import(mp_int* rop, size_t count, int order, size_t size, int endian, size_t nails, const void* op);
246
247 /* export binary data */
248 int mp_export(void* rop, size_t* countp, int order, size_t size, int endian, size_t nails, mp_int* op);
249
252 /* ---> digit manipulation <--- */ 250 /* ---> digit manipulation <--- */
253 251
254 /* right shift by "b" digits */ 252 /* right shift by "b" digits */
255 void mp_rshd(mp_int *a, int b); 253 void mp_rshd(mp_int *a, int b);
256 254
257 /* left shift by "b" digits */ 255 /* left shift by "b" digits */
258 int mp_lshd(mp_int *a, int b); 256 int mp_lshd(mp_int *a, int b);
259 257
260 /* c = a / 2**b */ 258 /* c = a / 2**b, implemented as c = a >> b */
261 int mp_div_2d(mp_int *a, int b, mp_int *c, mp_int *d); 259 int mp_div_2d(mp_int *a, int b, mp_int *c, mp_int *d);
262 260
263 /* b = a/2 */ 261 /* b = a/2 */
264 int mp_div_2(mp_int *a, mp_int *b); 262 int mp_div_2(mp_int *a, mp_int *b);
265 263
266 /* c = a * 2**b */ 264 /* c = a * 2**b, implemented as c = a << b */
267 int mp_mul_2d(mp_int *a, int b, mp_int *c); 265 int mp_mul_2d(mp_int *a, int b, mp_int *c);
268 266
269 /* b = a*2 */ 267 /* b = a*2 */
270 int mp_mul_2(mp_int *a, mp_int *b); 268 int mp_mul_2(mp_int *a, mp_int *b);
271 269
272 /* c = a mod 2**d */ 270 /* c = a mod 2**b */
273 int mp_mod_2d(mp_int *a, int b, mp_int *c); 271 int mp_mod_2d(mp_int *a, int b, mp_int *c);
274 272
275 /* computes a = 2**b */ 273 /* computes a = 2**b */
276 int mp_2expt(mp_int *a, int b); 274 int mp_2expt(mp_int *a, int b);
277 275
345 /* a/3 => 3c + d == a */ 343 /* a/3 => 3c + d == a */
346 int mp_div_3(mp_int *a, mp_int *c, mp_digit *d); 344 int mp_div_3(mp_int *a, mp_int *c, mp_digit *d);
347 345
348 /* c = a**b */ 346 /* c = a**b */
349 int mp_expt_d(mp_int *a, mp_digit b, mp_int *c); 347 int mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
348 int mp_expt_d_ex (mp_int * a, mp_digit b, mp_int * c, int fast);
350 349
351 /* c = a mod b, 0 <= c < b */ 350 /* c = a mod b, 0 <= c < b */
352 int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c); 351 int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c);
353 352
354 /* ---> number theory <--- */ 353 /* ---> number theory <--- */
380 /* finds one of the b'th root of a, such that |c|**b <= |a| 379 /* finds one of the b'th root of a, such that |c|**b <= |a|
381 * 380 *
382 * returns error if a < 0 and b is even 381 * returns error if a < 0 and b is even
383 */ 382 */
384 int mp_n_root(mp_int *a, mp_digit b, mp_int *c); 383 int mp_n_root(mp_int *a, mp_digit b, mp_int *c);
384 int mp_n_root_ex (mp_int * a, mp_digit b, mp_int * c, int fast);
385 385
386 /* special sqrt algo */ 386 /* special sqrt algo */
387 int mp_sqrt(mp_int *arg, mp_int *ret); 387 int mp_sqrt(mp_int *arg, mp_int *ret);
388
389 /* special sqrt (mod prime) */
390 int mp_sqrtmod_prime(mp_int *arg, mp_int *prime, mp_int *ret);
388 391
389 /* is number a square? */ 392 /* is number a square? */
390 int mp_is_square(mp_int *arg, int *ret); 393 int mp_is_square(mp_int *arg, int *ret);
391 394
392 /* computes the jacobi c = (a | n) (or Legendre if b is prime) */ 395 /* computes the jacobi c = (a | n) (or Legendre if b is prime) */
451 #else 454 #else
452 #define PRIME_SIZE 256 455 #define PRIME_SIZE 256
453 #endif 456 #endif
454 457
455 /* table of first PRIME_SIZE primes */ 458 /* table of first PRIME_SIZE primes */
456 extern const mp_digit ltm_prime_tab[]; 459 extern const mp_digit ltm_prime_tab[PRIME_SIZE];
457 460
458 /* result=1 if a is divisible by one of the first PRIME_SIZE primes */ 461 /* result=1 if a is divisible by one of the first PRIME_SIZE primes */
459 int mp_prime_is_divisible(mp_int *a, int *result); 462 int mp_prime_is_divisible(mp_int *a, int *result);
460 463
461 /* performs one Fermat test of "a" using base "b". 464 /* performs one Fermat test of "a" using base "b".
467 * Sets result to 0 if composite or 1 if probable prime 470 * Sets result to 0 if composite or 1 if probable prime
468 */ 471 */
469 int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result); 472 int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result);
470 473
471 /* This gives [for a given bit size] the number of trials required 474 /* This gives [for a given bit size] the number of trials required
472 * such that Miller-Rabin gives a prob of failure lower than 2^-96 475 * such that Miller-Rabin gives a prob of failure lower than 2^-96
473 */ 476 */
474 int mp_prime_rabin_miller_trials(int size); 477 int mp_prime_rabin_miller_trials(int size);
475 478
476 /* performs t rounds of Miller-Rabin on "a" using the first 479 /* performs t rounds of Miller-Rabin on "a" using the first
477 * t prime bases. Also performs an initial sieve of trial 480 * t prime bases. Also performs an initial sieve of trial
488 * bbs_style = 1 means the prime must be congruent to 3 mod 4 491 * bbs_style = 1 means the prime must be congruent to 3 mod 4
489 */ 492 */
490 int mp_prime_next_prime(mp_int *a, int t, int bbs_style); 493 int mp_prime_next_prime(mp_int *a, int t, int bbs_style);
491 494
492 /* makes a truly random prime of a given size (bytes), 495 /* makes a truly random prime of a given size (bytes),
493 * call with bbs = 1 if you want it to be congruent to 3 mod 4 496 * call with bbs = 1 if you want it to be congruent to 3 mod 4
494 * 497 *
495 * You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can 498 * You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can
496 * have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself 499 * have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself
497 * so it can be NULL 500 * so it can be NULL
498 * 501 *
501 #define mp_prime_random(a, t, size, bbs, cb, dat) mp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?LTM_PRIME_BBS:0, cb, dat) 504 #define mp_prime_random(a, t, size, bbs, cb, dat) mp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?LTM_PRIME_BBS:0, cb, dat)
502 505
503 /* makes a truly random prime of a given size (bits), 506 /* makes a truly random prime of a given size (bits),
504 * 507 *
505 * Flags are as follows: 508 * Flags are as follows:
506 * 509 *
507 * LTM_PRIME_BBS - make prime congruent to 3 mod 4 510 * LTM_PRIME_BBS - make prime congruent to 3 mod 4
508 * LTM_PRIME_SAFE - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS) 511 * LTM_PRIME_SAFE - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
509 * LTM_PRIME_2MSB_OFF - make the 2nd highest bit zero
510 * LTM_PRIME_2MSB_ON - make the 2nd highest bit one 512 * LTM_PRIME_2MSB_ON - make the 2nd highest bit one
511 * 513 *
512 * You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can 514 * You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can
513 * have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself 515 * have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself
514 * so it can be NULL 516 * so it can be NULL
532 int mp_read_radix(mp_int *a, const char *str, int radix); 534 int mp_read_radix(mp_int *a, const char *str, int radix);
533 int mp_toradix(mp_int *a, char *str, int radix); 535 int mp_toradix(mp_int *a, char *str, int radix);
534 int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen); 536 int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen);
535 int mp_radix_size(mp_int *a, int radix, int *size); 537 int mp_radix_size(mp_int *a, int radix, int *size);
536 538
539 #ifndef LTM_NO_FILE
537 int mp_fread(mp_int *a, int radix, FILE *stream); 540 int mp_fread(mp_int *a, int radix, FILE *stream);
538 int mp_fwrite(mp_int *a, int radix, FILE *stream); 541 int mp_fwrite(mp_int *a, int radix, FILE *stream);
542 #endif
539 543
540 #define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len)) 544 #define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
541 #define mp_raw_size(mp) mp_signed_bin_size(mp) 545 #define mp_raw_size(mp) mp_signed_bin_size(mp)
542 #define mp_toraw(mp, str) mp_to_signed_bin((mp), (str)) 546 #define mp_toraw(mp, str) mp_to_signed_bin((mp), (str))
543 #define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len)) 547 #define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
547 #define mp_tobinary(M, S) mp_toradix((M), (S), 2) 551 #define mp_tobinary(M, S) mp_toradix((M), (S), 2)
548 #define mp_tooctal(M, S) mp_toradix((M), (S), 8) 552 #define mp_tooctal(M, S) mp_toradix((M), (S), 8)
549 #define mp_todecimal(M, S) mp_toradix((M), (S), 10) 553 #define mp_todecimal(M, S) mp_toradix((M), (S), 10)
550 #define mp_tohex(M, S) mp_toradix((M), (S), 16) 554 #define mp_tohex(M, S) mp_toradix((M), (S), 16)
551 555
552 /* lowlevel functions, do not call! */
553 int s_mp_add(mp_int *a, mp_int *b, mp_int *c);
554 int s_mp_sub(mp_int *a, mp_int *b, mp_int *c);
555 #define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
556 int fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
557 int s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
558 int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
559 int s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
560 int fast_s_mp_sqr(mp_int *a, mp_int *b);
561 int s_mp_sqr(mp_int *a, mp_int *b);
562 int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c);
563 int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
564 int mp_karatsuba_sqr(mp_int *a, mp_int *b);
565 int mp_toom_sqr(mp_int *a, mp_int *b);
566 int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c);
567 int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c);
568 int fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
569 int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode);
570 int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int mode);
571 void bn_reverse(unsigned char *s, int len);
572
573 extern const char *mp_s_rmap;
574
575 #ifdef __cplusplus 556 #ifdef __cplusplus
576 } 557 }
577 #endif 558 #endif
578 559
579 #endif 560 #endif