diff options
Diffstat (limited to 'libtommath/bn_mp_expt_d.c')
-rw-r--r-- | libtommath/bn_mp_expt_d.c | 43 |
1 files changed, 9 insertions, 34 deletions
diff --git a/libtommath/bn_mp_expt_d.c b/libtommath/bn_mp_expt_d.c index 132f480..61c5a1d 100644 --- a/libtommath/bn_mp_expt_d.c +++ b/libtommath/bn_mp_expt_d.c @@ -1,4 +1,4 @@ -#include <tommath.h> +#include <tommath_private.h> #ifdef BN_MP_EXPT_D_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * @@ -12,42 +12,17 @@ * The library is free for all purposes without any express * guarantee it works. * - * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com + * Tom St Denis, tstdenis82@gmail.com, http://libtom.org */ -/* calculate c = a**b using a square-multiply algorithm */ +/* wrapper function for mp_expt_d_ex() */ int mp_expt_d (mp_int * a, mp_digit b, mp_int * c) { - int res, x; - mp_int g; - - if ((res = mp_init_copy (&g, a)) != MP_OKAY) { - return res; - } - - /* set initial result */ - mp_set (c, 1); - - for (x = 0; x < (int) DIGIT_BIT; x++) { - /* square */ - if ((res = mp_sqr (c, c)) != MP_OKAY) { - mp_clear (&g); - return res; - } - - /* if the bit is set multiply */ - if ((b & (mp_digit) (((mp_digit)1) << (DIGIT_BIT - 1))) != 0) { - if ((res = mp_mul (c, &g, c)) != MP_OKAY) { - mp_clear (&g); - return res; - } - } - - /* shift to next bit */ - b <<= 1; - } - - mp_clear (&g); - return MP_OKAY; + return mp_expt_d_ex(a, b, c, 0); } + #endif + +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */ |