comparison libtommath/bn_s_mp_mul_high_digs.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_S_MP_MUL_HIGH_DIGS_C 2 #ifdef BN_S_MP_MUL_HIGH_DIGS_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 /* multiplies |a| * |b| and does not compute the lower digs digits 6 /* multiplies |a| * |b| and does not compute the lower digs digits
16 * [meant to get the higher part of the product] 7 * [meant to get the higher part of the product]
17 */ 8 */
18 int s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) 9 mp_err s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
19 { 10 {
20 mp_int t; 11 mp_int t;
21 int res, pa, pb, ix, iy; 12 int pa, pb, ix, iy;
13 mp_err err;
22 mp_digit u; 14 mp_digit u;
23 mp_word r; 15 mp_word r;
24 mp_digit tmpx, *tmpt, *tmpy; 16 mp_digit tmpx, *tmpt, *tmpy;
25 17
26 /* can we use the fast multiplier? */ 18 /* can we use the fast multiplier? */
27 #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C 19 if (MP_HAS(S_MP_MUL_HIGH_DIGS_FAST)
28 if (((a->used + b->used + 1) < (int)MP_WARRAY) 20 && ((a->used + b->used + 1) < MP_WARRAY)
29 && (MIN(a->used, b->used) < (int)(1u << (((size_t)CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) { 21 && (MP_MIN(a->used, b->used) < MP_MAXFAST)) {
30 return fast_s_mp_mul_high_digs(a, b, c, digs); 22 return s_mp_mul_high_digs_fast(a, b, c, digs);
31 } 23 }
32 #endif
33 24
34 if ((res = mp_init_size(&t, a->used + b->used + 1)) != MP_OKAY) { 25 if ((err = mp_init_size(&t, a->used + b->used + 1)) != MP_OKAY) {
35 return res; 26 return err;
36 } 27 }
37 t.used = a->used + b->used + 1; 28 t.used = a->used + b->used + 1;
38 29
39 pa = a->used; 30 pa = a->used;
40 pb = b->used; 31 pb = b->used;
59 50
60 /* get the lower part */ 51 /* get the lower part */
61 *tmpt++ = (mp_digit)(r & (mp_word)MP_MASK); 52 *tmpt++ = (mp_digit)(r & (mp_word)MP_MASK);
62 53
63 /* carry the carry */ 54 /* carry the carry */
64 u = (mp_digit)(r >> (mp_word)DIGIT_BIT); 55 u = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
65 } 56 }
66 *tmpt = u; 57 *tmpt = u;
67 } 58 }
68 mp_clamp(&t); 59 mp_clamp(&t);
69 mp_exch(&t, c); 60 mp_exch(&t, c);
70 mp_clear(&t); 61 mp_clear(&t);
71 return MP_OKAY; 62 return MP_OKAY;
72 } 63 }
73 #endif 64 #endif
74
75 /* ref: HEAD -> master, tag: v1.1.0 */
76 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
77 /* commit time: 2019-01-28 20:32:32 +0100 */