annotate bn_mp_invmod_slow.c @ 163:8e94663164c6 libtommath LTM_DB_0.44

make pointers volatile so that memory zeroing won't get optimised away
author Matt Johnston <matt@ucc.asn.au>
date Sun, 02 Jan 2005 17:09:26 +0000
parents d29b64170cf0
children d8254fc979e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
142
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #include <tommath.h>
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 #ifdef BN_MP_INVMOD_SLOW_C
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 *
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 * LibTomMath is a library that provides multiple-precision
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 * integer arithmetic as well as number theoretic functionality.
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 *
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 * The library was designed directly after the MPI library by
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 * Michael Fromberger but has been written from scratch with
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 * additional optimizations in place.
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 *
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 * The library is free for all purposes without any express
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 * guarantee it works.
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 *
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 * Tom St Denis, [email protected], http://math.libtomcrypt.org
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 /* hac 14.61, pp608 */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c)
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 mp_int x, y, u, v, A, B, C, D;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 int res;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 /* b cannot be negative */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 if (b->sign == MP_NEG || mp_iszero(b) == 1) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 return MP_VAL;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 /* init temps */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 if ((res = mp_init_multi(&x, &y, &u, &v,
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 &A, &B, &C, &D, NULL)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 return res;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 /* x = a, y = b */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 if ((res = mp_copy (a, &x)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 if ((res = mp_copy (b, &y)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 /* 2. [modified] if x,y are both even then return an error! */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 if (mp_iseven (&x) == 1 && mp_iseven (&y) == 1) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 res = MP_VAL;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 if ((res = mp_copy (&x, &u)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 if ((res = mp_copy (&y, &v)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 mp_set (&A, 1);
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 mp_set (&D, 1);
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 top:
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 /* 4. while u is even do */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 while (mp_iseven (&u) == 1) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 /* 4.1 u = u/2 */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 /* 4.2 if A or B is odd then */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 if (mp_isodd (&A) == 1 || mp_isodd (&B) == 1) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 /* A = (A+y)/2, B = (B-x)/2 */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 if ((res = mp_add (&A, &y, &A)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 /* A = A/2, B = B/2 */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 if ((res = mp_div_2 (&A, &A)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 if ((res = mp_div_2 (&B, &B)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 /* 5. while v is even do */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 while (mp_iseven (&v) == 1) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 /* 5.1 v = v/2 */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 /* 5.2 if C or D is odd then */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 if (mp_isodd (&C) == 1 || mp_isodd (&D) == 1) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 /* C = (C+y)/2, D = (D-x)/2 */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 if ((res = mp_add (&C, &y, &C)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 /* C = C/2, D = D/2 */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102 if ((res = mp_div_2 (&C, &C)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 if ((res = mp_div_2 (&D, &D)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 /* 6. if u >= v then */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 if (mp_cmp (&u, &v) != MP_LT) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112 /* u = u - v, A = A - C, B = B - D */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 if ((res = mp_sub (&u, &v, &u)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117 if ((res = mp_sub (&A, &C, &A)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 } else {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 /* v - v - u, C = C - A, D = D - B */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 if ((res = mp_sub (&v, &u, &v)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130 if ((res = mp_sub (&C, &A, &C)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139 /* if not zero goto step 4 */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140 if (mp_iszero (&u) == 0)
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 goto top;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143 /* now a = C, b = D, gcd == g*v */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145 /* if v != 1 then there is no inverse */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146 if (mp_cmp_d (&v, 1) != MP_EQ) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147 res = MP_VAL;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 /* if its too low */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 while (mp_cmp_d(&C, 0) == MP_LT) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153 if ((res = mp_add(&C, b, &C)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
154 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158 /* too big */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159 while (mp_cmp_mag(&C, b) != MP_LT) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
160 if ((res = mp_sub(&C, b, &C)) != MP_OKAY) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 goto __ERR;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165 /* C is now the inverse */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166 mp_exch (&C, c);
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167 res = MP_OKAY;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168 __ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL);
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169 return res;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
170 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171 #endif