X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=userapps%2Fopensource%2Fsshd%2Flibtommath%2Fbn_mp_dr_reduce.c;fp=userapps%2Fopensource%2Fsshd%2Flibtommath%2Fbn_mp_dr_reduce.c;h=9bb7ad78920afc619feab611b7324ec4a577a42a;hb=57a096f051259ceaefd5977f30d269884e1dd248;hp=7d7259e5424b1086580eb02f97bacb60404efcf5;hpb=9887430fc6b7c0f8eb8e81de2bfe3bba12d8d4a1;p=bcm963xx.git diff --git a/userapps/opensource/sshd/libtommath/bn_mp_dr_reduce.c b/userapps/opensource/sshd/libtommath/bn_mp_dr_reduce.c index 7d7259e5..9bb7ad78 100755 --- a/userapps/opensource/sshd/libtommath/bn_mp_dr_reduce.c +++ b/userapps/opensource/sshd/libtommath/bn_mp_dr_reduce.c @@ -1,9 +1,11 @@ +#include +#ifdef BN_MP_DR_REDUCE_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,19 +14,20 @@ * * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org */ -#include /* reduce "x" in place modulo "n" using the Diminished Radix algorithm. * * Based on algorithm from the paper * * "Generating Efficient Primes for Discrete Log Cryptosystems" - * Chae Hoon Lim, Pil Loong Lee, + * Chae Hoon Lim, Pil Joong Lee, * POSTECH Information Research Laboratories * * The modulus must be of a special format [see manual] * * Has been modified to use algorithm 7.10 from the LTM book instead + * + * Input x must be in the range 0 <= x <= (n-1)**2 */ int mp_dr_reduce (mp_int * x, mp_int * n, mp_digit k) @@ -32,10 +35,10 @@ mp_dr_reduce (mp_int * x, mp_int * n, mp_digit k) int err, i, m; mp_word r; mp_digit mu, *tmpx1, *tmpx2; - + /* m = digits in modulus */ m = n->used; - + /* ensure that "x" has at least 2m digits */ if (x->alloc < m + m) { if ((err = mp_grow (x, m + m)) != MP_OKAY) { @@ -43,30 +46,30 @@ mp_dr_reduce (mp_int * x, mp_int * n, mp_digit k) } } -/* top of loop, this is where the code resumes if +/* top of loop, this is where the code resumes if * another reduction pass is required. */ top: /* aliases for digits */ /* alias for lower half of x */ tmpx1 = x->dp; - + /* alias for upper half of x, or x/B**m */ tmpx2 = x->dp + m; - + /* set carry to zero */ mu = 0; - - /* compute (x mod B**m) + mp * [x/B**m] inline and inplace */ + + /* compute (x mod B**m) + k * [x/B**m] inline and inplace */ for (i = 0; i < m; i++) { r = ((mp_word)*tmpx2++) * ((mp_word)k) + *tmpx1 + mu; *tmpx1++ = (mp_digit)(r & MP_MASK); mu = (mp_digit)(r >> ((mp_word)DIGIT_BIT)); } - + /* set final carry */ *tmpx1++ = mu; - + /* zero words above m */ for (i = m + 1; i < x->used; i++) { *tmpx1++ = 0; @@ -75,7 +78,7 @@ top: /* clamp, sub and return */ mp_clamp (x); - /* if x >= n then subtract and reduce again + /* if x >= n then subtract and reduce again * Each successive "recursion" makes the input smaller and smaller. */ if (mp_cmp_mag (x, n) != MP_LT) { @@ -84,3 +87,4 @@ top: } return MP_OKAY; } +#endif