Mercurial > dropbear
comparison bn_mp_jacobi.c @ 190:d8254fc979e9 libtommath-orig LTM_0.35
Initial import of libtommath 0.35
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 06 May 2005 08:59:30 +0000 |
parents | d29b64170cf0 |
children |
comparison
equal
deleted
inserted
replaced
142:d29b64170cf0 | 190:d8254fc979e9 |
---|---|
48 if ((res = mp_init_copy (&a1, a)) != MP_OKAY) { | 48 if ((res = mp_init_copy (&a1, a)) != MP_OKAY) { |
49 return res; | 49 return res; |
50 } | 50 } |
51 | 51 |
52 if ((res = mp_init (&p1)) != MP_OKAY) { | 52 if ((res = mp_init (&p1)) != MP_OKAY) { |
53 goto __A1; | 53 goto LBL_A1; |
54 } | 54 } |
55 | 55 |
56 /* divide out larger power of two */ | 56 /* divide out larger power of two */ |
57 k = mp_cnt_lsb(&a1); | 57 k = mp_cnt_lsb(&a1); |
58 if ((res = mp_div_2d(&a1, k, &a1, NULL)) != MP_OKAY) { | 58 if ((res = mp_div_2d(&a1, k, &a1, NULL)) != MP_OKAY) { |
59 goto __P1; | 59 goto LBL_P1; |
60 } | 60 } |
61 | 61 |
62 /* step 4. if e is even set s=1 */ | 62 /* step 4. if e is even set s=1 */ |
63 if ((k & 1) == 0) { | 63 if ((k & 1) == 0) { |
64 s = 1; | 64 s = 1; |
82 if (mp_cmp_d (&a1, 1) == MP_EQ) { | 82 if (mp_cmp_d (&a1, 1) == MP_EQ) { |
83 *c = s; | 83 *c = s; |
84 } else { | 84 } else { |
85 /* n1 = n mod a1 */ | 85 /* n1 = n mod a1 */ |
86 if ((res = mp_mod (p, &a1, &p1)) != MP_OKAY) { | 86 if ((res = mp_mod (p, &a1, &p1)) != MP_OKAY) { |
87 goto __P1; | 87 goto LBL_P1; |
88 } | 88 } |
89 if ((res = mp_jacobi (&p1, &a1, &r)) != MP_OKAY) { | 89 if ((res = mp_jacobi (&p1, &a1, &r)) != MP_OKAY) { |
90 goto __P1; | 90 goto LBL_P1; |
91 } | 91 } |
92 *c = s * r; | 92 *c = s * r; |
93 } | 93 } |
94 | 94 |
95 /* done */ | 95 /* done */ |
96 res = MP_OKAY; | 96 res = MP_OKAY; |
97 __P1:mp_clear (&p1); | 97 LBL_P1:mp_clear (&p1); |
98 __A1:mp_clear (&a1); | 98 LBL_A1:mp_clear (&a1); |
99 return res; | 99 return res; |
100 } | 100 } |
101 #endif | 101 #endif |