comparison bn_fast_s_mp_mul_high_digs.c @ 190:d8254fc979e9 libtommath-orig LTM_0.35

Initial import of libtommath 0.35
author Matt Johnston <matt@ucc.asn.au>
date Fri, 06 May 2005 08:59:30 +0000
parents d29b64170cf0
children
comparison
equal deleted inserted replaced
142:d29b64170cf0 190:d8254fc979e9
22 * This is used in the Barrett reduction since for one of the multiplications 22 * This is used in the Barrett reduction since for one of the multiplications
23 * only the higher digits were needed. This essentially halves the work. 23 * only the higher digits were needed. This essentially halves the work.
24 * 24 *
25 * Based on Algorithm 14.12 on pp.595 of HAC. 25 * Based on Algorithm 14.12 on pp.595 of HAC.
26 */ 26 */
27 int 27 int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
28 fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
29 { 28 {
30 int olduse, res, pa, ix, iz; 29 int olduse, res, pa, ix, iz;
31 mp_digit W[MP_WARRAY]; 30 mp_digit W[MP_WARRAY];
32 mp_word _W; 31 mp_word _W;
33 32
40 } 39 }
41 40
42 /* number of output digits to produce */ 41 /* number of output digits to produce */
43 pa = a->used + b->used; 42 pa = a->used + b->used;
44 _W = 0; 43 _W = 0;
45 for (ix = digs; ix <= pa; ix++) { 44 for (ix = digs; ix < pa; ix++) {
46 int tx, ty, iy; 45 int tx, ty, iy;
47 mp_digit *tmpx, *tmpy; 46 mp_digit *tmpx, *tmpy;
48 47
49 /* get offsets into the two bignums */ 48 /* get offsets into the two bignums */
50 ty = MIN(b->used-1, ix); 49 ty = MIN(b->used-1, ix);
68 W[ix] = ((mp_digit)_W) & MP_MASK; 67 W[ix] = ((mp_digit)_W) & MP_MASK;
69 68
70 /* make next carry */ 69 /* make next carry */
71 _W = _W >> ((mp_word)DIGIT_BIT); 70 _W = _W >> ((mp_word)DIGIT_BIT);
72 } 71 }
72
73 /* store final carry */
74 W[ix] = (mp_digit)(_W & MP_MASK);
73 75
74 /* setup dest */ 76 /* setup dest */
75 olduse = c->used; 77 olduse = c->used;
76 c->used = pa; 78 c->used = pa;
77 79