comparison libtommath/bn_s_mp_mul_digs.c @ 1436:60fc6476e044

Update to libtommath v1.0
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jun 2017 22:37:14 +0800
parents 5ff8218bcee9
children 8bba51a55704
comparison
equal deleted inserted replaced
1435:f849a5ca2efc 1436:60fc6476e044
1 #include <tommath.h> 1 #include <tommath_private.h>
2 #ifdef BN_S_MP_MUL_DIGS_C 2 #ifdef BN_S_MP_MUL_DIGS_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
4 * 4 *
5 * LibTomMath is a library that provides multiple-precision 5 * LibTomMath is a library that provides multiple-precision
6 * integer arithmetic as well as number theoretic functionality. 6 * integer arithmetic as well as number theoretic functionality.
10 * additional optimizations in place. 10 * additional optimizations in place.
11 * 11 *
12 * The library is free for all purposes without any express 12 * The library is free for all purposes without any express
13 * guarantee it works. 13 * guarantee it works.
14 * 14 *
15 * Tom St Denis, [email protected], http://math.libtomcrypt.com 15 * Tom St Denis, [email protected], http://libtom.org
16 */ 16 */
17 17
18 /* multiplies |a| * |b| and only computes upto digs digits of result 18 /* multiplies |a| * |b| and only computes upto digs digits of result
19 * HAC pp. 595, Algorithm 14.12 Modified so you can control how 19 * HAC pp. 595, Algorithm 14.12 Modified so you can control how
20 * many digits of output are created. 20 * many digits of output are created.
27 mp_word r; 27 mp_word r;
28 mp_digit tmpx, *tmpt, *tmpy; 28 mp_digit tmpx, *tmpt, *tmpy;
29 29
30 /* can we use the fast multiplier? */ 30 /* can we use the fast multiplier? */
31 if (((digs) < MP_WARRAY) && 31 if (((digs) < MP_WARRAY) &&
32 MIN (a->used, b->used) < 32 (MIN (a->used, b->used) <
33 (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) { 33 (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) {
34 return fast_s_mp_mul_digs (a, b, c, digs); 34 return fast_s_mp_mul_digs (a, b, c, digs);
35 } 35 }
36 36
37 if ((res = mp_init_size (&t, digs)) != MP_OKAY) { 37 if ((res = mp_init_size (&t, digs)) != MP_OKAY) {
38 return res; 38 return res;
59 tmpy = b->dp; 59 tmpy = b->dp;
60 60
61 /* compute the columns of the output and propagate the carry */ 61 /* compute the columns of the output and propagate the carry */
62 for (iy = 0; iy < pb; iy++) { 62 for (iy = 0; iy < pb; iy++) {
63 /* compute the column as a mp_word */ 63 /* compute the column as a mp_word */
64 r = ((mp_word)*tmpt) + 64 r = (mp_word)*tmpt +
65 ((mp_word)tmpx) * ((mp_word)*tmpy++) + 65 ((mp_word)tmpx * (mp_word)*tmpy++) +
66 ((mp_word) u); 66 (mp_word)u;
67 67
68 /* the new column is the lower part of the result */ 68 /* the new column is the lower part of the result */
69 *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK)); 69 *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
70 70
71 /* get the carry word from the result */ 71 /* get the carry word from the result */
72 u = (mp_digit) (r >> ((mp_word) DIGIT_BIT)); 72 u = (mp_digit) (r >> ((mp_word) DIGIT_BIT));
73 } 73 }
74 /* set carry if it is placed below digs */ 74 /* set carry if it is placed below digs */
75 if (ix + iy < digs) { 75 if ((ix + iy) < digs) {
76 *tmpt = u; 76 *tmpt = u;
77 } 77 }
78 } 78 }
79 79
80 mp_clamp (&t); 80 mp_clamp (&t);
83 mp_clear (&t); 83 mp_clear (&t);
84 return MP_OKAY; 84 return MP_OKAY;
85 } 85 }
86 #endif 86 #endif
87 87
88 /* $Source: /cvs/libtom/libtommath/bn_s_mp_mul_digs.c,v $ */ 88 /* $Source$ */
89 /* $Revision: 1.3 $ */ 89 /* $Revision$ */
90 /* $Date: 2006/03/31 14:18:44 $ */ 90 /* $Date$ */