142
|
1 #include <tommath.h> |
|
2 #ifdef BN_MP_REDUCE_2K_SETUP_C |
2
|
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis |
|
4 * |
|
5 * LibTomMath is a library that provides multiple-precision |
|
6 * integer arithmetic as well as number theoretic functionality. |
|
7 * |
|
8 * The library was designed directly after the MPI library by |
|
9 * Michael Fromberger but has been written from scratch with |
|
10 * additional optimizations in place. |
|
11 * |
|
12 * The library is free for all purposes without any express |
|
13 * guarantee it works. |
|
14 * |
|
15 * Tom St Denis, [email protected], http://math.libtomcrypt.org |
|
16 */ |
|
17 |
|
18 /* determines the setup value */ |
|
19 int |
|
20 mp_reduce_2k_setup(mp_int *a, mp_digit *d) |
|
21 { |
|
22 int res, p; |
|
23 mp_int tmp; |
|
24 |
|
25 if ((res = mp_init(&tmp)) != MP_OKAY) { |
|
26 return res; |
|
27 } |
|
28 |
|
29 p = mp_count_bits(a); |
|
30 if ((res = mp_2expt(&tmp, p)) != MP_OKAY) { |
|
31 mp_clear(&tmp); |
|
32 return res; |
|
33 } |
|
34 |
|
35 if ((res = s_mp_sub(&tmp, a, &tmp)) != MP_OKAY) { |
|
36 mp_clear(&tmp); |
|
37 return res; |
|
38 } |
|
39 |
|
40 *d = tmp.dp[0]; |
|
41 mp_clear(&tmp); |
|
42 return MP_OKAY; |
|
43 } |
142
|
44 #endif |