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