Mercurial > dropbear
comparison libtommath/bn_mp_montgomery_setup.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_MP_MONTGOMERY_SETUP_C | 2 #ifdef BN_MP_MONTGOMERY_SETUP_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 | 17 |
18 /* setups the montgomery reduction stuff */ | 18 /* setups the montgomery reduction stuff */ |
19 int | 19 int |
20 mp_montgomery_setup (mp_int * n, mp_digit * rho) | 20 mp_montgomery_setup (mp_int * n, mp_digit * rho) |
34 if ((b & 1) == 0) { | 34 if ((b & 1) == 0) { |
35 return MP_VAL; | 35 return MP_VAL; |
36 } | 36 } |
37 | 37 |
38 x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ | 38 x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ |
39 x *= 2 - b * x; /* here x*a==1 mod 2**8 */ | 39 x *= 2 - (b * x); /* here x*a==1 mod 2**8 */ |
40 #if !defined(MP_8BIT) | 40 #if !defined(MP_8BIT) |
41 x *= 2 - b * x; /* here x*a==1 mod 2**16 */ | 41 x *= 2 - (b * x); /* here x*a==1 mod 2**16 */ |
42 #endif | 42 #endif |
43 #if defined(MP_64BIT) || !(defined(MP_8BIT) || defined(MP_16BIT)) | 43 #if defined(MP_64BIT) || !(defined(MP_8BIT) || defined(MP_16BIT)) |
44 x *= 2 - b * x; /* here x*a==1 mod 2**32 */ | 44 x *= 2 - (b * x); /* here x*a==1 mod 2**32 */ |
45 #endif | 45 #endif |
46 #ifdef MP_64BIT | 46 #ifdef MP_64BIT |
47 x *= 2 - b * x; /* here x*a==1 mod 2**64 */ | 47 x *= 2 - (b * x); /* here x*a==1 mod 2**64 */ |
48 #endif | 48 #endif |
49 | 49 |
50 /* rho = -1/m mod b */ | 50 /* rho = -1/m mod b */ |
51 *rho = (unsigned long)(((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK; | 51 *rho = (mp_digit)(((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK; |
52 | 52 |
53 return MP_OKAY; | 53 return MP_OKAY; |
54 } | 54 } |
55 #endif | 55 #endif |
56 | 56 |
57 /* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_setup.c,v $ */ | 57 /* $Source$ */ |
58 /* $Revision: 1.4 $ */ | 58 /* $Revision$ */ |
59 /* $Date: 2006/12/04 21:34:03 $ */ | 59 /* $Date$ */ |