comparison libtommath/bn_mp_mul_2d.c @ 1692:1051e4eea25a

Update LibTomMath to 1.2.0 (#84) * update C files * update other files * update headers * update makefiles * remove mp_set/get_double() * use ltm 1.2.0 API * update ltm_desc * use bundled tommath if system-tommath is too old * XMALLOC etc. were changed to MP_MALLOC etc.
author Steffen Jaeckel <s@jaeckel.eu>
date Tue, 26 May 2020 17:36:47 +0200
parents f52919ffd3b1
children
comparison
equal deleted inserted replaced
1691:2d3745d58843 1692:1051e4eea25a
1 #include "tommath_private.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 /* SPDX-License-Identifier: Unlicense */
5 * LibTomMath is a library that provides multiple-precision
6 * integer arithmetic as well as number theoretic functionality.
7 *
8 * The library was designed directly after the MPI library by
9 * Michael Fromberger but has been written from scratch with
10 * additional optimizations in place.
11 *
12 * SPDX-License-Identifier: Unlicense
13 */
14 5
15 /* shift left by a certain bit count */ 6 /* shift left by a certain bit count */
16 int mp_mul_2d(const mp_int *a, int b, mp_int *c) 7 mp_err mp_mul_2d(const mp_int *a, int b, mp_int *c)
17 { 8 {
18 mp_digit d; 9 mp_digit d;
19 int res; 10 mp_err err;
20 11
21 /* copy */ 12 /* copy */
22 if (a != c) { 13 if (a != c) {
23 if ((res = mp_copy(a, c)) != MP_OKAY) { 14 if ((err = mp_copy(a, c)) != MP_OKAY) {
24 return res; 15 return err;
25 } 16 }
26 } 17 }
27 18
28 if (c->alloc < (c->used + (b / DIGIT_BIT) + 1)) { 19 if (c->alloc < (c->used + (b / MP_DIGIT_BIT) + 1)) {
29 if ((res = mp_grow(c, c->used + (b / DIGIT_BIT) + 1)) != MP_OKAY) { 20 if ((err = mp_grow(c, c->used + (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) {
30 return res; 21 return err;
31 } 22 }
32 } 23 }
33 24
34 /* shift by as many digits in the bit count */ 25 /* shift by as many digits in the bit count */
35 if (b >= DIGIT_BIT) { 26 if (b >= MP_DIGIT_BIT) {
36 if ((res = mp_lshd(c, b / DIGIT_BIT)) != MP_OKAY) { 27 if ((err = mp_lshd(c, b / MP_DIGIT_BIT)) != MP_OKAY) {
37 return res; 28 return err;
38 } 29 }
39 } 30 }
40 31
41 /* shift any bit count < DIGIT_BIT */ 32 /* shift any bit count < MP_DIGIT_BIT */
42 d = (mp_digit)(b % DIGIT_BIT); 33 d = (mp_digit)(b % MP_DIGIT_BIT);
43 if (d != 0u) { 34 if (d != 0u) {
44 mp_digit *tmpc, shift, mask, r, rr; 35 mp_digit *tmpc, shift, mask, r, rr;
45 int x; 36 int x;
46 37
47 /* bitmask for carries */ 38 /* bitmask for carries */
48 mask = ((mp_digit)1 << d) - (mp_digit)1; 39 mask = ((mp_digit)1 << d) - (mp_digit)1;
49 40
50 /* shift for msbs */ 41 /* shift for msbs */
51 shift = (mp_digit)DIGIT_BIT - d; 42 shift = (mp_digit)MP_DIGIT_BIT - d;
52 43
53 /* alias */ 44 /* alias */
54 tmpc = c->dp; 45 tmpc = c->dp;
55 46
56 /* carry */ 47 /* carry */
74 } 65 }
75 mp_clamp(c); 66 mp_clamp(c);
76 return MP_OKAY; 67 return MP_OKAY;
77 } 68 }
78 #endif 69 #endif
79
80 /* ref: HEAD -> master, tag: v1.1.0 */
81 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
82 /* commit time: 2019-01-28 20:32:32 +0100 */