Mercurial > dropbear
comparison bn_mp_cmp_mag.c @ 1:22d5cf7d4b1a libtommath
Renaming branch
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 31 May 2004 18:23:46 +0000 |
parents | |
children | d29b64170cf0 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 1:22d5cf7d4b1a |
---|---|
1 /* LibTomMath, multiple-precision integer library -- Tom St Denis | |
2 * | |
3 * LibTomMath is a library that provides multiple-precision | |
4 * integer arithmetic as well as number theoretic functionality. | |
5 * | |
6 * The library was designed directly after the MPI library by | |
7 * Michael Fromberger but has been written from scratch with | |
8 * additional optimizations in place. | |
9 * | |
10 * The library is free for all purposes without any express | |
11 * guarantee it works. | |
12 * | |
13 * Tom St Denis, [email protected], http://math.libtomcrypt.org | |
14 */ | |
15 #include <tommath.h> | |
16 | |
17 /* compare maginitude of two ints (unsigned) */ | |
18 int mp_cmp_mag (mp_int * a, mp_int * b) | |
19 { | |
20 int n; | |
21 mp_digit *tmpa, *tmpb; | |
22 | |
23 /* compare based on # of non-zero digits */ | |
24 if (a->used > b->used) { | |
25 return MP_GT; | |
26 } | |
27 | |
28 if (a->used < b->used) { | |
29 return MP_LT; | |
30 } | |
31 | |
32 /* alias for a */ | |
33 tmpa = a->dp + (a->used - 1); | |
34 | |
35 /* alias for b */ | |
36 tmpb = b->dp + (a->used - 1); | |
37 | |
38 /* compare based on digits */ | |
39 for (n = 0; n < a->used; ++n, --tmpa, --tmpb) { | |
40 if (*tmpa > *tmpb) { | |
41 return MP_GT; | |
42 } | |
43 | |
44 if (*tmpa < *tmpb) { | |
45 return MP_LT; | |
46 } | |
47 } | |
48 return MP_EQ; | |
49 } |