Mercurial > dropbear
comparison bn_fast_s_mp_mul_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 |
---|---|
29 * required for fast Barrett reduction). | 29 * required for fast Barrett reduction). |
30 * | 30 * |
31 * Based on Algorithm 14.12 on pp.595 of HAC. | 31 * Based on Algorithm 14.12 on pp.595 of HAC. |
32 * | 32 * |
33 */ | 33 */ |
34 int | 34 int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) |
35 fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) | |
36 { | 35 { |
37 int olduse, res, pa, ix, iz; | 36 int olduse, res, pa, ix, iz; |
38 mp_digit W[MP_WARRAY]; | 37 mp_digit W[MP_WARRAY]; |
39 register mp_word _W; | 38 register mp_word _W; |
40 | 39 |
48 /* number of output digits to produce */ | 47 /* number of output digits to produce */ |
49 pa = MIN(digs, a->used + b->used); | 48 pa = MIN(digs, a->used + b->used); |
50 | 49 |
51 /* clear the carry */ | 50 /* clear the carry */ |
52 _W = 0; | 51 _W = 0; |
53 for (ix = 0; ix <= pa; ix++) { | 52 for (ix = 0; ix < pa; ix++) { |
54 int tx, ty; | 53 int tx, ty; |
55 int iy; | 54 int iy; |
56 mp_digit *tmpx, *tmpy; | 55 mp_digit *tmpx, *tmpy; |
57 | 56 |
58 /* get offsets into the two bignums */ | 57 /* get offsets into the two bignums */ |
61 | 60 |
62 /* setup temp aliases */ | 61 /* setup temp aliases */ |
63 tmpx = a->dp + tx; | 62 tmpx = a->dp + tx; |
64 tmpy = b->dp + ty; | 63 tmpy = b->dp + ty; |
65 | 64 |
66 /* this is the number of times the loop will iterrate, essentially its | 65 /* this is the number of times the loop will iterrate, essentially |
67 while (tx++ < a->used && ty-- >= 0) { ... } | 66 while (tx++ < a->used && ty-- >= 0) { ... } |
68 */ | 67 */ |
69 iy = MIN(a->used-tx, ty+1); | 68 iy = MIN(a->used-tx, ty+1); |
70 | 69 |
71 /* execute loop */ | 70 /* execute loop */ |
78 | 77 |
79 /* make next carry */ | 78 /* make next carry */ |
80 _W = _W >> ((mp_word)DIGIT_BIT); | 79 _W = _W >> ((mp_word)DIGIT_BIT); |
81 } | 80 } |
82 | 81 |
82 /* store final carry */ | |
83 W[ix] = (mp_digit)(_W & MP_MASK); | |
84 | |
83 /* setup dest */ | 85 /* setup dest */ |
84 olduse = c->used; | 86 olduse = c->used; |
85 c->used = digs; | 87 c->used = pa; |
86 | 88 |
87 { | 89 { |
88 register mp_digit *tmpc; | 90 register mp_digit *tmpc; |
89 tmpc = c->dp; | 91 tmpc = c->dp; |
90 for (ix = 0; ix < digs; ix++) { | 92 for (ix = 0; ix < pa+1; ix++) { |
91 /* now extract the previous digit [below the carry] */ | 93 /* now extract the previous digit [below the carry] */ |
92 *tmpc++ = W[ix]; | 94 *tmpc++ = W[ix]; |
93 } | 95 } |
94 | 96 |
95 /* clear unused digits [that existed in the old copy of c] */ | 97 /* clear unused digits [that existed in the old copy of c] */ |