Mercurial > dropbear
comparison libtommath/bn_s_mp_exptmod.c @ 1436:60fc6476e044
Update to libtommath v1.0
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 24 Jun 2017 22:37:14 +0800 |
parents | 5ff8218bcee9 |
children | 8bba51a55704 |
comparison
equal
deleted
inserted
replaced
1435:f849a5ca2efc | 1436:60fc6476e044 |
---|---|
1 #include <tommath.h> | 1 #include <tommath_private.h> |
2 #ifdef BN_S_MP_EXPTMOD_C | 2 #ifdef BN_S_MP_EXPTMOD_C |
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis | 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis |
4 * | 4 * |
5 * LibTomMath is a library that provides multiple-precision | 5 * LibTomMath is a library that provides multiple-precision |
6 * integer arithmetic as well as number theoretic functionality. | 6 * integer arithmetic as well as number theoretic functionality. |
10 * additional optimizations in place. | 10 * additional optimizations in place. |
11 * | 11 * |
12 * The library is free for all purposes without any express | 12 * The library is free for all purposes without any express |
13 * guarantee it works. | 13 * guarantee it works. |
14 * | 14 * |
15 * Tom St Denis, [email protected], http://math.libtomcrypt.com | 15 * Tom St Denis, [email protected], http://libtom.org |
16 */ | 16 */ |
17 #ifdef MP_LOW_MEM | 17 #ifdef MP_LOW_MEM |
18 #define TAB_SIZE 32 | 18 #define TAB_SIZE 32 |
19 #else | 19 #else |
20 #define TAB_SIZE 256 | 20 #define TAB_SIZE 256 |
162 /* if the bit is zero and mode == 0 then we ignore it | 162 /* if the bit is zero and mode == 0 then we ignore it |
163 * These represent the leading zero bits before the first 1 bit | 163 * These represent the leading zero bits before the first 1 bit |
164 * in the exponent. Technically this opt is not required but it | 164 * in the exponent. Technically this opt is not required but it |
165 * does lower the # of trivial squaring/reductions used | 165 * does lower the # of trivial squaring/reductions used |
166 */ | 166 */ |
167 if (mode == 0 && y == 0) { | 167 if ((mode == 0) && (y == 0)) { |
168 continue; | 168 continue; |
169 } | 169 } |
170 | 170 |
171 /* if the bit is zero and mode == 1 then we square */ | 171 /* if the bit is zero and mode == 1 then we square */ |
172 if (mode == 1 && y == 0) { | 172 if ((mode == 1) && (y == 0)) { |
173 if ((err = mp_sqr (&res, &res)) != MP_OKAY) { | 173 if ((err = mp_sqr (&res, &res)) != MP_OKAY) { |
174 goto LBL_RES; | 174 goto LBL_RES; |
175 } | 175 } |
176 if ((err = redux (&res, P, &mu)) != MP_OKAY) { | 176 if ((err = redux (&res, P, &mu)) != MP_OKAY) { |
177 goto LBL_RES; | 177 goto LBL_RES; |
209 mode = 1; | 209 mode = 1; |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 /* if bits remain then square/multiply */ | 213 /* if bits remain then square/multiply */ |
214 if (mode == 2 && bitcpy > 0) { | 214 if ((mode == 2) && (bitcpy > 0)) { |
215 /* square then multiply if the bit is set */ | 215 /* square then multiply if the bit is set */ |
216 for (x = 0; x < bitcpy; x++) { | 216 for (x = 0; x < bitcpy; x++) { |
217 if ((err = mp_sqr (&res, &res)) != MP_OKAY) { | 217 if ((err = mp_sqr (&res, &res)) != MP_OKAY) { |
218 goto LBL_RES; | 218 goto LBL_RES; |
219 } | 219 } |
245 } | 245 } |
246 return err; | 246 return err; |
247 } | 247 } |
248 #endif | 248 #endif |
249 | 249 |
250 /* $Source: /cvs/libtom/libtommath/bn_s_mp_exptmod.c,v $ */ | 250 /* $Source$ */ |
251 /* $Revision: 1.4 $ */ | 251 /* $Revision$ */ |
252 /* $Date: 2006/03/31 14:18:44 $ */ | 252 /* $Date$ */ |