X-Git-Url: http://git.rot13.org/?p=bcm963xx.git;a=blobdiff_plain;f=userapps%2Fopensource%2Fsshd%2Flibtommath%2Fbn_mp_mul_2d.c;h=04cb8dd9e301bd0967f876f20c82af6e2f62712d;hp=ded3a3c6b84a07366883cb22804d2b6c589c7209;hb=57a096f051259ceaefd5977f30d269884e1dd248;hpb=9887430fc6b7c0f8eb8e81de2bfe3bba12d8d4a1 diff --git a/userapps/opensource/sshd/libtommath/bn_mp_mul_2d.c b/userapps/opensource/sshd/libtommath/bn_mp_mul_2d.c index ded3a3c6..04cb8dd9 100755 --- a/userapps/opensource/sshd/libtommath/bn_mp_mul_2d.c +++ b/userapps/opensource/sshd/libtommath/bn_mp_mul_2d.c @@ -1,9 +1,11 @@ +#include +#ifdef BN_MP_MUL_2D_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * - * LibTomMath is library that provides for multiple-precision + * LibTomMath is a library that provides multiple-precision * integer arithmetic as well as number theoretic functionality. * - * The library is designed directly after the MPI library by + * The library was designed directly after the MPI library by * Michael Fromberger but has been written from scratch with * additional optimizations in place. * @@ -12,17 +14,9 @@ * * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org */ -#include - -/* NOTE: This routine requires updating. For instance the c->used = c->alloc bit - is wrong. We should just shift c->used digits then set the carry as c->dp[c->used] = carry - - To be fixed for LTM 0.18 - */ /* shift left by a certain bit count */ -int -mp_mul_2d (mp_int * a, int b, mp_int * c) +int mp_mul_2d (mp_int * a, int b, mp_int * c) { mp_digit d; int res; @@ -34,8 +28,8 @@ mp_mul_2d (mp_int * a, int b, mp_int * c) } } - if (c->alloc < (int)(c->used + b/DIGIT_BIT + 2)) { - if ((res = mp_grow (c, c->used + b / DIGIT_BIT + 2)) != MP_OKAY) { + if (c->alloc < (int)(c->used + b/DIGIT_BIT + 1)) { + if ((res = mp_grow (c, c->used + b / DIGIT_BIT + 1)) != MP_OKAY) { return res; } } @@ -46,17 +40,19 @@ mp_mul_2d (mp_int * a, int b, mp_int * c) return res; } } - c->used = c->alloc; /* shift any bit count < DIGIT_BIT */ d = (mp_digit) (b % DIGIT_BIT); if (d != 0) { - register mp_digit *tmpc, mask, r, rr; + register mp_digit *tmpc, shift, mask, r, rr; register int x; /* bitmask for carries */ mask = (((mp_digit)1) << d) - 1; + /* shift for msbs */ + shift = DIGIT_BIT - d; + /* alias */ tmpc = c->dp; @@ -64,7 +60,7 @@ mp_mul_2d (mp_int * a, int b, mp_int * c) r = 0; for (x = 0; x < c->used; x++) { /* get the higher bits of the current word */ - rr = (*tmpc >> (DIGIT_BIT - d)) & mask; + rr = (*tmpc >> shift) & mask; /* shift the current word and OR in the carry */ *tmpc = ((*tmpc << d) | r) & MP_MASK; @@ -73,7 +69,13 @@ mp_mul_2d (mp_int * a, int b, mp_int * c) /* set the carry to the carry bits of the current word */ r = rr; } + + /* set final carry */ + if (r != 0) { + c->dp[(c->used)++] = r; + } } mp_clamp (c); return MP_OKAY; } +#endif