Skip to content

Commit

Permalink
Improve math
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Jan 6, 2023
1 parent 73cf04e commit 3b72151
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,10 @@ function sqrtMod(x: bigint): bigint {
const b223 = (pow2(b220, _3n) * b3) % P;
const t1 = (pow2(b223, _23n) * b22) % P;
const t2 = (pow2(t1, _6n) * b2) % P;
return pow2(t2, _2n);
const rt = pow2(t2, _2n);
const xc = (rt * rt) % P;
if (xc !== x) throw new Error('Cannot find square root');
return rt;
}

// Inverses number over modulo
Expand Down

0 comments on commit 3b72151

Please sign in to comment.