comparison bn_s_mp_mul_high_digs.c @ 142:d29b64170cf0 libtommath-orig

import of libtommath 0.32
author Matt Johnston <matt@ucc.asn.au>
date Sun, 19 Dec 2004 11:33:56 +0000
parents 86e0b50a9b58
children
comparison
equal deleted inserted replaced
19:e1037a1e12e7 142:d29b64170cf0
1 #include <tommath.h>
2 #ifdef BN_S_MP_MUL_HIGH_DIGS_C
1 /* LibTomMath, multiple-precision integer library -- Tom St Denis 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
2 * 4 *
3 * LibTomMath is a library that provides multiple-precision 5 * LibTomMath is a library that provides multiple-precision
4 * integer arithmetic as well as number theoretic functionality. 6 * integer arithmetic as well as number theoretic functionality.
5 * 7 *
10 * The library is free for all purposes without any express 12 * The library is free for all purposes without any express
11 * guarantee it works. 13 * guarantee it works.
12 * 14 *
13 * Tom St Denis, [email protected], http://math.libtomcrypt.org 15 * Tom St Denis, [email protected], http://math.libtomcrypt.org
14 */ 16 */
15 #include <tommath.h>
16 17
17 /* multiplies |a| * |b| and does not compute the lower digs digits 18 /* multiplies |a| * |b| and does not compute the lower digs digits
18 * [meant to get the higher part of the product] 19 * [meant to get the higher part of the product]
19 */ 20 */
20 int 21 int
25 mp_digit u; 26 mp_digit u;
26 mp_word r; 27 mp_word r;
27 mp_digit tmpx, *tmpt, *tmpy; 28 mp_digit tmpx, *tmpt, *tmpy;
28 29
29 /* can we use the fast multiplier? */ 30 /* can we use the fast multiplier? */
31 #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
30 if (((a->used + b->used + 1) < MP_WARRAY) 32 if (((a->used + b->used + 1) < MP_WARRAY)
31 && MIN (a->used, b->used) < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) { 33 && MIN (a->used, b->used) < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
32 return fast_s_mp_mul_high_digs (a, b, c, digs); 34 return fast_s_mp_mul_high_digs (a, b, c, digs);
33 } 35 }
36 #endif
34 37
35 if ((res = mp_init_size (&t, a->used + b->used + 1)) != MP_OKAY) { 38 if ((res = mp_init_size (&t, a->used + b->used + 1)) != MP_OKAY) {
36 return res; 39 return res;
37 } 40 }
38 t.used = a->used + b->used + 1; 41 t.used = a->used + b->used + 1;
69 mp_clamp (&t); 72 mp_clamp (&t);
70 mp_exch (&t, c); 73 mp_exch (&t, c);
71 mp_clear (&t); 74 mp_clear (&t);
72 return MP_OKAY; 75 return MP_OKAY;
73 } 76 }
77 #endif