Codebase list libcryptx-perl / 9bac49a
libtommath updated to the latest develop branch, commit 0fd5e6c17f Dec 11 14:59:35 2014 +0100 Karel Miko 8 years ago
21 changed file(s) with 728 addition(s) and 386 deletion(s). Raw diff Collapse all Expand all
0 #include <tommath.h>
1 #ifdef BN_MP_EXPORT_C
2 /* LibTomMath, multiple-precision integer library -- Tom St Denis
3 *
4 * LibTomMath is a library that provides multiple-precision
5 * integer arithmetic as well as number theoretic functionality.
6 *
7 * The library was designed directly after the MPI library by
8 * Michael Fromberger but has been written from scratch with
9 * additional optimizations in place.
10 *
11 * The library is free for all purposes without any express
12 * guarantee it works.
13 *
14 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
15 */
16
17 /* based on gmp's mpz_export.
18 * see http://gmplib.org/manual/Integer-Import-and-Export.html
19 */
20 int mp_export(void* rop, size_t* countp, int order, size_t size,
21 int endian, size_t nails, mp_int* op) {
22 int result;
23 size_t odd_nails, nail_bytes, i, j, bits, count;
24 unsigned char odd_nail_mask;
25
26 mp_int t;
27
28 if ((result = mp_init_copy(&t, op)) != MP_OKAY) {
29 return result;
30 }
31
32 if (endian == 0) {
33 union {
34 unsigned int i;
35 char c[4];
36 } lint = {0x01020304};
37
38 endian = (lint.c[0] == 4 ? -1 : 1);
39 }
40
41 odd_nails = (nails % 8);
42 odd_nail_mask = 0xff;
43 for (i = 0; i < odd_nails; ++i) {
44 odd_nail_mask ^= (1 << (7 - i));
45 }
46 nail_bytes = nails / 8;
47
48 bits = mp_count_bits(&t);
49 count = bits / (size * 8 - nails) + (bits % (size * 8 - nails) ? 1 : 0);
50
51 for (i = 0; i < count; ++i) {
52 for (j = 0; j < size; ++j) {
53 unsigned char* byte = (
54 (unsigned char*)rop +
55 (order == -1 ? i : count - 1 - i) * size +
56 (endian == -1 ? j : size - 1 - j)
57 );
58
59 if (j >= (size - nail_bytes)) {
60 *byte = 0;
61 continue;
62 }
63
64 *byte = (unsigned char)(j == size - nail_bytes - 1 ? (t.dp[0] & odd_nail_mask) : t.dp[0] & 0xFF);
65
66 if ((result = mp_div_2d(&t, (j == size - nail_bytes - 1 ? 8 - odd_nails : 8), &t, NULL)) != MP_OKAY) {
67 mp_clear(&t);
68 return result;
69 }
70 }
71 }
72
73 mp_clear(&t);
74
75 if (countp) {
76 *countp = count;
77 }
78
79 return MP_OKAY;
80 }
81
82 #endif
83
84 /* $Source$ */
85 /* $Revision$ */
86 /* $Date$ */
1414 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
1515 */
1616
17 /* calculate c = a**b using a square-multiply algorithm */
17 /* wrapper function for mp_expt_d_ex() */
1818 int mp_expt_d (mp_int * a, mp_digit b, mp_int * c)
1919 {
20 int res;
21 mp_int g;
20 return mp_expt_d_ex(a, b, c, 0);
21 }
2222
23 if ((res = mp_init_copy (&g, a)) != MP_OKAY) {
24 return res;
25 }
26
27 /* set initial result */
28 mp_set (c, 1);
29
30 while (b > 0) {
31 /* if the bit is set multiply */
32 if (b & 1) {
33 if ((res = mp_mul (c, &g, c)) != MP_OKAY) {
34 mp_clear (&g);
35 return res;
36 }
37 }
38
39 /* square */
40 if (b > 1 && (res = mp_sqr (&g, &g)) != MP_OKAY) {
41 mp_clear (&g);
42 return res;
43 }
44
45 /* shift to next bit */
46 b >>= 1;
47 }
48
49 mp_clear (&g);
50 return MP_OKAY;
51 }
5223 #endif
5324
5425 /* $Source$ */
0 #include <tommath.h>
1 #ifdef BN_MP_EXPT_D_EX_C
2 /* LibTomMath, multiple-precision integer library -- Tom St Denis
3 *
4 * LibTomMath is a library that provides multiple-precision
5 * integer arithmetic as well as number theoretic functionality.
6 *
7 * The library was designed directly after the MPI library by
8 * Michael Fromberger but has been written from scratch with
9 * additional optimizations in place.
10 *
11 * The library is free for all purposes without any express
12 * guarantee it works.
13 *
14 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
15 */
16
17 /* calculate c = a**b using a square-multiply algorithm */
18 int mp_expt_d_ex (mp_int * a, mp_digit b, mp_int * c, int fast)
19 {
20 int res;
21 unsigned int x;
22
23 mp_int g;
24
25 if ((res = mp_init_copy (&g, a)) != MP_OKAY) {
26 return res;
27 }
28
29 /* set initial result */
30 mp_set (c, 1);
31
32 if (fast) {
33 while (b > 0) {
34 /* if the bit is set multiply */
35 if (b & 1) {
36 if ((res = mp_mul (c, &g, c)) != MP_OKAY) {
37 mp_clear (&g);
38 return res;
39 }
40 }
41
42 /* square */
43 if (b > 1 && (res = mp_sqr (&g, &g)) != MP_OKAY) {
44 mp_clear (&g);
45 return res;
46 }
47
48 /* shift to next bit */
49 b >>= 1;
50 }
51 }
52 else {
53 for (x = 0; x < DIGIT_BIT; x++) {
54 /* square */
55 if ((res = mp_sqr (c, c)) != MP_OKAY) {
56 mp_clear (&g);
57 return res;
58 }
59
60 /* if the bit is set multiply */
61 if ((b & (mp_digit) (((mp_digit)1) << (DIGIT_BIT - 1))) != 0) {
62 if ((res = mp_mul (c, &g, c)) != MP_OKAY) {
63 mp_clear (&g);
64 return res;
65 }
66 }
67
68 /* shift to next bit */
69 b <<= 1;
70 }
71 } /* if ... else */
72
73 mp_clear (&g);
74 return MP_OKAY;
75 }
76 #endif
77
78 /* $Source$ */
79 /* $Revision$ */
80 /* $Date$ */
1515 */
1616
1717 /* get the lower 32-bits of an mp_int */
18 unsigned long mp_get_int(mp_int * a)
18 unsigned long mp_get_int(mp_int * a)
1919 {
2020 int i;
21 ulong64 res;
21 mp_min_u32 res;
2222
2323 if (a->used == 0) {
2424 return 0;
2929
3030 /* get most significant digit of result */
3131 res = DIGIT(a,i);
32
32
3333 while (--i >= 0) {
3434 res = (res << DIGIT_BIT) | DIGIT(a,i);
3535 }
3636
3737 /* force result to 32-bits always so it is consistent on non 32-bit platforms */
38 return (unsigned long)(res & 0xFFFFFFFFUL);
38 return res & 0xFFFFFFFFUL;
3939 }
4040 #endif
4141
0 #include <tommath.h>
1 #ifdef BN_MP_GET_LONG_C
2 /* LibTomMath, multiple-precision integer library -- Tom St Denis
3 *
4 * LibTomMath is a library that provides multiple-precision
5 * integer arithmetic as well as number theoretic functionality.
6 *
7 * The library was designed directly after the MPI library by
8 * Michael Fromberger but has been written from scratch with
9 * additional optimizations in place.
10 *
11 * The library is free for all purposes without any express
12 * guarantee it works.
13 *
14 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
15 */
16
17 /* get the lower unsigned long of an mp_int, platform dependent */
18 unsigned long mp_get_long(mp_int * a)
19 {
20 int i;
21 unsigned long res;
22
23 if (a->used == 0) {
24 return 0;
25 }
26
27 /* get number of digits of the lsb we have to read */
28 i = MIN(a->used,(int)((sizeof(unsigned long)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1;
29
30 /* get most significant digit of result */
31 res = DIGIT(a,i);
32
33 #if ULONG_MAX != 0xfffffffful || DIGIT_BIT < 32
34 while (--i >= 0) {
35 res = (res << DIGIT_BIT) | DIGIT(a,i);
36 }
37 #endif
38 return res;
39 }
40 #endif
0 #include <tommath.h>
1 #ifdef BN_MP_GET_LONG_LONG_C
2 /* LibTomMath, multiple-precision integer library -- Tom St Denis
3 *
4 * LibTomMath is a library that provides multiple-precision
5 * integer arithmetic as well as number theoretic functionality.
6 *
7 * The library was designed directly after the MPI library by
8 * Michael Fromberger but has been written from scratch with
9 * additional optimizations in place.
10 *
11 * The library is free for all purposes without any express
12 * guarantee it works.
13 *
14 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
15 */
16
17 /* get the lower unsigned long long of an mp_int, platform dependent */
18 unsigned long long mp_get_long_long (mp_int * a)
19 {
20 int i;
21 unsigned long long res;
22
23 if (a->used == 0) {
24 return 0;
25 }
26
27 /* get number of digits of the lsb we have to read */
28 i = MIN(a->used,(int)((sizeof(unsigned long long)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1;
29
30 /* get most significant digit of result */
31 res = DIGIT(a,i);
32
33 #if DIGIT_BIT < 64
34 while (--i >= 0) {
35 res = (res << DIGIT_BIT) | DIGIT(a,i);
36 }
37 #endif
38 return res;
39 }
40 #endif
0 #include <tommath.h>
1 #ifdef BN_MP_IMPORT_C
2 /* LibTomMath, multiple-precision integer library -- Tom St Denis
3 *
4 * LibTomMath is a library that provides multiple-precision
5 * integer arithmetic as well as number theoretic functionality.
6 *
7 * The library was designed directly after the MPI library by
8 * Michael Fromberger but has been written from scratch with
9 * additional optimizations in place.
10 *
11 * The library is free for all purposes without any express
12 * guarantee it works.
13 *
14 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
15 */
16
17 /* based on gmp's mpz_import.
18 * see http://gmplib.org/manual/Integer-Import-and-Export.html
19 */
20 int mp_import(mp_int* rop, size_t count, int order, size_t size,
21 int endian, size_t nails, const void* op) {
22 int result;
23 size_t odd_nails, nail_bytes, i, j;
24 unsigned char odd_nail_mask;
25
26 mp_zero(rop);
27
28 if (endian == 0) {
29 union {
30 unsigned int i;
31 char c[4];
32 } lint = {0x01020304};
33
34 endian = (lint.c[0] == 4 ? -1 : 1);
35 }
36
37 odd_nails = (nails % 8);
38 odd_nail_mask = 0xff;
39 for (i = 0; i < odd_nails; ++i) {
40 odd_nail_mask ^= (1 << (7 - i));
41 }
42 nail_bytes = nails / 8;
43
44 for (i = 0; i < count; ++i) {
45 for (j = 0; j < size - nail_bytes; ++j) {
46 unsigned char byte = *(
47 (unsigned char*)op +
48 (order == 1 ? i : count - 1 - i) * size +
49 (endian == 1 ? j + nail_bytes : size - 1 - j - nail_bytes)
50 );
51
52 if (
53 (result = mp_mul_2d(rop, (j == 0 ? 8 - odd_nails : 8), rop)) != MP_OKAY) {
54 return result;
55 }
56
57 rop->dp[0] |= (j == 0 ? (byte & odd_nail_mask) : byte);
58 rop->used += 1;
59 }
60 }
61
62 mp_clamp(rop);
63
64 return MP_OKAY;
65 }
66
67 #endif
68
69 /* $Source$ */
70 /* $Revision$ */
71 /* $Date$ */
1919 {
2020 int res;
2121
22 if ((res = mp_init (a)) != MP_OKAY) {
22 if ((res = mp_init_size (a, b->used)) != MP_OKAY) {
2323 return res;
2424 }
2525 return mp_copy (b, a);
4747 #endif
4848
4949 /* rho = -1/m mod b */
50 *rho = (unsigned long)(((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK;
50 *rho = (mp_digit)(((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK;
5151
5252 return MP_OKAY;
5353 }
1414 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
1515 */
1616
17 /* find the n'th root of an integer
18 *
19 * Result found such that (c)**b <= a and (c+1)**b > a
20 *
21 * This algorithm uses Newton's approximation
22 * x[i+1] = x[i] - f(x[i])/f'(x[i])
23 * which will find the root in log(N) time where
24 * each step involves a fair bit. This is not meant to
25 * find huge roots [square and cube, etc].
17 /* wrapper function for mp_n_root_ex()
18 * computes c = (a)**(1/b) such that (c)**b <= a and (c+1)**b > a
2619 */
2720 int mp_n_root (mp_int * a, mp_digit b, mp_int * c)
2821 {
29 mp_int t1, t2, t3;
30 int res, neg;
22 return mp_n_root_ex(a, b, c, 0);
23 }
3124
32 /* input must be positive if b is even */
33 if ((b & 1) == 0 && a->sign == MP_NEG) {
34 return MP_VAL;
35 }
36
37 if ((res = mp_init (&t1)) != MP_OKAY) {
38 return res;
39 }
40
41 if ((res = mp_init (&t2)) != MP_OKAY) {
42 goto LBL_T1;
43 }
44
45 if ((res = mp_init (&t3)) != MP_OKAY) {
46 goto LBL_T2;
47 }
48
49 /* if a is negative fudge the sign but keep track */
50 neg = a->sign;
51 a->sign = MP_ZPOS;
52
53 /* t2 = 2 */
54 mp_set (&t2, 2);
55
56 do {
57 /* t1 = t2 */
58 if ((res = mp_copy (&t2, &t1)) != MP_OKAY) {
59 goto LBL_T3;
60 }
61
62 /* t2 = t1 - ((t1**b - a) / (b * t1**(b-1))) */
63
64 /* t3 = t1**(b-1) */
65 if ((res = mp_expt_d (&t1, b - 1, &t3)) != MP_OKAY) {
66 goto LBL_T3;
67 }
68
69 /* numerator */
70 /* t2 = t1**b */
71 if ((res = mp_mul (&t3, &t1, &t2)) != MP_OKAY) {
72 goto LBL_T3;
73 }
74
75 /* t2 = t1**b - a */
76 if ((res = mp_sub (&t2, a, &t2)) != MP_OKAY) {
77 goto LBL_T3;
78 }
79
80 /* denominator */
81 /* t3 = t1**(b-1) * b */
82 if ((res = mp_mul_d (&t3, b, &t3)) != MP_OKAY) {
83 goto LBL_T3;
84 }
85
86 /* t3 = (t1**b - a)/(b * t1**(b-1)) */
87 if ((res = mp_div (&t2, &t3, &t3, NULL)) != MP_OKAY) {
88 goto LBL_T3;
89 }
90
91 if ((res = mp_sub (&t1, &t3, &t2)) != MP_OKAY) {
92 goto LBL_T3;
93 }
94 } while (mp_cmp (&t1, &t2) != MP_EQ);
95
96 /* result can be off by a few so check */
97 for (;;) {
98 if ((res = mp_expt_d (&t1, b, &t2)) != MP_OKAY) {
99 goto LBL_T3;
100 }
101
102 if (mp_cmp (&t2, a) == MP_GT) {
103 if ((res = mp_sub_d (&t1, 1, &t1)) != MP_OKAY) {
104 goto LBL_T3;
105 }
106 } else {
107 break;
108 }
109 }
110
111 /* reset the sign of a first */
112 a->sign = neg;
113
114 /* set the result */
115 mp_exch (&t1, c);
116
117 /* set the sign of the result */
118 c->sign = neg;
119
120 res = MP_OKAY;
121
122 LBL_T3:mp_clear (&t3);
123 LBL_T2:mp_clear (&t2);
124 LBL_T1:mp_clear (&t1);
125 return res;
126 }
12725 #endif
12826
12927 /* $Source$ */
0 #include <tommath.h>
1 #ifdef BN_MP_N_ROOT_EX_C
2 /* LibTomMath, multiple-precision integer library -- Tom St Denis
3 *
4 * LibTomMath is a library that provides multiple-precision
5 * integer arithmetic as well as number theoretic functionality.
6 *
7 * The library was designed directly after the MPI library by
8 * Michael Fromberger but has been written from scratch with
9 * additional optimizations in place.
10 *
11 * The library is free for all purposes without any express
12 * guarantee it works.
13 *
14 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
15 */
16
17 /* find the n'th root of an integer
18 *
19 * Result found such that (c)**b <= a and (c+1)**b > a
20 *
21 * This algorithm uses Newton's approximation
22 * x[i+1] = x[i] - f(x[i])/f'(x[i])
23 * which will find the root in log(N) time where
24 * each step involves a fair bit. This is not meant to
25 * find huge roots [square and cube, etc].
26 */
27 int mp_n_root_ex (mp_int * a, mp_digit b, mp_int * c, int fast)
28 {
29 mp_int t1, t2, t3;
30 int res, neg;
31
32 /* input must be positive if b is even */
33 if ((b & 1) == 0 && a->sign == MP_NEG) {
34 return MP_VAL;
35 }
36
37 if ((res = mp_init (&t1)) != MP_OKAY) {
38 return res;
39 }
40
41 if ((res = mp_init (&t2)) != MP_OKAY) {
42 goto LBL_T1;
43 }
44
45 if ((res = mp_init (&t3)) != MP_OKAY) {
46 goto LBL_T2;
47 }
48
49 /* if a is negative fudge the sign but keep track */
50 neg = a->sign;
51 a->sign = MP_ZPOS;
52
53 /* t2 = 2 */
54 mp_set (&t2, 2);
55
56 do {
57 /* t1 = t2 */
58 if ((res = mp_copy (&t2, &t1)) != MP_OKAY) {
59 goto LBL_T3;
60 }
61
62 /* t2 = t1 - ((t1**b - a) / (b * t1**(b-1))) */
63
64 /* t3 = t1**(b-1) */
65 if ((res = mp_expt_d_ex (&t1, b - 1, &t3, fast)) != MP_OKAY) {
66 goto LBL_T3;
67 }
68
69 /* numerator */
70 /* t2 = t1**b */
71 if ((res = mp_mul (&t3, &t1, &t2)) != MP_OKAY) {
72 goto LBL_T3;
73 }
74
75 /* t2 = t1**b - a */
76 if ((res = mp_sub (&t2, a, &t2)) != MP_OKAY) {
77 goto LBL_T3;
78 }
79
80 /* denominator */
81 /* t3 = t1**(b-1) * b */
82 if ((res = mp_mul_d (&t3, b, &t3)) != MP_OKAY) {
83 goto LBL_T3;
84 }
85
86 /* t3 = (t1**b - a)/(b * t1**(b-1)) */
87 if ((res = mp_div (&t2, &t3, &t3, NULL)) != MP_OKAY) {
88 goto LBL_T3;
89 }
90
91 if ((res = mp_sub (&t1, &t3, &t2)) != MP_OKAY) {
92 goto LBL_T3;
93 }
94 } while (mp_cmp (&t1, &t2) != MP_EQ);
95
96 /* result can be off by a few so check */
97 for (;;) {
98 if ((res = mp_expt_d_ex (&t1, b, &t2, fast)) != MP_OKAY) {
99 goto LBL_T3;
100 }
101
102 if (mp_cmp (&t2, a) == MP_GT) {
103 if ((res = mp_sub_d (&t1, 1, &t1)) != MP_OKAY) {
104 goto LBL_T3;
105 }
106 } else {
107 break;
108 }
109 }
110
111 /* reset the sign of a first */
112 a->sign = neg;
113
114 /* set the result */
115 mp_exch (&t1, c);
116
117 /* set the sign of the result */
118 c->sign = neg;
119
120 res = MP_OKAY;
121
122 LBL_T3:mp_clear (&t3);
123 LBL_T2:mp_clear (&t2);
124 LBL_T1:mp_clear (&t1);
125 return res;
126 }
127 #endif
128
129 /* $Source$ */
130 /* $Revision$ */
131 /* $Date$ */
44 * LibTomMath is a library that provides multiple-precision
55 * integer arithmetic as well as number theoretic functionality.
66 *
7 * The library was designed directly after the MPI library by
8 * Michael Fromberger but has been written from scratch with
9 * additional optimizations in place.
10 *
711 * The library is free for all purposes without any express
812 * guarantee it works.
13 *
14 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
915 */
1016
11 /* ideas from Dana Jacobsen's
12 * https://github.com/danaj/Math-Prime-Util-GMP
13 */
17 /* performs a variable number of rounds of Miller-Rabin
18 *
19 * Probability of error after t rounds is no more than
1420
15 int mp_prime_is_prime_ex(mp_int * a, int t, int *result, ltm_prime_callback cb, void *dat)
21 *
22 * Sets result to 1 if probably prime, 0 otherwise
23 */
24 int mp_prime_is_prime (mp_int * a, int t, int *result)
1625 {
17 mp_int b;
18 int ix, err, res, abits, atests;
19 mp_digit maxp, r;
26 mp_int b;
27 int ix, err, res;
2028
21 maxp = ltm_prime_tab[PRIME_SIZE-1]; /* max. predefined prime number */
22 *result = MP_NO; /* default */
29 /* default to no */
30 *result = MP_NO;
2331
24 /* special case: a <= max_predef_prime */
25 if (mp_cmp_d(a, maxp+1) == MP_LT) {
26 /* test if a is equal to any of the first N primes */
27 for (ix = 0; ix < PRIME_SIZE; ix++) {
28 if (mp_cmp_d(a, ltm_prime_tab[ix]) == MP_EQ) { *result = MP_YES; return MP_OKAY; }
29 }
30 /* here it must be composite */
32 /* valid value of t? */
33 if (t <= 0 || t > PRIME_SIZE) {
34 return MP_VAL;
35 }
36
37 /* is the input equal to one of the primes in the table? */
38 for (ix = 0; ix < PRIME_SIZE; ix++) {
39 if (mp_cmp_d(a, ltm_prime_tab[ix]) == MP_EQ) {
40 *result = 1;
41 return MP_OKAY;
42 }
43 }
44
45 /* first perform trial division */
46 if ((err = mp_prime_is_divisible (a, &res)) != MP_OKAY) {
47 return err;
48 }
49
50 /* return if it was trivially divisible */
51 if (res == MP_YES) {
3152 return MP_OKAY;
3253 }
3354
34 /* go through all known predefined primes - BEWARE: max_predef_prime should never go over 65536 */
35 for (ix = 0; ix < PRIME_SIZE; ix++) {
36 /* return YES if A < p[ix]*p[ix] */
37 if (mp_cmp_d(a, ltm_prime_tab[ix]*ltm_prime_tab[ix]) == MP_LT) { *result = MP_YES; return MP_OKAY; }
38 /* return NO if A % p[ix] == 0 */
39 if ((err = mp_mod_d(a, ltm_prime_tab[ix], &r)) != MP_OKAY) { return err; }
40 if (r == 0) { return MP_OKAY; }
55 /* now perform the miller-rabin rounds */
56 if ((err = mp_init (&b)) != MP_OKAY) {
57 return err;
4158 }
4259
43 /* init b */
44 if ((err = mp_init(&b)) != MP_OKAY) { return err; }
60 for (ix = 0; ix < t; ix++) {
61 /* set the prime */
62 mp_set (&b, ltm_prime_tab[ix]);
4563
46 /* Miller Rabin with base 2 */
47 mp_set(&b, 2);
48 err = mp_prime_miller_rabin(a, &b, &res);
49 if (err != MP_OKAY) { goto LBL_B; }
50 if (res != MP_YES) { goto LBL_B; }
64 if ((err = mp_prime_miller_rabin (a, &b, &res)) != MP_OKAY) {
65 goto LBL_B;
66 }
5167
52 /* Extra-Strong Lucas test */
53 err = mp_prime_lucas(a, 2, &res);
54 if (err != MP_OKAY) { goto LBL_B; }
55 if (res != MP_YES) { goto LBL_B; }
56
57 /* BPSW is deterministic below 2^64 */
58 if (mp_count_bits(a) <= 64) { *result = MP_YES; return MP_OKAY; }
59
60 if (cb && dat) {
61 /* Miller Rabin with N random bases */
62 if (t > 0) {
63 atests = t;
64 }
65 else {
66 abits = mp_count_bits(a);
67 if (abits < 80) atests = 5;
68 else if (abits < 105) atests = 4;
69 else if (abits < 160) atests = 3;
70 else if (abits < 413) atests = 2;
71 else atests = 1;
72 }
73 err = mp_prime_miller_rabin_random(a, atests, &res, cb, dat);
74 if (err != MP_OKAY) { goto LBL_B; }
75 if (res != MP_YES) { goto LBL_B; }
76 }
77 else {
78 /* Miller Rabin with first N primes */
79 if (t > 0) {
80 atests = t;
81 }
82 else {
83 abits = mp_count_bits(a);
84 atests = mp_prime_rabin_miller_trials(abits);
85 }
86 for (ix = 1; ix < atests; ix++) { /* skip ltm_prime_tab[0] (==2) as it was already tested) */
87 mp_set(&b, ltm_prime_tab[ix]);
88 if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) { goto LBL_B; }
89 if (res == MP_NO) { goto LBL_B; }
68 if (res == MP_NO) {
69 goto LBL_B;
9070 }
9171 }
9272
93 /* passed all tests */
73 /* passed the test */
9474 *result = MP_YES;
95 err = MP_OKAY;
96
97 LBL_B:
98 mp_clear(&b);
75 LBL_B:mp_clear (&b);
9976 return err;
100 }
101
102 int mp_prime_is_prime(mp_int * a, int t, int *result)
103 {
104 return mp_prime_is_prime_ex(a, t, result, NULL, NULL);
10577 }
10678 #endif
10779
+0
-24
src/ltm/bn_mp_prime_lucas.c less more
0 #include <tommath.h>
1 #ifdef BN_MP_PRIME_LUCAS_C
2 /* LibTomMath, multiple-precision integer library -- Tom St Denis
3 *
4 * LibTomMath is a library that provides multiple-precision
5 * integer arithmetic as well as number theoretic functionality.
6 *
7 * The library is free for all purposes without any express
8 * guarantee it works.
9 */
10
11 int mp_prime_lucas (mp_int * a, int level, int *result)
12 {
13 /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
14 /* fprintf(stderr, "XXX-DEBUG: mp_prime_lucas begin bits=%d, level=%d\n", mp_count_bits(a), level); */
15
16 *result = MP_YES; /* XXX let's always pass */
17 return MP_OKAY;
18 }
19 #endif
20
21 /* $Source$ */
22 /* $Revision$ */
23 /* $Date$ */
+0
-66
src/ltm/bn_mp_prime_miller_rabin_random.c less more
0 #include <tommath.h>
1 #ifdef BN_MP_PRIME_MILLER_RABIN_RANDOM_C
2 /* LibTomMath, multiple-precision integer library -- Tom St Denis
3 *
4 * LibTomMath is a library that provides multiple-precision
5 * integer arithmetic as well as number theoretic functionality.
6 *
7 * The library is free for all purposes without any express
8 * guarantee it works.
9 */
10
11 int mp_prime_miller_rabin_random(mp_int *a, int t, int *result, ltm_prime_callback cb, void *dat)
12 {
13 mp_int b, c;
14 int res, err, bsize, trials;
15 unsigned char *tmp;
16
17 fprintf(stderr, "XXX-DEBUG: mp_prime_miller_rabin_random begin bits=%d, t=%d\n", mp_count_bits(a), t); /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
18
19 /* default */
20 *result = MP_NO;
21
22 /* tests should be >0 */
23 if (t <= 0) { return MP_VAL; }
24
25 /* calculate the byte size */
26 bsize = mp_unsigned_bin_size(a);
27
28 /* we need a buffer of bsize bytes */
29 tmp = OPT_CAST(unsigned char) XMALLOC(bsize);
30 if (tmp == NULL) { return MP_MEM; }
31
32 /* initialize b */
33 if ((err = mp_init_multi(&b, &c, NULL)) != MP_OKAY) { return err; }
34
35 trials = 0;
36 do {
37 /* read the bytes */
38 if (cb(tmp, bsize, dat) != bsize) { err = MP_VAL; goto LBL_BC; }
39
40 /* read it in */
41 if ((err = mp_read_unsigned_bin(&b, tmp, bsize)) != MP_OKAY) { goto LBL_BC; }
42
43 /* test if b is in [2, a-2] */
44 mp_add_d(&b, 1, &c); /* c = b + 1 */
45 if (mp_cmp_d(&c, 2) != MP_GT && mp_cmp(&c, a) != MP_LT) continue;
46
47 /* do Miller Rabin */
48 if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) { goto LBL_BC; }
49 if (res == MP_NO) { err = MP_OKAY; goto LBL_BC; }
50 trials++;
51 } while (++trials < t);
52
53 /* passed the test */
54 *result = MP_YES;
55 err = MP_OKAY;
56
57 LBL_BC:
58 mp_clear_multi(&b, &c, NULL);
59 return err;
60 }
61 #endif
62
63 /* $Source$ */
64 /* $Revision$ */
65 /* $Date$ */
2121 */
2222 int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
2323 {
24 int err, res, x, y;
24 int err, res = MP_NO, x, y;
2525 mp_digit res_tab[PRIME_SIZE], step, kstep;
2626 mp_int b;
2727
2828
2929 /* first place a random non-zero digit */
3030 do {
31 d = ((mp_digit) abs (rand ())) & MP_MASK;
31 d = ((mp_digit) abs (MP_GEN_RANDOM())) & MP_MASK;
3232 } while (d == 0);
3333
3434 if ((res = mp_add_d (a, d, a)) != MP_OKAY) {
4040 return res;
4141 }
4242
43 if ((res = mp_add_d (a, ((mp_digit) abs (rand ())), a)) != MP_OKAY) {
43 if ((res = mp_add_d (a, ((mp_digit) abs (MP_GEN_RANDOM())), a)) != MP_OKAY) {
4444 return res;
4545 }
4646 }
1414 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
1515 */
1616
17 /* reduces x mod m, assumes 0 < x < m**2, mu is
17 /* reduces x mod m, assumes 0 < x < m**2, mu is
1818 * precomputed via mp_reduce_setup.
1919 * From HAC pp.604 Algorithm 14.42
2020 */
2929 }
3030
3131 /* q1 = x / b**(k-1) */
32 mp_rshd (&q, um - 1);
32 mp_rshd (&q, um - 1);
3333
3434 /* according to HAC this optimization is ok */
35 if (((unsigned long) um) > (((mp_digit)1) << (DIGIT_BIT - 1))) {
35 if (((mp_digit) um) > (((mp_digit)1) << (DIGIT_BIT - 1))) {
3636 if ((res = mp_mul (&q, mu, &q)) != MP_OKAY) {
3737 goto CLEANUP;
3838 }
4545 if ((res = fast_s_mp_mul_high_digs (&q, mu, &q, um)) != MP_OKAY) {
4646 goto CLEANUP;
4747 }
48 #else
49 {
48 #else
49 {
5050 res = MP_VAL;
5151 goto CLEANUP;
5252 }
5454 }
5555
5656 /* q3 = q2 / b**(k+1) */
57 mp_rshd (&q, um + 1);
57 mp_rshd (&q, um + 1);
5858
5959 /* x = x mod b**(k+1), quick (no division) */
6060 if ((res = mp_mod_2d (x, DIGIT_BIT * (um + 1), x)) != MP_OKAY) {
8686 goto CLEANUP;
8787 }
8888 }
89
89
9090 CLEANUP:
9191 mp_clear (&q);
9292
0 #include <tommath.h>
1 #ifdef BN_MP_SET_LONG_C
2 /* LibTomMath, multiple-precision integer library -- Tom St Denis
3 *
4 * LibTomMath is a library that provides multiple-precision
5 * integer arithmetic as well as number theoretic functionality.
6 *
7 * The library was designed directly after the MPI library by
8 * Michael Fromberger but has been written from scratch with
9 * additional optimizations in place.
10 *
11 * The library is free for all purposes without any express
12 * guarantee it works.
13 *
14 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
15 */
16
17 /* set a platform dependent unsigned long int */
18 MP_SET_XLONG(mp_set_long, unsigned long)
19 #endif
20
21 /* $Source$ */
22 /* $Revision$ */
23 /* $Date$ */
0 #include <tommath.h>
1 #ifdef BN_MP_SET_LONG_LONG_C
2 /* LibTomMath, multiple-precision integer library -- Tom St Denis
3 *
4 * LibTomMath is a library that provides multiple-precision
5 * integer arithmetic as well as number theoretic functionality.
6 *
7 * The library was designed directly after the MPI library by
8 * Michael Fromberger but has been written from scratch with
9 * additional optimizations in place.
10 *
11 * The library is free for all purposes without any express
12 * guarantee it works.
13 *
14 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
15 */
16
17 /* set a platform dependent unsigned long long int */
18 MP_SET_XLONG(mp_set_long_long, unsigned long long)
19 #endif
20
21 /* $Source$ */
22 /* $Revision$ */
23 /* $Date$ */
4545
4646
4747 /* detect 64-bit mode if possible */
48 #if defined(__x86_64__)
49 #if !(defined(MP_64BIT) && defined(MP_16BIT) && defined(MP_8BIT))
48 #if defined(__x86_64__)
49 #if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
5050 #define MP_64BIT
5151 #endif
5252 #endif
6262 #ifdef MP_8BIT
6363 typedef unsigned char mp_digit;
6464 typedef unsigned short mp_word;
65 #define MP_SIZEOF_MP_DIGIT 1
66 #ifdef DIGIT_BIT
67 #error You must not define DIGIT_BIT when using MP_8BIT
68 #endif
6569 #elif defined(MP_16BIT)
6670 typedef unsigned short mp_digit;
67 typedef unsigned long mp_word;
71 typedef unsigned int mp_word;
72 #define MP_SIZEOF_MP_DIGIT 2
73 #ifdef DIGIT_BIT
74 #error You must not define DIGIT_BIT when using MP_16BIT
75 #endif
6876 #elif defined(MP_64BIT)
6977 /* for GCC only on supported platforms */
7078 #ifndef CRYPT
7280 typedef signed long long long64;
7381 #endif
7482
75 #ifdef __WIN64
76 typedef unsigned long mp_digit;
77 typedef unsigned long long mp_word;
78 #define DIGIT_BIT 28
79 #define MP_28BIT
80 #else
81 typedef unsigned long mp_digit;
83 typedef unsigned long long mp_digit;
8284 typedef unsigned long mp_word __attribute__ ((mode(TI)));
85
8386 #define DIGIT_BIT 60
84 #endif
85
86
8787 #else
8888 /* this is the default case, 28-bit digits */
89
89
9090 /* this is to make porting into LibTomCrypt easier :-) */
9191 #ifndef CRYPT
92 #if defined(_MSC_VER) || defined(__BORLANDC__)
92 #if defined(_MSC_VER) || defined(__BORLANDC__)
9393 typedef unsigned __int64 ulong64;
9494 typedef signed __int64 long64;
9595 #else
101101 typedef unsigned long mp_digit;
102102 typedef ulong64 mp_word;
103103
104 #ifdef MP_31BIT
104 #ifdef MP_31BIT
105105 /* this is an extension that uses 31-bit digits */
106106 #define DIGIT_BIT 31
107107 #else
108108 /* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */
109109 #define DIGIT_BIT 28
110110 #define MP_28BIT
111 #endif
111 #endif
112112 #endif
113113
114114 /* define heap macros */
115115 #ifndef CRYPT
116116 /* default to libc stuff */
117 #ifndef XMALLOC
117 #ifndef XMALLOC
118118 #define XMALLOC malloc
119119 #define XFREE free
120120 #define XREALLOC realloc
131131
132132 /* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
133133 #ifndef DIGIT_BIT
134 #define DIGIT_BIT ((int)((CHAR_BIT * sizeof(mp_digit) - 1))) /* bits per digit */
134 #define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */
135 typedef unsigned long mp_min_u32;
136 #else
137 typedef mp_digit mp_min_u32;
138 #endif
139
140 /* platforms that can use a better rand function */
141 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
142 #define MP_USE_ALT_RAND 1
143 #endif
144
145 /* use arc4random on platforms that support it */
146 #ifdef MP_USE_ALT_RAND
147 #define MP_GEN_RANDOM() arc4random()
148 #else
149 #define MP_GEN_RANDOM() rand()
135150 #endif
136151
137152 #define MP_DIGIT_BIT DIGIT_BIT
176191 #define MP_PREC 32 /* default digits of precision */
177192 #else
178193 #define MP_PREC 8 /* default digits of precision */
179 #endif
194 #endif
180195 #endif
181196
182197 /* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
228243 #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
229244 #define mp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
230245 #define mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
246 #define mp_isneg(a) (((a)->sign) ? MP_YES : MP_NO)
231247
232248 /* set to zero */
233249 void mp_zero(mp_int *a);
238254 /* set a 32-bit const */
239255 int mp_set_int(mp_int *a, unsigned long b);
240256
257 /* set a platform dependent unsigned long value */
258 int mp_set_long(mp_int *a, unsigned long b);
259
260 /* set a platform dependent unsigned long long value */
261 int mp_set_long_long(mp_int *a, unsigned long long b);
262
241263 /* get a 32-bit value */
242264 unsigned long mp_get_int(mp_int * a);
243265
266 /* get a platform dependent unsigned long value */
267 unsigned long mp_get_long(mp_int * a);
268
269 /* get a platform dependent unsigned long long value */
270 unsigned long long mp_get_long_long(mp_int * a);
271
244272 /* initialize and set a digit */
245273 int mp_init_set (mp_int * a, mp_digit b);
246274
256284 /* trim unused digits */
257285 void mp_clamp(mp_int *a);
258286
287 /* import binary data */
288 int mp_import(mp_int* rop, size_t count, int order, size_t size, int endian, size_t nails, const void* op);
289
290 /* export binary data */
291 int mp_export(void* rop, size_t* countp, int order, size_t size, int endian, size_t nails, mp_int* op);
292
259293 /* ---> digit manipulation <--- */
260294
261295 /* right shift by "b" digits */
276310 /* b = a*2 */
277311 int mp_mul_2(mp_int *a, mp_int *b);
278312
279 /* c = a mod 2**d */
313 /* c = a mod 2**b */
280314 int mp_mod_2d(mp_int *a, int b, mp_int *c);
281315
282316 /* computes a = 2**b */
354388
355389 /* c = a**b */
356390 int mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
391 int mp_expt_d_ex (mp_int * a, mp_digit b, mp_int * c, int fast);
357392
358393 /* c = a mod b, 0 <= c < b */
359394 int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c);
389424 * returns error if a < 0 and b is even
390425 */
391426 int mp_n_root(mp_int *a, mp_digit b, mp_int *c);
427 int mp_n_root_ex (mp_int * a, mp_digit b, mp_int * c, int fast);
392428
393429 /* special sqrt algo */
394430 int mp_sqrt(mp_int *arg, mp_int *ret);
473509 */
474510 int mp_prime_fermat(mp_int *a, mp_int *b, int *result);
475511
476 /* performs Lucas test of "a".
477 * Sets result to 0 if composite or 1 if probable prime
478 */
479 int mp_prime_lucas (mp_int * a, int level, int *result);
480
481512 /* performs one Miller-Rabin test of "a" using base "b".
482513 * Sets result to 0 if composite or 1 if probable prime
483514 */
484515 int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result);
485516
486 /* performs one Miller-Rabin test of "a" using base "t"
487 * random bases chosen from [2, a-2].
488 * Sets result to 0 if composite or 1 if probable prime
489 */
490 int mp_prime_miller_rabin_random(mp_int *a, int t, int *result, ltm_prime_callback cb, void *dat);
491
492517 /* This gives [for a given bit size] the number of trials required
493 * such that Miller-Rabin gives a prob of failure lower than 2^-96
518 * such that Miller-Rabin gives a prob of failure lower than 2^-96
494519 */
495520 int mp_prime_rabin_miller_trials(int size);
496521
503528 */
504529 int mp_prime_is_prime(mp_int *a, int t, int *result);
505530
506 /* performs extended primality tests
507 * Miller-Rabin (t random or fixed bases) + Lucas
508 *
509 * Sets result to 1 if probably prime, 0 otherwise
510 */
511 int mp_prime_is_prime_ex(mp_int *a, int t, int *result, ltm_prime_callback cb, void *dat);
512
513531 /* finds the next prime after the number "a" using "t" trials
514532 * of Miller-Rabin.
515533 *
518536 int mp_prime_next_prime(mp_int *a, int t, int bbs_style);
519537
520538 /* makes a truly random prime of a given size (bytes),
521 * call with bbs = 1 if you want it to be congruent to 3 mod 4
539 * call with bbs = 1 if you want it to be congruent to 3 mod 4
522540 *
523541 * You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can
524542 * have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself
531549 /* makes a truly random prime of a given size (bits),
532550 *
533551 * Flags are as follows:
534 *
552 *
535553 * LTM_PRIME_BBS - make prime congruent to 3 mod 4
536554 * LTM_PRIME_SAFE - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
537555 * LTM_PRIME_2MSB_ON - make the 2nd highest bit one
599617
600618 extern const char *mp_s_rmap;
601619
620 /* Fancy macro to set an MPI from another type.
621 * There are several things assumed:
622 * x is the counter and unsigned
623 * a is the pointer to the MPI
624 * b is the original value that should be set in the MPI.
625 */
626 #define MP_SET_XLONG(func_name, type) \
627 int func_name (mp_int * a, type b) \
628 { \
629 unsigned int x; \
630 int res; \
631 \
632 mp_zero (a); \
633 \
634 /* set four bits at a time */ \
635 for (x = 0; x < sizeof(type) * 2; x++) { \
636 /* shift the number up four bits */ \
637 if ((res = mp_mul_2d (a, 4, a)) != MP_OKAY) { \
638 return res; \
639 } \
640 \
641 /* OR in the top four bits of the source */ \
642 a->dp[0] |= (b >> ((sizeof(type)) * 8 - 4)) & 15; \
643 \
644 /* shift the source up to the next four bits */ \
645 b <<= 4; \
646 \
647 /* ensure that digits are not clamped off */ \
648 a->used += 1; \
649 } \
650 mp_clamp (a); \
651 return MP_OKAY; \
652 }
653
602654 #ifdef __cplusplus
603655 }
604656 #endif
3737 #define BN_MP_DR_REDUCE_C
3838 #define BN_MP_DR_SETUP_C
3939 #define BN_MP_EXCH_C
40 #define BN_MP_EXPORT_C
4041 #define BN_MP_EXPT_D_C
42 #define BN_MP_EXPT_D_EX_C
4143 #define BN_MP_EXPTMOD_C
4244 #define BN_MP_EXPTMOD_FAST_C
4345 #define BN_MP_EXTEUCLID_C
4547 #define BN_MP_FWRITE_C
4648 #define BN_MP_GCD_C
4749 #define BN_MP_GET_INT_C
50 #define BN_MP_GET_LONG_C
51 #define BN_MP_GET_LONG_LONG_C
4852 #define BN_MP_GROW_C
53 #define BN_MP_IMPORT_C
4954 #define BN_MP_INIT_C
5055 #define BN_MP_INIT_COPY_C
5156 #define BN_MP_INIT_MULTI_C
7277 #define BN_MP_MUL_D_C
7378 #define BN_MP_MULMOD_C
7479 #define BN_MP_N_ROOT_C
80 #define BN_MP_N_ROOT_EX_C
7581 #define BN_MP_NEG_C
7682 #define BN_MP_OR_C
7783 #define BN_MP_PRIME_FERMAT_C
7884 #define BN_MP_PRIME_IS_DIVISIBLE_C
7985 #define BN_MP_PRIME_IS_PRIME_C
8086 #define BN_MP_PRIME_MILLER_RABIN_C
81 #define BN_MP_PRIME_MILLER_RABIN_RANDOM_C
82 #define BN_MP_PRIME_LUCAS_C
8387 #define BN_MP_PRIME_NEXT_PRIME_C
8488 #define BN_MP_PRIME_RABIN_MILLER_TRIALS_C
8589 #define BN_MP_PRIME_RANDOM_EX_C
100104 #define BN_MP_RSHD_C
101105 #define BN_MP_SET_C
102106 #define BN_MP_SET_INT_C
107 #define BN_MP_SET_LONG_C
108 #define BN_MP_SET_LONG_LONG_C
103109 #define BN_MP_SHRINK_C
104110 #define BN_MP_SIGNED_BIN_SIZE_C
105111 #define BN_MP_SQR_C
317323 #if defined(BN_MP_EXCH_C)
318324 #endif
319325
326 #if defined(BN_MP_EXPORT_C)
327 #define BN_MP_INIT_COPY_C
328 #define BN_MP_COUNT_BITS_C
329 #define BN_MP_DIV_2D_C
330 #define BN_MP_CLEAR_C
331 #endif
332
320333 #if defined(BN_MP_EXPT_D_C)
321 #define BN_MP_INIT_COPY_C
322 #define BN_MP_SET_C
334 #define BN_MP_EXPT_D_EX_C
335 #endif
336
337 #if defined(BN_MP_EXPT_D_EX_C)
338 #define BN_MP_INIT_COPY_C
339 #define BN_MP_SET_C
340 #define BN_MP_MUL_C
341 #define BN_MP_CLEAR_C
323342 #define BN_MP_SQR_C
324 #define BN_MP_CLEAR_C
325 #define BN_MP_MUL_C
326343 #endif
327344
328345 #if defined(BN_MP_EXPTMOD_C)
389406 #if defined(BN_MP_GCD_C)
390407 #define BN_MP_ISZERO_C
391408 #define BN_MP_ABS_C
392 #define BN_MP_ZERO_C
393409 #define BN_MP_INIT_COPY_C
394410 #define BN_MP_CNT_LSB_C
395411 #define BN_MP_DIV_2D_C
403419 #if defined(BN_MP_GET_INT_C)
404420 #endif
405421
422 #if defined(BN_MP_GET_LONG_C)
423 #endif
424
425 #if defined(BN_MP_GET_LONG_LONG_C)
426 #define BN_MP_GET_LONG_C
427 #endif
428
406429 #if defined(BN_MP_GROW_C)
407430 #endif
408431
432 #if defined(BN_MP_IMPORT_C)
433 #define BN_MP_ZERO_C
434 #define BN_MP_MUL_2D_C
435 #define BN_MP_CLAMP_C
436 #endif
437
409438 #if defined(BN_MP_INIT_C)
410439 #endif
411440
412441 #if defined(BN_MP_INIT_COPY_C)
442 #define BN_MP_INIT_SIZE_C
413443 #define BN_MP_COPY_C
414444 #endif
415445
483513 #define BN_MP_MUL_C
484514 #define BN_MP_INIT_SIZE_C
485515 #define BN_MP_CLAMP_C
486 #define BN_MP_SUB_C
516 #define BN_S_MP_ADD_C
487517 #define BN_MP_ADD_C
518 #define BN_S_MP_SUB_C
488519 #define BN_MP_LSHD_C
489520 #define BN_MP_CLEAR_C
490521 #endif
493524 #define BN_MP_INIT_SIZE_C
494525 #define BN_MP_CLAMP_C
495526 #define BN_MP_SQR_C
496 #define BN_MP_SUB_C
497527 #define BN_S_MP_ADD_C
528 #define BN_S_MP_SUB_C
498529 #define BN_MP_LSHD_C
499530 #define BN_MP_ADD_C
500531 #define BN_MP_CLEAR_C
518549 #define BN_MP_INIT_C
519550 #define BN_MP_DIV_C
520551 #define BN_MP_CLEAR_C
552 #define BN_MP_ISZERO_C
553 #define BN_MP_EXCH_C
521554 #define BN_MP_ADD_C
522 #define BN_MP_EXCH_C
523555 #endif
524556
525557 #if defined(BN_MP_MOD_2D_C)
585617 #endif
586618
587619 #if defined(BN_MP_N_ROOT_C)
588 #define BN_MP_INIT_C
589 #define BN_MP_SET_C
590 #define BN_MP_COPY_C
591 #define BN_MP_EXPT_D_C
620 #define BN_MP_N_ROOT_EX_C
621 #endif
622
623 #if defined(BN_MP_N_ROOT_EX_C)
624 #define BN_MP_INIT_C
625 #define BN_MP_SET_C
626 #define BN_MP_COPY_C
627 #define BN_MP_EXPT_D_EX_C
592628 #define BN_MP_MUL_C
593629 #define BN_MP_SUB_C
594630 #define BN_MP_MUL_D_C
669705 #endif
670706
671707 #if defined(BN_MP_RADIX_SIZE_C)
672 #define BN_MP_COUNT_BITS_C
673 #define BN_MP_INIT_COPY_C
674 #define BN_MP_ISZERO_C
708 #define BN_MP_ISZERO_C
709 #define BN_MP_COUNT_BITS_C
710 #define BN_MP_INIT_COPY_C
675711 #define BN_MP_DIV_D_C
676712 #define BN_MP_CLEAR_C
677713 #endif
689725 #if defined(BN_MP_READ_RADIX_C)
690726 #define BN_MP_ZERO_C
691727 #define BN_MP_S_RMAP_C
692 #define BN_MP_RADIX_SMAP_C
693728 #define BN_MP_MUL_D_C
694729 #define BN_MP_ADD_D_C
695730 #define BN_MP_ISZERO_C
788823 #define BN_MP_ZERO_C
789824 #define BN_MP_MUL_2D_C
790825 #define BN_MP_CLAMP_C
826 #endif
827
828 #if defined(BN_MP_SET_LONG_C)
829 #endif
830
831 #if defined(BN_MP_SET_LONG_LONG_C)
791832 #endif
792833
793834 #if defined(BN_MP_SHRINK_C)
10071048 #else
10081049 #define LTM_LAST
10091050 #endif
1010
1011 /* $Source$ */
1012 /* $Revision$ */
1013 /* $Date$ */