Mercurial > dropbear
comparison libtommath/bn_mp_gcd.c @ 398:59c7938af2bd
merge of '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
and '7f8670ac3bb975f40967f3979d09d2199b7e90c8'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 03 Feb 2007 08:20:30 +0000 |
parents | 5ff8218bcee9 |
children | 60fc6476e044 |
comparison
equal
deleted
inserted
replaced
396:e7c1a77d2921 | 398:59c7938af2bd |
---|---|
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 $ */ |