comparison libtommath/bn_mp_gcd.c @ 511:582cb38e4eb5 insecure-nocrypto

propagate from branch 'au.asn.ucc.matt.dropbear' (head cdcc3c729e29544e8b98a408e2dc60e4483dfd2a) to branch 'au.asn.ucc.matt.dropbear.insecure-nocrypto' (head 0ca38a1cf349f7426ac9de34ebe4c3e3735effab)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 06 Nov 2008 13:16:55 +0000
parents 5ff8218bcee9
children 60fc6476e044
comparison
equal deleted inserted replaced
361:461c4b1fb35f 511:582cb38e4eb5
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 $ */