Mercurial > dropbear
comparison libtommath/bn_mp_mul_d.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_D_C | 2 #ifdef BN_MP_MUL_D_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 /* multiply by a digit */ | 6 /* multiply by a digit */ |
16 int mp_mul_d(const mp_int *a, mp_digit b, mp_int *c) | 7 mp_err mp_mul_d(const mp_int *a, mp_digit b, mp_int *c) |
17 { | 8 { |
18 mp_digit u, *tmpa, *tmpc; | 9 mp_digit u, *tmpa, *tmpc; |
19 mp_word r; | 10 mp_word r; |
20 int ix, res, olduse; | 11 mp_err err; |
12 int ix, olduse; | |
21 | 13 |
22 /* make sure c is big enough to hold a*b */ | 14 /* make sure c is big enough to hold a*b */ |
23 if (c->alloc < (a->used + 1)) { | 15 if (c->alloc < (a->used + 1)) { |
24 if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) { | 16 if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) { |
25 return res; | 17 return err; |
26 } | 18 } |
27 } | 19 } |
28 | 20 |
29 /* get the original destinations used count */ | 21 /* get the original destinations used count */ |
30 olduse = c->used; | 22 olduse = c->used; |
48 | 40 |
49 /* mask off higher bits to get a single digit */ | 41 /* mask off higher bits to get a single digit */ |
50 *tmpc++ = (mp_digit)(r & (mp_word)MP_MASK); | 42 *tmpc++ = (mp_digit)(r & (mp_word)MP_MASK); |
51 | 43 |
52 /* send carry into next iteration */ | 44 /* send carry into next iteration */ |
53 u = (mp_digit)(r >> (mp_word)DIGIT_BIT); | 45 u = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT); |
54 } | 46 } |
55 | 47 |
56 /* store final carry [if any] and increment ix offset */ | 48 /* store final carry [if any] and increment ix offset */ |
57 *tmpc++ = u; | 49 *tmpc++ = u; |
58 ++ix; | 50 ++ix; |
59 | 51 |
60 /* now zero digits above the top */ | 52 /* now zero digits above the top */ |
61 while (ix++ < olduse) { | 53 MP_ZERO_DIGITS(tmpc, olduse - ix); |
62 *tmpc++ = 0; | |
63 } | |
64 | 54 |
65 /* set used count */ | 55 /* set used count */ |
66 c->used = a->used + 1; | 56 c->used = a->used + 1; |
67 mp_clamp(c); | 57 mp_clamp(c); |
68 | 58 |
69 return MP_OKAY; | 59 return MP_OKAY; |
70 } | 60 } |
71 #endif | 61 #endif |
72 | |
73 /* ref: HEAD -> master, tag: v1.1.0 */ | |
74 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ | |
75 /* commit time: 2019-01-28 20:32:32 +0100 */ |