From: Mark Wooding Date: Fri, 27 Dec 2013 12:00:53 +0000 (+0000) Subject: math/mp-gcd.c: Avoid clobbering constants during the sign fixup. X-Git-Tag: 2.1.6~3 X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/commitdiff_plain/9b8ff1cfc6305fc32614c20a00c168e9a268c949 math/mp-gcd.c: Avoid clobbering constants during the sign fixup. If the GCD computation was trivial, then the state still contains references to the constants `MP_ZERO' and `MP_ONE'. It would be Really Bad to trash their signs -- in particular, this causes comparisons with `MP_ONE' to fail, leading to an assertion failure from `mp_modinv'. --- diff --git a/math/mp-gcd.c b/math/mp-gcd.c index 6e059e30..c36689ca 100644 --- a/math/mp-gcd.c +++ b/math/mp-gcd.c @@ -199,10 +199,8 @@ void mp_gcd(mp **gcd, mp **xx, mp **yy, mp *a, mp *b) /* --- Twiddle the signs --- */ - if (f & f_aneg) - x->f ^= MP_NEG; - if (f & f_bneg) - y->f ^= MP_NEG; + if (f & f_aneg) { MP_SPLIT(x); x->f ^= MP_NEG; } + if (f & f_bneg) { MP_SPLIT(y); y->f ^= MP_NEG; } /* --- Store the results --- */ diff --git a/math/t/mp b/math/t/mp index fe74f073..7dae5526 100644 --- a/math/t/mp +++ b/math/t/mp @@ -199,6 +199,7 @@ modinv { 5 9 2; 15 64 47; 564566436 546457643 408896426; + -1 257 -1; } jacobi {