diff --git a/modules/math.js b/modules/math.js index b3bbfcb..4add6a1 100644 --- a/modules/math.js +++ b/modules/math.js @@ -170,10 +170,10 @@ function modsqrt(n, modulus) { if (n % modulus === 0n) { return 0n; - } else if (legendreSymbol(n, modulus) !== 1n) { - throw new Error("radicand is not a quadratic residue of the modulus"); } else if (modulus === 2n) { return n % 2n; + } else if (legendreSymbol(n, modulus) !== 1n) { + throw new Error("radicand is not a quadratic residue of the modulus"); } else if (modulus % 4n === 3n) { return modpow(n, (modulus+1n)/4n, modulus); }