X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/5b295848664fa50612fb2df8aba58f29f9f74d63..HEAD:/math/mp-modsqrt.c diff --git a/math/mp-modsqrt.c b/math/mp-modsqrt.c index c5aed1fa..f7a74148 100644 --- a/math/mp-modsqrt.c +++ b/math/mp-modsqrt.c @@ -63,12 +63,18 @@ mp *mp_modsqrt(mp *d, mp *a, mp *p) mp *r, *A, *aa; mp *t; grand *gr; + int j; /* --- Cope if %$a \not\in Q_p$% --- */ - if (mp_jacobi(a, p) != 1) { + j = mp_jacobi(a, p); + if (j == -1) { mp_drop(d); return (0); + } else if (j == 0) { + if (d != a) mp_drop(d); + d = MP_COPY(a); + return (d); } /* --- Choose some quadratic non-residue --- */