From 2296938608bd3f52aa8e580ab945eff411226c00 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sun, 3 Aug 2025 15:00:00 -0700 Subject: [PATCH] Eliminate function calls by declaring float arrays inline. --- src/lib/nano-nacl.ts | 52 ++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/src/lib/nano-nacl.ts b/src/lib/nano-nacl.ts index e16ea3a..9ec8ff3 100644 --- a/src/lib/nano-nacl.ts +++ b/src/lib/nano-nacl.ts @@ -24,12 +24,6 @@ export class NanoNaCl { static crypto_sign_PRIVATEKEYBYTES: 32 = 32 static crypto_sign_SEEDBYTES: 32 = 32 - static gf (init: number[] = []): Float64Array { - const r = new Float64Array(16) - r.set(init) - return r - } - static gf4 (): Float64Array[] { return [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)] } @@ -76,8 +70,8 @@ export class NanoNaCl { static pack25519 (o: Uint8Array, n: Float64Array): void { let b: number - const m: Float64Array = this.gf() - const t: Float64Array = this.gf() + const m: Float64Array = new Float64Array(16) + const t: Float64Array = new Float64Array(16) t.set(n.subarray(0, 16), 0) this.car25519(t) this.car25519(t) @@ -228,7 +222,7 @@ export class NanoNaCl { } static pow2523 (o: Float64Array, i: Float64Array): void { - const c: Float64Array = this.gf() + const c: Float64Array = new Float64Array(16) c.set(i.subarray(0, 16), 0) for (let a = 250; a >= 0; a--) { this.Square(c, c) @@ -240,15 +234,15 @@ export class NanoNaCl { } static add (p: Float64Array[], q: Float64Array[]): void { - const a: Float64Array = this.gf() - const b: Float64Array = this.gf() - const c: Float64Array = this.gf() - const d: Float64Array = this.gf() - const e: Float64Array = this.gf() - const f: Float64Array = this.gf() - const g: Float64Array = this.gf() - const h: Float64Array = this.gf() - const t: Float64Array = this.gf() + const a: Float64Array = new Float64Array(16) + const b: Float64Array = new Float64Array(16) + const c: Float64Array = new Float64Array(16) + const d: Float64Array = new Float64Array(16) + const e: Float64Array = new Float64Array(16) + const f: Float64Array = new Float64Array(16) + const g: Float64Array = new Float64Array(16) + const h: Float64Array = new Float64Array(16) + const t: Float64Array = new Float64Array(16) this.Subtract(a, p[1], p[0]) this.Subtract(t, q[1], q[0]) @@ -278,9 +272,9 @@ export class NanoNaCl { } static pack (r: Uint8Array, p: Float64Array[]): void { - const tx: Float64Array = this.gf() - const ty: Float64Array = this.gf() - const zi: Float64Array = this.gf() + const tx: Float64Array = new Float64Array(16) + const ty: Float64Array = new Float64Array(16) + const zi: Float64Array = new Float64Array(16) this.inv25519(zi, p[2]) this.Multiply(tx, p[0], zi) this.Multiply(ty, p[1], zi) @@ -384,13 +378,13 @@ export class NanoNaCl { } static unpackneg (r: Float64Array[], p: Uint8Array): -1 | 0 { - const t: Float64Array = this.gf() - const chk: Float64Array = this.gf() - const num: Float64Array = this.gf() - const den: Float64Array = this.gf() - const den2: Float64Array = this.gf() - const den4: Float64Array = this.gf() - const den6: Float64Array = this.gf() + const t: Float64Array = new Float64Array(16) + const chk: Float64Array = new Float64Array(16) + const num: Float64Array = new Float64Array(16) + const den: Float64Array = new Float64Array(16) + const den2: Float64Array = new Float64Array(16) + const den4: Float64Array = new Float64Array(16) + const den6: Float64Array = new Float64Array(16) r[2].fill(0).set([1], 0) this.unpack25519(r[1], p) @@ -421,7 +415,7 @@ export class NanoNaCl { if (this.neq25519(chk, num)) return -1 if (this.par25519(r[0]) === (p[31] >> 7)) { - this.Subtract(r[0], this.gf(), r[0]) + this.Subtract(r[0], new Float64Array(16), r[0]) } this.Multiply(r[3], r[0], r[1]) return 0 -- 2.47.3