return r >= 0n ? r : p + r
}
- /** Modular inversion using eucledian GCD (non-CT). No negative exponent for now. */
- // prettier-ignore
+ /**
+ * Modular inversion using euclidean GCD (non-constant-time).
+ * No negative exponent for now.
+ */
static invert (num: bigint): bigint {
- if (num === 0n || this.P <= 0n) this.err('no inverse n=' + num + ' mod=' + this.P)
+ if (num === 0n || this.P <= 0n) this.err(`no inverse n=${num} mod=${this.P}`)
let a = this.M(num), b = this.P, x = 0n, y = 1n, u = 1n, v = 0n
while (a !== 0n) {
const q = b / a, r = b % a
}
// ## End of Helpers
- // -----------------
/** secp256k1 formula. Koblitz curves are subclass of weierstrass curves with a=0, making it x³+b */
static koblitz = (x: bigint): bigint => this.M(this.M(x * x) * x + this.b)