comparison bn_mp_gcd.c @ 386:97db060d0ef5 libtommath-orig libtommath-0.40

Update to LibTomMath 0.40
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 03:11:15 +0000
parents 91fbc376f010
children
comparison
equal deleted inserted replaced
282:91fbc376f010 386:97db060d0ef5
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 $ */