comparison libtommath/bn_mp_cmp_mag.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_CMP_MAG_C 2 #ifdef BN_MP_CMP_MAG_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 /* compare maginitude of two ints (unsigned) */ 15 /* compare maginitude of two ints (unsigned) */
19 int mp_cmp_mag (mp_int * a, mp_int * b) 16 int mp_cmp_mag(const mp_int *a, const mp_int *b)
20 { 17 {
21 int n; 18 int n;
22 mp_digit *tmpa, *tmpb; 19 mp_digit *tmpa, *tmpb;
23 20
24 /* compare based on # of non-zero digits */ 21 /* compare based on # of non-zero digits */
25 if (a->used > b->used) { 22 if (a->used > b->used) {
26 return MP_GT; 23 return MP_GT;
27 } 24 }
28
29 if (a->used < b->used) {
30 return MP_LT;
31 }
32 25
33 /* alias for a */ 26 if (a->used < b->used) {
34 tmpa = a->dp + (a->used - 1); 27 return MP_LT;
28 }
35 29
36 /* alias for b */ 30 /* alias for a */
37 tmpb = b->dp + (a->used - 1); 31 tmpa = a->dp + (a->used - 1);
38 32
39 /* compare based on digits */ 33 /* alias for b */
40 for (n = 0; n < a->used; ++n, --tmpa, --tmpb) { 34 tmpb = b->dp + (a->used - 1);
41 if (*tmpa > *tmpb) {
42 return MP_GT;
43 }
44 35
45 if (*tmpa < *tmpb) { 36 /* compare based on digits */
46 return MP_LT; 37 for (n = 0; n < a->used; ++n, --tmpa, --tmpb) {
47 } 38 if (*tmpa > *tmpb) {
48 } 39 return MP_GT;
49 return MP_EQ; 40 }
41
42 if (*tmpa < *tmpb) {
43 return MP_LT;
44 }
45 }
46 return MP_EQ;
50 } 47 }
51 #endif 48 #endif
52 49
53 /* ref: $Format:%D$ */ 50 /* ref: HEAD -> master, tag: v1.1.0 */
54 /* git commit: $Format:%H$ */ 51 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
55 /* commit time: $Format:%ai$ */ 52 /* commit time: 2019-01-28 20:32:32 +0100 */