Mercurial > dropbear
comparison libtommath/bn_mp_gcd.c @ 435:337c45621e81
merge of 'a9b0496634cdd25647b65e585cc3240f3fa699ee'
and 'c22be8b8f570b48e9662dac32c7b3e7148a42206'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 22 Feb 2007 14:53:49 +0000 |
parents | 5ff8218bcee9 |
children | 60fc6476e044 |
comparison
equal
deleted
inserted
replaced
434:0aaaf68e97dc | 435:337c45621e81 |
---|---|
10 * additional optimizations in place. | 10 * additional optimizations in place. |
11 * | 11 * |
12 * The library is free for all purposes without any express | 12 * The library is free for all purposes without any express |
13 * guarantee it works. | 13 * guarantee it works. |
14 * | 14 * |
15 * Tom St Denis, [email protected], http://math.libtomcrypt.org | 15 * Tom St Denis, [email protected], http://math.libtomcrypt.com |
16 */ | 16 */ |
17 | 17 |
18 /* Greatest Common Divisor using the binary method */ | 18 /* Greatest Common Divisor using the binary method */ |
19 int mp_gcd (mp_int * a, mp_int * b, mp_int * c) | 19 int mp_gcd (mp_int * a, mp_int * b, mp_int * c) |
20 { | 20 { |
21 mp_int u, v; | 21 mp_int u, v; |
22 int k, u_lsb, v_lsb, res; | 22 int k, u_lsb, v_lsb, res; |
23 | 23 |
24 /* either zero than gcd is the largest */ | 24 /* either zero than gcd is the largest */ |
25 if (mp_iszero (a) == 1 && mp_iszero (b) == 0) { | 25 if (mp_iszero (a) == MP_YES) { |
26 return mp_abs (b, c); | 26 return mp_abs (b, c); |
27 } | 27 } |
28 if (mp_iszero (a) == 0 && mp_iszero (b) == 1) { | 28 if (mp_iszero (b) == MP_YES) { |
29 return mp_abs (a, c); | 29 return mp_abs (a, c); |
30 } | |
31 | |
32 /* optimized. At this point if a == 0 then | |
33 * b must equal zero too | |
34 */ | |
35 if (mp_iszero (a) == 1) { | |
36 mp_zero(c); | |
37 return MP_OKAY; | |
38 } | 30 } |
39 | 31 |
40 /* get copies of a and b we can modify */ | 32 /* get copies of a and b we can modify */ |
41 if ((res = mp_init_copy (&u, a)) != MP_OKAY) { | 33 if ((res = mp_init_copy (&u, a)) != MP_OKAY) { |
42 return res; | 34 return res; |
105 LBL_V:mp_clear (&u); | 97 LBL_V:mp_clear (&u); |
106 LBL_U:mp_clear (&v); | 98 LBL_U:mp_clear (&v); |
107 return res; | 99 return res; |
108 } | 100 } |
109 #endif | 101 #endif |
102 | |
103 /* $Source: /cvs/libtom/libtommath/bn_mp_gcd.c,v $ */ | |
104 /* $Revision: 1.4 $ */ | |
105 /* $Date: 2006/03/31 14:18:44 $ */ |