From: Chris Duncan Date: Sun, 3 Aug 2025 09:05:15 +0000 (-0700) Subject: Expand operation function names for clarity over brevity. X-Git-Tag: v0.10.5~46^2~32 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=09e350c9ccc4dfc40445fb0098d822bcd1ababd5;p=libnemo.git Expand operation function names for clarity over brevity. --- diff --git a/src/lib/nano-nacl.ts b/src/lib/nano-nacl.ts index 5cad828..789f52a 100644 --- a/src/lib/nano-nacl.ts +++ b/src/lib/nano-nacl.ts @@ -126,19 +126,19 @@ export class NanoNaCl { o[15] &= (1 << 15) - 1 } - static A (o: Float64Array, a: Float64Array, b: Float64Array): void { + static Add (o: Float64Array, a: Float64Array, b: Float64Array): void { for (let i = 0; i < 16; i++) { o[i] = a[i] + b[i] } } - static Z (o: Float64Array, a: Float64Array, b: Float64Array): void { + static Subtract (o: Float64Array, a: Float64Array, b: Float64Array): void { for (let i = 0; i < 16; i++) { o[i] = a[i] - b[i] } } - static M (o: Float64Array, a: Float64Array, b: Float64Array): void { + static Multiply (o: Float64Array, a: Float64Array, b: Float64Array): void { let v, c, s = 1 << 16 const t = new Array(31) t.fill(0) @@ -177,17 +177,17 @@ export class NanoNaCl { o.set(t.slice(0, 16), 0) } - static S (o: Float64Array, a: Float64Array): void { - this.M(o, a, a) + static Square (o: Float64Array, a: Float64Array): void { + this.Multiply(o, a, a) } static inv25519 (o: Float64Array, i: Float64Array): void { const c: Float64Array = new Float64Array(16) c.set(i.subarray(0, 16), 0) for (let a = 253; a >= 0; a--) { - this.S(c, c) + this.Square(c, c) if (a !== 2 && a !== 4) { - this.M(c, c, i) + this.Multiply(c, c, i) } } o.set(c, 0) @@ -197,9 +197,9 @@ export class NanoNaCl { const c: Float64Array = this.gf() c.set(i.subarray(0, 16), 0) for (let a = 250; a >= 0; a--) { - this.S(c, c) + this.Square(c, c) if (a !== 1) { - this.M(c, c, i) + this.Multiply(c, c, i) } } o.set(c, 0) @@ -216,25 +216,25 @@ export class NanoNaCl { const h: Float64Array = this.gf() const t: Float64Array = this.gf() - this.Z(a, p[1], p[0]) - this.Z(t, q[1], q[0]) - this.M(a, a, t) - this.A(b, p[0], p[1]) - this.A(t, q[0], q[1]) - this.M(b, b, t) - this.M(c, p[3], q[3]) - this.M(c, c, this.D2) - this.M(d, p[2], q[2]) - this.A(d, d, d) - this.Z(e, b, a) - this.Z(f, d, c) - this.A(g, d, c) - this.A(h, b, a) - - this.M(p[0], e, f) - this.M(p[1], h, g) - this.M(p[2], g, f) - this.M(p[3], e, h) + this.Subtract(a, p[1], p[0]) + this.Subtract(t, q[1], q[0]) + this.Multiply(a, a, t) + this.Add(b, p[0], p[1]) + this.Add(t, q[0], q[1]) + this.Multiply(b, b, t) + this.Multiply(c, p[3], q[3]) + this.Multiply(c, c, this.D2) + this.Multiply(d, p[2], q[2]) + this.Add(d, d, d) + this.Subtract(e, b, a) + this.Subtract(f, d, c) + this.Add(g, d, c) + this.Add(h, b, a) + + this.Multiply(p[0], e, f) + this.Multiply(p[1], h, g) + this.Multiply(p[2], g, f) + this.Multiply(p[3], e, h) } static cswap (p: Float64Array[], q: Float64Array[], b: number): void { @@ -248,8 +248,8 @@ export class NanoNaCl { const ty: Float64Array = this.gf() const zi: Float64Array = this.gf() this.inv25519(zi, p[2]) - this.M(tx, p[0], zi) - this.M(ty, p[1], zi) + this.Multiply(tx, p[0], zi) + this.Multiply(ty, p[1], zi) this.pack25519(r, ty) r[31] ^= this.par25519(tx) << 7 } @@ -360,34 +360,34 @@ export class NanoNaCl { this.set25519(r[2], this.gf([1])) this.unpack25519(r[1], p) - this.S(num, r[1]) - this.M(den, num, this.D) - this.Z(num, num, r[2]) - this.A(den, r[2], den) + this.Square(num, r[1]) + this.Multiply(den, num, this.D) + this.Subtract(num, num, r[2]) + this.Add(den, r[2], den) - this.S(den2, den) - this.S(den4, den2) - this.M(den6, den4, den2) - this.M(t, den6, num) - this.M(t, t, den) + this.Square(den2, den) + this.Square(den4, den2) + this.Multiply(den6, den4, den2) + this.Multiply(t, den6, num) + this.Multiply(t, t, den) this.pow2523(t, t) - this.M(t, t, num) - this.M(t, t, den) - this.M(t, t, den) - this.M(r[0], t, den) + this.Multiply(t, t, num) + this.Multiply(t, t, den) + this.Multiply(t, t, den) + this.Multiply(r[0], t, den) - this.S(chk, r[0]) - this.M(chk, chk, den) - if (this.neq25519(chk, num)) this.M(r[0], r[0], this.I) + this.Square(chk, r[0]) + this.Multiply(chk, chk, den) + if (this.neq25519(chk, num)) this.Multiply(r[0], r[0], this.I) - this.S(chk, r[0]) - this.M(chk, chk, den) + this.Square(chk, r[0]) + this.Multiply(chk, chk, den) if (this.neq25519(chk, num)) return -1 - if (this.par25519(r[0]) === (p[31] >> 7)) this.Z(r[0], this.gf(), r[0]) - this.M(r[3], r[0], r[1]) + if (this.par25519(r[0]) === (p[31] >> 7)) this.Subtract(r[0], this.gf(), r[0]) + this.Multiply(r[3], r[0], r[1]) return 0 }