summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_montgomery_reduce.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-06-13 19:07:13 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-06-13 19:07:13 (GMT)
commit505f963287b050bd46871d4659cebc65986ca5ac (patch)
tree853ad3262ab07f7c5755e76b8154f36f24608014 /libtommath/bn_mp_montgomery_reduce.c
parent689987ea924a8fded1801777c1a14ab1205fa826 (diff)
downloadtcl-505f963287b050bd46871d4659cebc65986ca5ac.zip
tcl-505f963287b050bd46871d4659cebc65986ca5ac.tar.gz
tcl-505f963287b050bd46871d4659cebc65986ca5ac.tar.bz2
Update to latest libtommath's "develop" branch. On the way to 1.2.0
Diffstat (limited to 'libtommath/bn_mp_montgomery_reduce.c')
-rw-r--r--libtommath/bn_mp_montgomery_reduce.c39
1 files changed, 13 insertions, 26 deletions
diff --git a/libtommath/bn_mp_montgomery_reduce.c b/libtommath/bn_mp_montgomery_reduce.c
index 382c7cc..ffe8341 100644
--- a/libtommath/bn_mp_montgomery_reduce.c
+++ b/libtommath/bn_mp_montgomery_reduce.c
@@ -1,21 +1,13 @@
#include "tommath_private.h"
#ifdef BN_MP_MONTGOMERY_REDUCE_C
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * SPDX-License-Identifier: Unlicense
- */
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
/* computes xR**-1 == x (mod N) via Montgomery Reduction */
-int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
+mp_err mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
{
- int ix, res, digs;
+ int ix, digs;
+ mp_err err;
mp_digit mu;
/* can the fast reduction [comba] method be used?
@@ -25,17 +17,16 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
* are fixed up in the inner loop.
*/
digs = (n->used * 2) + 1;
- if ((digs < (int)MP_WARRAY) &&
- (x->used <= (int)MP_WARRAY) &&
- (n->used <
- (int)(1u << (((size_t)CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) {
- return fast_mp_montgomery_reduce(x, n, rho);
+ if ((digs < MP_WARRAY) &&
+ (x->used <= MP_WARRAY) &&
+ (n->used < MP_MAXFAST)) {
+ return s_mp_montgomery_reduce_fast(x, n, rho);
}
/* grow the input as required */
if (x->alloc < digs) {
- if ((res = mp_grow(x, digs)) != MP_OKAY) {
- return res;
+ if ((err = mp_grow(x, digs)) != MP_OKAY) {
+ return err;
}
}
x->used = digs;
@@ -73,7 +64,7 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
(mp_word)u + (mp_word)*tmpx;
/* get carry */
- u = (mp_digit)(r >> (mp_word)DIGIT_BIT);
+ u = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
/* fix digit */
*tmpx++ = (mp_digit)(r & (mp_word)MP_MASK);
@@ -84,7 +75,7 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
/* propagate carries upwards as required*/
while (u != 0u) {
*tmpx += u;
- u = *tmpx >> DIGIT_BIT;
+ u = *tmpx >> MP_DIGIT_BIT;
*tmpx++ &= MP_MASK;
}
}
@@ -109,7 +100,3 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
return MP_OKAY;
}
#endif
-
-/* ref: $Format:%D$ */
-/* git commit: $Format:%H$ */
-/* commit time: $Format:%ai$ */