Mercurial > dropbear
comparison libtommath/bn_mp_lcm.c @ 1655:f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
* make key-generation compliant to FIPS 186.4
* fix includes in tommath_class.h
* update fuzzcorpus instead of error-out
* fixup fuzzing make-targets
* update Makefile.in
* apply necessary patches to ltm sources
* clean-up not required ltm files
* update to vanilla ltm 1.1.0
this already only contains the required files
* remove set/get double
author | Steffen Jaeckel <s_jaeckel@gmx.de> |
---|---|
date | Mon, 16 Sep 2019 15:50:38 +0200 |
parents | 8bba51a55704 |
children | 1051e4eea25a |
comparison
equal
deleted
inserted
replaced
1654:cc0fc5131c5c | 1655:f52919ffd3b1 |
---|---|
1 #include <tommath_private.h> | 1 #include "tommath_private.h" |
2 #ifdef BN_MP_LCM_C | 2 #ifdef BN_MP_LCM_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. |
7 * | 7 * |
8 * The library was designed directly after the MPI library by | 8 * The library was designed directly after the MPI library by |
9 * Michael Fromberger but has been written from scratch with | 9 * Michael Fromberger but has been written from scratch with |
10 * additional optimizations in place. | 10 * additional optimizations in place. |
11 * | 11 * |
12 * The library is free for all purposes without any express | 12 * SPDX-License-Identifier: Unlicense |
13 * guarantee it works. | |
14 * | |
15 * Tom St Denis, [email protected], http://libtom.org | |
16 */ | 13 */ |
17 | 14 |
18 /* computes least common multiple as |a*b|/(a, b) */ | 15 /* computes least common multiple as |a*b|/(a, b) */ |
19 int mp_lcm (mp_int * a, mp_int * b, mp_int * c) | 16 int mp_lcm(const mp_int *a, const mp_int *b, mp_int *c) |
20 { | 17 { |
21 int res; | 18 int res; |
22 mp_int t1, t2; | 19 mp_int t1, t2; |
23 | 20 |
24 | 21 |
25 if ((res = mp_init_multi (&t1, &t2, NULL)) != MP_OKAY) { | 22 if ((res = mp_init_multi(&t1, &t2, NULL)) != MP_OKAY) { |
26 return res; | 23 return res; |
27 } | 24 } |
28 | 25 |
29 /* t1 = get the GCD of the two inputs */ | 26 /* t1 = get the GCD of the two inputs */ |
30 if ((res = mp_gcd (a, b, &t1)) != MP_OKAY) { | 27 if ((res = mp_gcd(a, b, &t1)) != MP_OKAY) { |
31 goto LBL_T; | 28 goto LBL_T; |
32 } | 29 } |
33 | 30 |
34 /* divide the smallest by the GCD */ | 31 /* divide the smallest by the GCD */ |
35 if (mp_cmp_mag(a, b) == MP_LT) { | 32 if (mp_cmp_mag(a, b) == MP_LT) { |
36 /* store quotient in t2 such that t2 * b is the LCM */ | 33 /* store quotient in t2 such that t2 * b is the LCM */ |
37 if ((res = mp_div(a, &t1, &t2, NULL)) != MP_OKAY) { | 34 if ((res = mp_div(a, &t1, &t2, NULL)) != MP_OKAY) { |
38 goto LBL_T; | 35 goto LBL_T; |
39 } | 36 } |
40 res = mp_mul(b, &t2, c); | 37 res = mp_mul(b, &t2, c); |
41 } else { | 38 } else { |
42 /* store quotient in t2 such that t2 * a is the LCM */ | 39 /* store quotient in t2 such that t2 * a is the LCM */ |
43 if ((res = mp_div(b, &t1, &t2, NULL)) != MP_OKAY) { | 40 if ((res = mp_div(b, &t1, &t2, NULL)) != MP_OKAY) { |
44 goto LBL_T; | 41 goto LBL_T; |
45 } | 42 } |
46 res = mp_mul(a, &t2, c); | 43 res = mp_mul(a, &t2, c); |
47 } | 44 } |
48 | 45 |
49 /* fix the sign to positive */ | 46 /* fix the sign to positive */ |
50 c->sign = MP_ZPOS; | 47 c->sign = MP_ZPOS; |
51 | 48 |
52 LBL_T: | 49 LBL_T: |
53 mp_clear_multi (&t1, &t2, NULL); | 50 mp_clear_multi(&t1, &t2, NULL); |
54 return res; | 51 return res; |
55 } | 52 } |
56 #endif | 53 #endif |
57 | 54 |
58 /* ref: $Format:%D$ */ | 55 /* ref: HEAD -> master, tag: v1.1.0 */ |
59 /* git commit: $Format:%H$ */ | 56 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ |
60 /* commit time: $Format:%ai$ */ | 57 /* commit time: 2019-01-28 20:32:32 +0100 */ |