Mercurial > dropbear
comparison libtommath/bn_mp_add.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_ADD_C | 2 #ifdef BN_MP_ADD_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 /* high level addition (handles signs) */ | 15 /* high level addition (handles signs) */ |
19 int mp_add (mp_int * a, mp_int * b, mp_int * c) | 16 int mp_add(const mp_int *a, const mp_int *b, mp_int *c) |
20 { | 17 { |
21 int sa, sb, res; | 18 int sa, sb, res; |
22 | 19 |
23 /* get sign of both inputs */ | 20 /* get sign of both inputs */ |
24 sa = a->sign; | 21 sa = a->sign; |
25 sb = b->sign; | 22 sb = b->sign; |
26 | 23 |
27 /* handle two cases, not four */ | 24 /* handle two cases, not four */ |
28 if (sa == sb) { | 25 if (sa == sb) { |
29 /* both positive or both negative */ | 26 /* both positive or both negative */ |
30 /* add their magnitudes, copy the sign */ | 27 /* add their magnitudes, copy the sign */ |
31 c->sign = sa; | |
32 res = s_mp_add (a, b, c); | |
33 } else { | |
34 /* one positive, the other negative */ | |
35 /* subtract the one with the greater magnitude from */ | |
36 /* the one of the lesser magnitude. The result gets */ | |
37 /* the sign of the one with the greater magnitude. */ | |
38 if (mp_cmp_mag (a, b) == MP_LT) { | |
39 c->sign = sb; | |
40 res = s_mp_sub (b, a, c); | |
41 } else { | |
42 c->sign = sa; | 28 c->sign = sa; |
43 res = s_mp_sub (a, b, c); | 29 res = s_mp_add(a, b, c); |
44 } | 30 } else { |
45 } | 31 /* one positive, the other negative */ |
46 return res; | 32 /* subtract the one with the greater magnitude from */ |
33 /* the one of the lesser magnitude. The result gets */ | |
34 /* the sign of the one with the greater magnitude. */ | |
35 if (mp_cmp_mag(a, b) == MP_LT) { | |
36 c->sign = sb; | |
37 res = s_mp_sub(b, a, c); | |
38 } else { | |
39 c->sign = sa; | |
40 res = s_mp_sub(a, b, c); | |
41 } | |
42 } | |
43 return res; | |
47 } | 44 } |
48 | 45 |
49 #endif | 46 #endif |
50 | 47 |
51 /* ref: $Format:%D$ */ | 48 /* ref: HEAD -> master, tag: v1.1.0 */ |
52 /* git commit: $Format:%H$ */ | 49 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ |
53 /* commit time: $Format:%ai$ */ | 50 /* commit time: 2019-01-28 20:32:32 +0100 */ |