Mercurial > dropbear
comparison libtommath/bn_mp_sub.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_SUB_C | 2 #ifdef BN_MP_SUB_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 subtraction (handles signs) */ | 15 /* high level subtraction (handles signs) */ |
19 int | 16 int mp_sub(const mp_int *a, const mp_int *b, mp_int *c) |
20 mp_sub (mp_int * a, mp_int * b, mp_int * c) | |
21 { | 17 { |
22 int sa, sb, res; | 18 int sa, sb, res; |
23 | 19 |
24 sa = a->sign; | 20 sa = a->sign; |
25 sb = b->sign; | 21 sb = b->sign; |
26 | 22 |
27 if (sa != sb) { | 23 if (sa != sb) { |
28 /* subtract a negative from a positive, OR */ | 24 /* subtract a negative from a positive, OR */ |
29 /* subtract a positive from a negative. */ | 25 /* subtract a positive from a negative. */ |
30 /* In either case, ADD their magnitudes, */ | 26 /* In either case, ADD their magnitudes, */ |
31 /* and use the sign of the first number. */ | 27 /* and use the sign of the first number. */ |
32 c->sign = sa; | |
33 res = s_mp_add (a, b, c); | |
34 } else { | |
35 /* subtract a positive from a positive, OR */ | |
36 /* subtract a negative from a negative. */ | |
37 /* First, take the difference between their */ | |
38 /* magnitudes, then... */ | |
39 if (mp_cmp_mag (a, b) != MP_LT) { | |
40 /* Copy the sign from the first */ | |
41 c->sign = sa; | 28 c->sign = sa; |
42 /* The first has a larger or equal magnitude */ | 29 res = s_mp_add(a, b, c); |
43 res = s_mp_sub (a, b, c); | 30 } else { |
44 } else { | 31 /* subtract a positive from a positive, OR */ |
45 /* The result has the *opposite* sign from */ | 32 /* subtract a negative from a negative. */ |
46 /* the first number. */ | 33 /* First, take the difference between their */ |
47 c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS; | 34 /* magnitudes, then... */ |
48 /* The second has a larger magnitude */ | 35 if (mp_cmp_mag(a, b) != MP_LT) { |
49 res = s_mp_sub (b, a, c); | 36 /* Copy the sign from the first */ |
50 } | 37 c->sign = sa; |
51 } | 38 /* The first has a larger or equal magnitude */ |
52 return res; | 39 res = s_mp_sub(a, b, c); |
40 } else { | |
41 /* The result has the *opposite* sign from */ | |
42 /* the first number. */ | |
43 c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS; | |
44 /* The second has a larger magnitude */ | |
45 res = s_mp_sub(b, a, c); | |
46 } | |
47 } | |
48 return res; | |
53 } | 49 } |
54 | 50 |
55 #endif | 51 #endif |
56 | 52 |
57 /* ref: $Format:%D$ */ | 53 /* ref: HEAD -> master, tag: v1.1.0 */ |
58 /* git commit: $Format:%H$ */ | 54 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ |
59 /* commit time: $Format:%ai$ */ | 55 /* commit time: 2019-01-28 20:32:32 +0100 */ |