Mercurial > dropbear
comparison libtommath/bn_mp_mul_2d.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_MUL_2D_C | 2 #ifdef BN_MP_MUL_2D_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 /* shift left by a certain bit count */ | 18 /* shift left by a certain bit count */ |
19 int mp_mul_2d (mp_int * a, int b, mp_int * c) | 19 int mp_mul_2d (mp_int * a, int b, mp_int * c) |
20 { | 20 { |
26 if ((res = mp_copy (a, c)) != MP_OKAY) { | 26 if ((res = mp_copy (a, c)) != MP_OKAY) { |
27 return res; | 27 return res; |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 if (c->alloc < (int)(c->used + b/DIGIT_BIT + 1)) { | 31 if (c->alloc < (int)(c->used + (b / DIGIT_BIT) + 1)) { |
32 if ((res = mp_grow (c, c->used + b / DIGIT_BIT + 1)) != MP_OKAY) { | 32 if ((res = mp_grow (c, c->used + (b / DIGIT_BIT) + 1)) != MP_OKAY) { |
33 return res; | 33 return res; |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 /* shift by as many digits in the bit count */ | 37 /* shift by as many digits in the bit count */ |
42 } | 42 } |
43 | 43 |
44 /* shift any bit count < DIGIT_BIT */ | 44 /* shift any bit count < DIGIT_BIT */ |
45 d = (mp_digit) (b % DIGIT_BIT); | 45 d = (mp_digit) (b % DIGIT_BIT); |
46 if (d != 0) { | 46 if (d != 0) { |
47 register mp_digit *tmpc, shift, mask, r, rr; | 47 mp_digit *tmpc, shift, mask, r, rr; |
48 register int x; | 48 int x; |
49 | 49 |
50 /* bitmask for carries */ | 50 /* bitmask for carries */ |
51 mask = (((mp_digit)1) << d) - 1; | 51 mask = (((mp_digit)1) << d) - 1; |
52 | 52 |
53 /* shift for msbs */ | 53 /* shift for msbs */ |
78 mp_clamp (c); | 78 mp_clamp (c); |
79 return MP_OKAY; | 79 return MP_OKAY; |
80 } | 80 } |
81 #endif | 81 #endif |
82 | 82 |
83 /* $Source: /cvs/libtom/libtommath/bn_mp_mul_2d.c,v $ */ | 83 /* $Source$ */ |
84 /* $Revision: 1.3 $ */ | 84 /* $Revision$ */ |
85 /* $Date: 2006/03/31 14:18:44 $ */ | 85 /* $Date$ */ |