comparison libtommath/bn_fast_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_FAST_S_MP_MUL_DIGS_C 2 #ifdef BN_FAST_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 /* Fast (comba) multiplier 18 /* Fast (comba) multiplier
19 * 19 *
20 * This is the fast column-array [comba] multiplier. It is 20 * This is the fast column-array [comba] multiplier. It is
33 */ 33 */
34 int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) 34 int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
35 { 35 {
36 int olduse, res, pa, ix, iz; 36 int olduse, res, pa, ix, iz;
37 mp_digit W[MP_WARRAY]; 37 mp_digit W[MP_WARRAY];
38 register mp_word _W; 38 mp_word _W;
39 39
40 /* grow the destination as required */ 40 /* grow the destination as required */
41 if (c->alloc < digs) { 41 if (c->alloc < digs) {
42 if ((res = mp_grow (c, digs)) != MP_OKAY) { 42 if ((res = mp_grow (c, digs)) != MP_OKAY) {
43 return res; 43 return res;
76 /* store term */ 76 /* store term */
77 W[ix] = ((mp_digit)_W) & MP_MASK; 77 W[ix] = ((mp_digit)_W) & MP_MASK;
78 78
79 /* make next carry */ 79 /* make next carry */
80 _W = _W >> ((mp_word)DIGIT_BIT); 80 _W = _W >> ((mp_word)DIGIT_BIT);
81 } 81 }
82 82
83 /* setup dest */ 83 /* setup dest */
84 olduse = c->used; 84 olduse = c->used;
85 c->used = pa; 85 c->used = pa;
86 86
87 { 87 {
88 register mp_digit *tmpc; 88 mp_digit *tmpc;
89 tmpc = c->dp; 89 tmpc = c->dp;
90 for (ix = 0; ix < pa+1; ix++) { 90 for (ix = 0; ix < (pa + 1); ix++) {
91 /* now extract the previous digit [below the carry] */ 91 /* now extract the previous digit [below the carry] */
92 *tmpc++ = W[ix]; 92 *tmpc++ = W[ix];
93 } 93 }
94 94
95 /* clear unused digits [that existed in the old copy of c] */ 95 /* clear unused digits [that existed in the old copy of c] */
100 mp_clamp (c); 100 mp_clamp (c);
101 return MP_OKAY; 101 return MP_OKAY;
102 } 102 }
103 #endif 103 #endif
104 104
105 /* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_mul_digs.c,v $ */ 105 /* $Source$ */
106 /* $Revision: 1.7 $ */ 106 /* $Revision$ */
107 /* $Date: 2006/03/31 14:18:44 $ */ 107 /* $Date$ */