tommath.h

Go to the documentation of this file.
00001 /* LibTomMath, multiple-precision integer library -- Tom St Denis
00002  *
00003  * LibTomMath is a library that provides multiple-precision
00004  * integer arithmetic as well as number theoretic functionality.
00005  *
00006  * The library was designed directly after the MPI library by
00007  * Michael Fromberger but has been written from scratch with
00008  * additional optimizations in place.
00009  *
00010  * The library is free for all purposes without any express
00011  * guarantee it works.
00012  *
00013  * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
00014  */
00015 #ifndef BN_H_
00016 #define BN_H_
00017 
00018 #include <stdio.h>
00019 #include <string.h>
00020 #include <stdlib.h>
00021 #include <ctype.h>
00022 #include <limits.h>
00023 
00024 #include <tommath_class.h>
00025 
00026 #ifndef MIN
00027    #define MIN(x,y) ((x)<(y)?(x):(y))
00028 #endif
00029 
00030 #ifndef MAX
00031    #define MAX(x,y) ((x)>(y)?(x):(y))
00032 #endif
00033 
00034 #ifdef __cplusplus
00035 extern "C" {
00036 
00037 /* C++ compilers don't like assigning void * to mp_digit * */
00038 #define  OPT_CAST(x)  (x *)
00039 
00040 #else
00041 
00042 /* C on the other hand doesn't care */
00043 #define  OPT_CAST(x)
00044 
00045 #endif
00046 
00047 
00048 /* detect 64-bit mode if possible */
00049 #if defined(__x86_64__) 
00050    #if !(defined(MP_64BIT) && defined(MP_16BIT) && defined(MP_8BIT))
00051       #define MP_64BIT
00052    #endif
00053 #endif
00054 
00055 /* some default configurations.
00056  *
00057  * A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
00058  * A "mp_word" must be able to hold 2*DIGIT_BIT + 1 bits
00059  *
00060  * At the very least a mp_digit must be able to hold 7 bits
00061  * [any size beyond that is ok provided it doesn't overflow the data type]
00062  */
00063 #ifdef MP_8BIT
00064    typedef unsigned char      mp_digit;
00065    typedef unsigned short     mp_word;
00066 #elif defined(MP_16BIT)
00067    typedef unsigned short     mp_digit;
00068    typedef unsigned long      mp_word;
00069 #elif defined(MP_64BIT)
00070    /* for GCC only on supported platforms */
00071 #ifndef CRYPT
00072    typedef unsigned long long ulong64;
00073    typedef signed long long   long64;
00074 #endif
00075 
00076    typedef unsigned long      mp_digit;
00077    typedef unsigned long      mp_word __attribute__ ((mode(TI)));
00078 
00079    #define DIGIT_BIT          60
00080 #else
00081    /* this is the default case, 28-bit digits */
00082    
00083    /* this is to make porting into LibTomCrypt easier :-) */
00084 #ifndef CRYPT
00085    #if defined(_MSC_VER) || defined(__BORLANDC__) 
00086       typedef unsigned __int64   ulong64;
00087       typedef signed __int64     long64;
00088    #else
00089       typedef unsigned long long ulong64;
00090       typedef signed long long   long64;
00091    #endif
00092 #endif
00093 
00094    typedef unsigned long      mp_digit;
00095    typedef ulong64            mp_word;
00096 
00097 #ifdef MP_31BIT   
00098    /* this is an extension that uses 31-bit digits */
00099    #define DIGIT_BIT          31
00100 #else
00101    /* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */
00102    #define DIGIT_BIT          28
00103    #define MP_28BIT
00104 #endif   
00105 #endif
00106 
00107 /* define heap macros */
00108 #ifndef CRYPT
00109    /* default to libc stuff */
00110    #ifndef XMALLOC 
00111        #define XMALLOC  malloc
00112        #define XFREE    free
00113        #define XREALLOC realloc
00114        #define XCALLOC  calloc
00115    #else
00116       /* prototypes for our heap functions */
00117       extern void *XMALLOC(size_t n);
00118       extern void *XREALLOC(void *p, size_t n);
00119       extern void *XCALLOC(size_t n, size_t s);
00120       extern void XFREE(void *p);
00121    #endif
00122 #endif
00123 
00124 
00125 /* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
00126 #ifndef DIGIT_BIT
00127    #define DIGIT_BIT     ((int)((CHAR_BIT * sizeof(mp_digit) - 1)))  /* bits per digit */
00128 #endif
00129 
00130 #define MP_DIGIT_BIT     DIGIT_BIT
00131 #define MP_MASK          ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
00132 #define MP_DIGIT_MAX     MP_MASK
00133 
00134 /* equalities */
00135 #define MP_LT        -1   /* less than */
00136 #define MP_EQ         0   /* equal to */
00137 #define MP_GT         1   /* greater than */
00138 
00139 #define MP_ZPOS       0   /* positive integer */
00140 #define MP_NEG        1   /* negative */
00141 
00142 #define MP_OKAY       0   /* ok result */
00143 #define MP_MEM        -2  /* out of mem */
00144 #define MP_VAL        -3  /* invalid input */
00145 #define MP_RANGE      MP_VAL
00146 
00147 #define MP_YES        1   /* yes response */
00148 #define MP_NO         0   /* no response */
00149 
00150 /* Primality generation flags */
00151 #define LTM_PRIME_BBS      0x0001 /* BBS style prime */
00152 #define LTM_PRIME_SAFE     0x0002 /* Safe prime (p-1)/2 == prime */
00153 #define LTM_PRIME_2MSB_ON  0x0008 /* force 2nd MSB to 1 */
00154 
00155 typedef int           mp_err;
00156 
00157 /* you'll have to tune these... */
00158 extern int KARATSUBA_MUL_CUTOFF,
00159            KARATSUBA_SQR_CUTOFF,
00160            TOOM_MUL_CUTOFF,
00161            TOOM_SQR_CUTOFF;
00162 
00163 /* define this to use lower memory usage routines (exptmods mostly) */
00164 /* #define MP_LOW_MEM */
00165 
00166 /* default precision */
00167 #ifndef MP_PREC
00168    #ifndef MP_LOW_MEM
00169       #define MP_PREC                 32     /* default digits of precision */
00170    #else
00171       #define MP_PREC                 8      /* default digits of precision */
00172    #endif   
00173 #endif
00174 
00175 /* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
00176 #define MP_WARRAY               (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
00177 
00178 /* the infamous mp_int structure */
00179 typedef struct  {
00180     int used, alloc, sign;
00181     mp_digit *dp;
00182 } mp_int;
00183 
00184 /* callback for mp_prime_random, should fill dst with random bytes and return how many read [upto len] */
00185 typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
00186 
00187 
00188 #define USED(m)    ((m)->used)
00189 #define DIGIT(m,k) ((m)->dp[(k)])
00190 #define SIGN(m)    ((m)->sign)
00191 
00192 /* error code to char* string */
00193 char *mp_error_to_string(int code);
00194 
00195 /* ---> init and deinit bignum functions <--- */
00196 /* init a bignum */
00197 int mp_init(mp_int *a);
00198 
00199 /* free a bignum */
00200 void mp_clear(mp_int *a);
00201 
00202 /* init a null terminated series of arguments */
00203 int mp_init_multi(mp_int *mp, ...);
00204 
00205 /* clear a null terminated series of arguments */
00206 void mp_clear_multi(mp_int *mp, ...);
00207 
00208 /* exchange two ints */
00209 void mp_exch(mp_int *a, mp_int *b);
00210 
00211 /* shrink ram required for a bignum */
00212 int mp_shrink(mp_int *a);
00213 
00214 /* grow an int to a given size */
00215 int mp_grow(mp_int *a, int size);
00216 
00217 /* init to a given number of digits */
00218 int mp_init_size(mp_int *a, int size);
00219 
00220 /* ---> Basic Manipulations <--- */
00221 #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
00222 #define mp_iseven(a) (((a)->used == 0 || (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
00223 #define mp_isodd(a)  (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
00224 
00225 /* set to zero */
00226 void mp_zero(mp_int *a);
00227 
00228 /* set to a digit */
00229 void mp_set(mp_int *a, mp_digit b);
00230 
00231 /* set a 32-bit const */
00232 int mp_set_int(mp_int *a, unsigned long b);
00233 
00234 /* get a 32-bit value */
00235 unsigned long mp_get_int(mp_int * a);
00236 
00237 /* initialize and set a digit */
00238 int mp_init_set (mp_int * a, mp_digit b);
00239 
00240 /* initialize and set 32-bit value */
00241 int mp_init_set_int (mp_int * a, unsigned long b);
00242 
00243 /* copy, b = a */
00244 int mp_copy(mp_int *a, mp_int *b);
00245 
00246 /* inits and copies, a = b */
00247 int mp_init_copy(mp_int *a, mp_int *b);
00248 
00249 /* trim unused digits */
00250 void mp_clamp(mp_int *a);
00251 
00252 /* ---> digit manipulation <--- */
00253 
00254 /* right shift by "b" digits */
00255 void mp_rshd(mp_int *a, int b);
00256 
00257 /* left shift by "b" digits */
00258 int mp_lshd(mp_int *a, int b);
00259 
00260 /* c = a / 2**b */
00261 int mp_div_2d(mp_int *a, int b, mp_int *c, mp_int *d);
00262 
00263 /* b = a/2 */
00264 int mp_div_2(mp_int *a, mp_int *b);
00265 
00266 /* c = a * 2**b */
00267 int mp_mul_2d(mp_int *a, int b, mp_int *c);
00268 
00269 /* b = a*2 */
00270 int mp_mul_2(mp_int *a, mp_int *b);
00271 
00272 /* c = a mod 2**d */
00273 int mp_mod_2d(mp_int *a, int b, mp_int *c);
00274 
00275 /* computes a = 2**b */
00276 int mp_2expt(mp_int *a, int b);
00277 
00278 /* Counts the number of lsbs which are zero before the first zero bit */
00279 int mp_cnt_lsb(mp_int *a);
00280 
00281 /* I Love Earth! */
00282 
00283 /* makes a pseudo-random int of a given size */
00284 int mp_rand(mp_int *a, int digits);
00285 
00286 /* ---> binary operations <--- */
00287 /* c = a XOR b  */
00288 int mp_xor(mp_int *a, mp_int *b, mp_int *c);
00289 
00290 /* c = a OR b */
00291 int mp_or(mp_int *a, mp_int *b, mp_int *c);
00292 
00293 /* c = a AND b */
00294 int mp_and(mp_int *a, mp_int *b, mp_int *c);
00295 
00296 /* ---> Basic arithmetic <--- */
00297 
00298 /* b = -a */
00299 int mp_neg(mp_int *a, mp_int *b);
00300 
00301 /* b = |a| */
00302 int mp_abs(mp_int *a, mp_int *b);
00303 
00304 /* compare a to b */
00305 int mp_cmp(mp_int *a, mp_int *b);
00306 
00307 /* compare |a| to |b| */
00308 int mp_cmp_mag(mp_int *a, mp_int *b);
00309 
00310 /* c = a + b */
00311 int mp_add(mp_int *a, mp_int *b, mp_int *c);
00312 
00313 /* c = a - b */
00314 int mp_sub(mp_int *a, mp_int *b, mp_int *c);
00315 
00316 /* c = a * b */
00317 int mp_mul(mp_int *a, mp_int *b, mp_int *c);
00318 
00319 /* b = a*a  */
00320 int mp_sqr(mp_int *a, mp_int *b);
00321 
00322 /* a/b => cb + d == a */
00323 int mp_div(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
00324 
00325 /* c = a mod b, 0 <= c < b  */
00326 int mp_mod(mp_int *a, mp_int *b, mp_int *c);
00327 
00328 /* ---> single digit functions <--- */
00329 
00330 /* compare against a single digit */
00331 int mp_cmp_d(mp_int *a, mp_digit b);
00332 
00333 /* c = a + b */
00334 int mp_add_d(mp_int *a, mp_digit b, mp_int *c);
00335 
00336 /* c = a - b */
00337 int mp_sub_d(mp_int *a, mp_digit b, mp_int *c);
00338 
00339 /* c = a * b */
00340 int mp_mul_d(mp_int *a, mp_digit b, mp_int *c);
00341 
00342 /* a/b => cb + d == a */
00343 int mp_div_d(mp_int *a, mp_digit b, mp_int *c, mp_digit *d);
00344 
00345 /* a/3 => 3c + d == a */
00346 int mp_div_3(mp_int *a, mp_int *c, mp_digit *d);
00347 
00348 /* c = a**b */
00349 int mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
00350 
00351 /* c = a mod b, 0 <= c < b  */
00352 int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c);
00353 
00354 /* ---> number theory <--- */
00355 
00356 /* d = a + b (mod c) */
00357 int mp_addmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
00358 
00359 /* d = a - b (mod c) */
00360 int mp_submod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
00361 
00362 /* d = a * b (mod c) */
00363 int mp_mulmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
00364 
00365 /* c = a * a (mod b) */
00366 int mp_sqrmod(mp_int *a, mp_int *b, mp_int *c);
00367 
00368 /* c = 1/a (mod b) */
00369 int mp_invmod(mp_int *a, mp_int *b, mp_int *c);
00370 
00371 /* c = (a, b) */
00372 int mp_gcd(mp_int *a, mp_int *b, mp_int *c);
00373 
00374 /* produces value such that U1*a + U2*b = U3 */
00375 int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3);
00376 
00377 /* c = [a, b] or (a*b)/(a, b) */
00378 int mp_lcm(mp_int *a, mp_int *b, mp_int *c);
00379 
00380 /* finds one of the b'th root of a, such that |c|**b <= |a|
00381  *
00382  * returns error if a < 0 and b is even
00383  */
00384 int mp_n_root(mp_int *a, mp_digit b, mp_int *c);
00385 
00386 /* special sqrt algo */
00387 int mp_sqrt(mp_int *arg, mp_int *ret);
00388 
00389 /* is number a square? */
00390 int mp_is_square(mp_int *arg, int *ret);
00391 
00392 /* computes the jacobi c = (a | n) (or Legendre if b is prime)  */
00393 int mp_jacobi(mp_int *a, mp_int *n, int *c);
00394 
00395 /* used to setup the Barrett reduction for a given modulus b */
00396 int mp_reduce_setup(mp_int *a, mp_int *b);
00397 
00398 /* Barrett Reduction, computes a (mod b) with a precomputed value c
00399  *
00400  * Assumes that 0 < a <= b*b, note if 0 > a > -(b*b) then you can merely
00401  * compute the reduction as -1 * mp_reduce(mp_abs(a)) [pseudo code].
00402  */
00403 int mp_reduce(mp_int *a, mp_int *b, mp_int *c);
00404 
00405 /* setups the montgomery reduction */
00406 int mp_montgomery_setup(mp_int *a, mp_digit *mp);
00407 
00408 /* computes a = B**n mod b without division or multiplication useful for
00409  * normalizing numbers in a Montgomery system.
00410  */
00411 int mp_montgomery_calc_normalization(mp_int *a, mp_int *b);
00412 
00413 /* computes x/R == x (mod N) via Montgomery Reduction */
00414 int mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
00415 
00416 /* returns 1 if a is a valid DR modulus */
00417 int mp_dr_is_modulus(mp_int *a);
00418 
00419 /* sets the value of "d" required for mp_dr_reduce */
00420 void mp_dr_setup(mp_int *a, mp_digit *d);
00421 
00422 /* reduces a modulo b using the Diminished Radix method */
00423 int mp_dr_reduce(mp_int *a, mp_int *b, mp_digit mp);
00424 
00425 /* returns true if a can be reduced with mp_reduce_2k */
00426 int mp_reduce_is_2k(mp_int *a);
00427 
00428 /* determines k value for 2k reduction */
00429 int mp_reduce_2k_setup(mp_int *a, mp_digit *d);
00430 
00431 /* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
00432 int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d);
00433 
00434 /* returns true if a can be reduced with mp_reduce_2k_l */
00435 int mp_reduce_is_2k_l(mp_int *a);
00436 
00437 /* determines k value for 2k reduction */
00438 int mp_reduce_2k_setup_l(mp_int *a, mp_int *d);
00439 
00440 /* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
00441 int mp_reduce_2k_l(mp_int *a, mp_int *n, mp_int *d);
00442 
00443 /* d = a**b (mod c) */
00444 int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
00445 
00446 /* ---> Primes <--- */
00447 
00448 /* number of primes */
00449 #ifdef MP_8BIT
00450    #define PRIME_SIZE      31
00451 #else
00452    #define PRIME_SIZE      256
00453 #endif
00454 
00455 /* table of first PRIME_SIZE primes */
00456 extern const mp_digit ltm_prime_tab[];
00457 
00458 /* result=1 if a is divisible by one of the first PRIME_SIZE primes */
00459 int mp_prime_is_divisible(mp_int *a, int *result);
00460 
00461 /* performs one Fermat test of "a" using base "b".
00462  * Sets result to 0 if composite or 1 if probable prime
00463  */
00464 int mp_prime_fermat(mp_int *a, mp_int *b, int *result);
00465 
00466 /* performs one Miller-Rabin test of "a" using base "b".
00467  * Sets result to 0 if composite or 1 if probable prime
00468  */
00469 int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result);
00470 
00471 /* This gives [for a given bit size] the number of trials required
00472  * such that Miller-Rabin gives a prob of failure lower than 2^-96 
00473  */
00474 int mp_prime_rabin_miller_trials(int size);
00475 
00476 /* performs t rounds of Miller-Rabin on "a" using the first
00477  * t prime bases.  Also performs an initial sieve of trial
00478  * division.  Determines if "a" is prime with probability
00479  * of error no more than (1/4)**t.
00480  *
00481  * Sets result to 1 if probably prime, 0 otherwise
00482  */
00483 int mp_prime_is_prime(mp_int *a, int t, int *result);
00484 
00485 /* finds the next prime after the number "a" using "t" trials
00486  * of Miller-Rabin.
00487  *
00488  * bbs_style = 1 means the prime must be congruent to 3 mod 4
00489  */
00490 int mp_prime_next_prime(mp_int *a, int t, int bbs_style);
00491 
00492 /* makes a truly random prime of a given size (bytes),
00493  * call with bbs = 1 if you want it to be congruent to 3 mod 4 
00494  *
00495  * You have to supply a callback which fills in a buffer with random bytes.  "dat" is a parameter you can
00496  * have passed to the callback (e.g. a state or something).  This function doesn't use "dat" itself
00497  * so it can be NULL
00498  *
00499  * The prime generated will be larger than 2^(8*size).
00500  */
00501 #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)
00502 
00503 /* makes a truly random prime of a given size (bits),
00504  *
00505  * Flags are as follows:
00506  * 
00507  *   LTM_PRIME_BBS      - make prime congruent to 3 mod 4
00508  *   LTM_PRIME_SAFE     - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
00509  *   LTM_PRIME_2MSB_OFF - make the 2nd highest bit zero
00510  *   LTM_PRIME_2MSB_ON  - make the 2nd highest bit one
00511  *
00512  * You have to supply a callback which fills in a buffer with random bytes.  "dat" is a parameter you can
00513  * have passed to the callback (e.g. a state or something).  This function doesn't use "dat" itself
00514  * so it can be NULL
00515  *
00516  */
00517 int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat);
00518 
00519 /* ---> radix conversion <--- */
00520 int mp_count_bits(mp_int *a);
00521 
00522 int mp_unsigned_bin_size(mp_int *a);
00523 int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c);
00524 int mp_to_unsigned_bin(mp_int *a, unsigned char *b);
00525 int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
00526 
00527 int mp_signed_bin_size(mp_int *a);
00528 int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c);
00529 int mp_to_signed_bin(mp_int *a,  unsigned char *b);
00530 int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
00531 
00532 int mp_read_radix(mp_int *a, const char *str, int radix);
00533 int mp_toradix(mp_int *a, char *str, int radix);
00534 int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen);
00535 int mp_radix_size(mp_int *a, int radix, int *size);
00536 
00537 int mp_fread(mp_int *a, int radix, FILE *stream);
00538 int mp_fwrite(mp_int *a, int radix, FILE *stream);
00539 
00540 #define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
00541 #define mp_raw_size(mp)           mp_signed_bin_size(mp)
00542 #define mp_toraw(mp, str)         mp_to_signed_bin((mp), (str))
00543 #define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
00544 #define mp_mag_size(mp)           mp_unsigned_bin_size(mp)
00545 #define mp_tomag(mp, str)         mp_to_unsigned_bin((mp), (str))
00546 
00547 #define mp_tobinary(M, S)  mp_toradix((M), (S), 2)
00548 #define mp_tooctal(M, S)   mp_toradix((M), (S), 8)
00549 #define mp_todecimal(M, S) mp_toradix((M), (S), 10)
00550 #define mp_tohex(M, S)     mp_toradix((M), (S), 16)
00551 
00552 /* lowlevel functions, do not call! */
00553 int s_mp_add(mp_int *a, mp_int *b, mp_int *c);
00554 int s_mp_sub(mp_int *a, mp_int *b, mp_int *c);
00555 #define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
00556 int fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
00557 int s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
00558 int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
00559 int s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
00560 int fast_s_mp_sqr(mp_int *a, mp_int *b);
00561 int s_mp_sqr(mp_int *a, mp_int *b);
00562 int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c);
00563 int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
00564 int mp_karatsuba_sqr(mp_int *a, mp_int *b);
00565 int mp_toom_sqr(mp_int *a, mp_int *b);
00566 int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c);
00567 int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c);
00568 int fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
00569 int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode);
00570 int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int mode);
00571 void bn_reverse(unsigned char *s, int len);
00572 
00573 extern const char *mp_s_rmap;
00574 
00575 #ifdef __cplusplus
00576    }
00577 #endif
00578 
00579 #endif
00580 
00581 
00582 /* $Source: /cvsroot/tcl/libtommath/tommath.h,v $ */
00583 /* Based on Tom's version 1.8 */
00584 /* $Revision: 1.4 $ */
00585 /* $Date: 2006/12/01 00:31:32 $ */



Generated on Wed Mar 12 12:18:24 2008 by  doxygen 1.5.1