From: Chris Duncan Date: Sun, 3 Aug 2025 22:01:33 +0000 (-0700) Subject: Eliminate another function call by declaring 4-element arrays of float arrays inline. X-Git-Tag: v0.10.5~46^2~25 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=c84f119ab5c35dcc826bab3f885ce6810e0c3315;p=libnemo.git Eliminate another function call by declaring 4-element arrays of float arrays inline. --- diff --git a/src/lib/nano-nacl.ts b/src/lib/nano-nacl.ts index 9ec8ff3..7c6b702 100644 --- a/src/lib/nano-nacl.ts +++ b/src/lib/nano-nacl.ts @@ -23,11 +23,6 @@ export class NanoNaCl { static crypto_sign_PUBLICKEYBYTES: 32 = 32 static crypto_sign_PRIVATEKEYBYTES: 32 = 32 static crypto_sign_SEEDBYTES: 32 = 32 - - static gf4 (): Float64Array[] { - return [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)] - } - static D: Float64Array = new Float64Array([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]) static D2: Float64Array = new Float64Array([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]) static X: Float64Array = new Float64Array([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]) @@ -35,7 +30,6 @@ export class NanoNaCl { static I: Float64Array = new Float64Array([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]) static XY: Float64Array = new Float64Array([0xdd90, 0xa5b7, 0x8ab3, 0x6dde, 0x52f5, 0x7751, 0x9f80, 0x20f0, 0xe37d, 0x64ab, 0x4e8e, 0x66ea, 0x7665, 0xd78b, 0x5f0f, 0xe787]) - static vn (x: Uint8Array, xi: number, y: Uint8Array, yi: number, n: number): number { let d = 0 for (let i = 0; i < n; i++) { @@ -297,7 +291,7 @@ export class NanoNaCl { } static scalarbase (p: Float64Array[], s: Uint8Array): void { - const q: Float64Array[] = this.gf4() + const q: Float64Array[] = [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)] q[0].set(this.X, 0) q[1].set(this.Y, 0) q[2].set([1], 0) @@ -347,7 +341,7 @@ export class NanoNaCl { } static crypto_sign (sm: Uint8Array, m: Uint8Array, n: number, sk: Uint8Array, pk: Uint8Array): void { - const p: Float64Array[] = this.gf4() + const p: Float64Array[] = [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)] const d = new Blake2b(64).update(sk).digest() d[0] &= 248 @@ -423,8 +417,8 @@ export class NanoNaCl { static crypto_sign_open (m: Uint8Array, sm: Uint8Array, n: number, pk: Uint8Array): number { const t = new Uint8Array(32) - const p: Float64Array[] = this.gf4() - const q: Float64Array[] = this.gf4() + const p: Float64Array[] = [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)] + const q: Float64Array[] = [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)] if (n < 64) return -1 @@ -484,7 +478,7 @@ export class NanoNaCl { throw new Error('Invalid seed size to convert to public key') } const pk = new Uint8Array(this.crypto_sign_PUBLICKEYBYTES) - const p: Float64Array[] = this.gf4() + const p: Float64Array[] = [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)] const hash = new Blake2b(64).update(s).digest() hash[0] &= 248