add special case
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user