add special case

This commit is contained in:
filifa 2025-12-11 23:49:34 -05:00
parent f38c0f5063
commit aa1399a574
1 changed files with 2 additions and 2 deletions

View File

@ -163,8 +163,6 @@ function modsqrt(n, modulus) {
throw new Error("modulus must be prime to compute square root");
}
// TODO: add special case for modulus = 3 (mod 4)
n %= modulus;
if (n < 0n) {
n += modulus;
@ -176,6 +174,8 @@ function modsqrt(n, modulus) {
throw new Error("radicand is not a quadratic residue of the modulus");
} else if (modulus === 2n) {
return n % 2n;
} else if (modulus % 4n === 3n) {
return modpow(n, (modulus+1n)/4n, modulus);
}
return tonelliShanks(n, modulus);