comparison ltc_tommath.h @ 143:5d99163f7e32 libtomcrypt-orig

import of libtomcrypt 0.99
author Matt Johnston <matt@ucc.asn.au>
date Sun, 19 Dec 2004 11:34:45 +0000
parents 6362d3854bb4
children
comparison
equal deleted inserted replaced
15:6362d3854bb4 143:5d99163f7e32
19 #include <string.h> 19 #include <string.h>
20 #include <stdlib.h> 20 #include <stdlib.h>
21 #include <ctype.h> 21 #include <ctype.h>
22 #include <limits.h> 22 #include <limits.h>
23 23
24 #include <tommath_class.h>
25
24 #undef MIN 26 #undef MIN
25 #define MIN(x,y) ((x)<(y)?(x):(y)) 27 #define MIN(x,y) ((x)<(y)?(x):(y))
26 #undef MAX 28 #undef MAX
27 #define MAX(x,y) ((x)>(y)?(x):(y)) 29 #define MAX(x,y) ((x)>(y)?(x):(y))
28 30
35 #else 37 #else
36 38
37 /* C on the other hand doesn't care */ 39 /* C on the other hand doesn't care */
38 #define OPT_CAST(x) 40 #define OPT_CAST(x)
39 41
42 #endif
43
44
45 /* detect 64-bit mode if possible */
46 #if defined(__x86_64__)
47 #if !(defined(MP_64BIT) && defined(MP_16BIT) && defined(MP_8BIT))
48 #define MP_64BIT
49 #endif
40 #endif 50 #endif
41 51
42 /* some default configurations. 52 /* some default configurations.
43 * 53 *
44 * A "mp_digit" must be able to hold DIGIT_BIT + 1 bits 54 * A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
58 #ifndef CRYPT 68 #ifndef CRYPT
59 typedef unsigned long long ulong64; 69 typedef unsigned long long ulong64;
60 typedef signed long long long64; 70 typedef signed long long long64;
61 #endif 71 #endif
62 72
63 typedef ulong64 mp_digit; 73 typedef unsigned long mp_digit;
64 typedef unsigned long mp_word __attribute__ ((mode(TI))); 74 typedef unsigned long mp_word __attribute__ ((mode(TI)));
65 75
66 #define DIGIT_BIT 60 76 #define DIGIT_BIT 60
67 #else 77 #else
68 /* this is the default case, 28-bit digits */ 78 /* this is the default case, 28-bit digits */
151 /* define this to use lower memory usage routines (exptmods mostly) */ 161 /* define this to use lower memory usage routines (exptmods mostly) */
152 /* #define MP_LOW_MEM */ 162 /* #define MP_LOW_MEM */
153 163
154 /* default precision */ 164 /* default precision */
155 #ifndef MP_PREC 165 #ifndef MP_PREC
156 #ifdef MP_LOW_MEM 166 #ifndef MP_LOW_MEM
157 #define MP_PREC 64 /* default digits of precision */ 167 #define MP_PREC 64 /* default digits of precision */
158 #else 168 #else
159 #define MP_PREC 8 /* default digits of precision */ 169 #define MP_PREC 8 /* default digits of precision */
160 #endif 170 #endif
161 #endif 171 #endif
539 int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c); 549 int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c);
540 int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c); 550 int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
541 int mp_karatsuba_sqr(mp_int *a, mp_int *b); 551 int mp_karatsuba_sqr(mp_int *a, mp_int *b);
542 int mp_toom_sqr(mp_int *a, mp_int *b); 552 int mp_toom_sqr(mp_int *a, mp_int *b);
543 int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c); 553 int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c);
554 int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c);
544 int fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp); 555 int fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
545 int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode); 556 int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode);
546 int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y); 557 int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y);
547 void bn_reverse(unsigned char *s, int len); 558 void bn_reverse(unsigned char *s, int len);
548 559