summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_exteuclid.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-18 08:31:55 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-18 08:31:55 (GMT)
commita187f65cfd5964971d7ed52f09e18fdbb4bf51cc (patch)
tree6b7bbde03122d1571d4543d10eccfe88610bd680 /libtommath/bn_mp_exteuclid.c
parent0faaca01de4e9fa2039c7fdd34f60b138f665249 (diff)
parent30f7e69b182d1267056ee2628a860891f6555aa3 (diff)
downloadtcl-a187f65cfd5964971d7ed52f09e18fdbb4bf51cc.zip
tcl-a187f65cfd5964971d7ed52f09e18fdbb4bf51cc.tar.gz
tcl-a187f65cfd5964971d7ed52f09e18fdbb4bf51cc.tar.bz2
Merge libtommath upstream changes (astyle formatting only). No functional changes. All Tcl-specific modifications are kept.
Diffstat (limited to 'libtommath/bn_mp_exteuclid.c')
-rw-r--r--libtommath/bn_mp_exteuclid.c92
1 files changed, 67 insertions, 25 deletions
diff --git a/libtommath/bn_mp_exteuclid.c b/libtommath/bn_mp_exteuclid.c
index 3c9612e..419146b 100644
--- a/libtommath/bn_mp_exteuclid.c
+++ b/libtommath/bn_mp_exteuclid.c
@@ -29,47 +29,89 @@ int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3)
/* initialize, (u1,u2,u3) = (1,0,a) */
mp_set(&u1, 1);
- if ((err = mp_copy(a, &u3)) != MP_OKAY) { goto LBL_ERR; }
+ if ((err = mp_copy(a, &u3)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
/* initialize, (v1,v2,v3) = (0,1,b) */
mp_set(&v2, 1);
- if ((err = mp_copy(b, &v3)) != MP_OKAY) { goto LBL_ERR; }
+ if ((err = mp_copy(b, &v3)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
/* loop while v3 != 0 */
while (mp_iszero(&v3) == MP_NO) {
- /* q = u3/v3 */
- if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY) { goto LBL_ERR; }
+ /* q = u3/v3 */
+ if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
- /* (t1,t2,t3) = (u1,u2,u3) - (v1,v2,v3)q */
- if ((err = mp_mul(&v1, &q, &tmp)) != MP_OKAY) { goto LBL_ERR; }
- if ((err = mp_sub(&u1, &tmp, &t1)) != MP_OKAY) { goto LBL_ERR; }
- if ((err = mp_mul(&v2, &q, &tmp)) != MP_OKAY) { goto LBL_ERR; }
- if ((err = mp_sub(&u2, &tmp, &t2)) != MP_OKAY) { goto LBL_ERR; }
- if ((err = mp_mul(&v3, &q, &tmp)) != MP_OKAY) { goto LBL_ERR; }
- if ((err = mp_sub(&u3, &tmp, &t3)) != MP_OKAY) { goto LBL_ERR; }
+ /* (t1,t2,t3) = (u1,u2,u3) - (v1,v2,v3)q */
+ if ((err = mp_mul(&v1, &q, &tmp)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ if ((err = mp_sub(&u1, &tmp, &t1)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ if ((err = mp_mul(&v2, &q, &tmp)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ if ((err = mp_sub(&u2, &tmp, &t2)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ if ((err = mp_mul(&v3, &q, &tmp)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ if ((err = mp_sub(&u3, &tmp, &t3)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
- /* (u1,u2,u3) = (v1,v2,v3) */
- if ((err = mp_copy(&v1, &u1)) != MP_OKAY) { goto LBL_ERR; }
- if ((err = mp_copy(&v2, &u2)) != MP_OKAY) { goto LBL_ERR; }
- if ((err = mp_copy(&v3, &u3)) != MP_OKAY) { goto LBL_ERR; }
+ /* (u1,u2,u3) = (v1,v2,v3) */
+ if ((err = mp_copy(&v1, &u1)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ if ((err = mp_copy(&v2, &u2)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ if ((err = mp_copy(&v3, &u3)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
- /* (v1,v2,v3) = (t1,t2,t3) */
- if ((err = mp_copy(&t1, &v1)) != MP_OKAY) { goto LBL_ERR; }
- if ((err = mp_copy(&t2, &v2)) != MP_OKAY) { goto LBL_ERR; }
- if ((err = mp_copy(&t3, &v3)) != MP_OKAY) { goto LBL_ERR; }
+ /* (v1,v2,v3) = (t1,t2,t3) */
+ if ((err = mp_copy(&t1, &v1)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ if ((err = mp_copy(&t2, &v2)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ if ((err = mp_copy(&t3, &v3)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
}
/* make sure U3 >= 0 */
if (u3.sign == MP_NEG) {
- if ((err = mp_neg(&u1, &u1)) != MP_OKAY) { goto LBL_ERR; }
- if ((err = mp_neg(&u2, &u2)) != MP_OKAY) { goto LBL_ERR; }
- if ((err = mp_neg(&u3, &u3)) != MP_OKAY) { goto LBL_ERR; }
+ if ((err = mp_neg(&u1, &u1)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ if ((err = mp_neg(&u2, &u2)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ if ((err = mp_neg(&u3, &u3)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
}
/* copy result out */
- if (U1 != NULL) { mp_exch(U1, &u1); }
- if (U2 != NULL) { mp_exch(U2, &u2); }
- if (U3 != NULL) { mp_exch(U3, &u3); }
+ if (U1 != NULL) {
+ mp_exch(U1, &u1);
+ }
+ if (U2 != NULL) {
+ mp_exch(U2, &u2);
+ }
+ if (U3 != NULL) {
+ mp_exch(U3, &u3);
+ }
err = MP_OKAY;
LBL_ERR: