]> git.codecow.com Git - libnemo.git/commitdiff
Eliminate another function call by declaring 4-element arrays of float arrays inline.
authorChris Duncan <chris@zoso.dev>
Sun, 3 Aug 2025 22:01:33 +0000 (15:01 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 3 Aug 2025 22:01:33 +0000 (15:01 -0700)
src/lib/nano-nacl.ts

index 9ec8ff3130aa0fb98bb2ba838d6616f1252a2fcd..7c6b70217fe71d1f631ca643e288168d59e9974b 100644 (file)
@@ -23,11 +23,6 @@ export class NanoNaCl {
        static crypto_sign_PUBLICKEYBYTES: 32 = 32\r
        static crypto_sign_PRIVATEKEYBYTES: 32 = 32\r
        static crypto_sign_SEEDBYTES: 32 = 32\r
-\r
-       static gf4 (): Float64Array[] {\r
-               return [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)]\r
-       }\r
-\r
        static D: Float64Array = new Float64Array([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203])\r
        static D2: Float64Array = new Float64Array([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406])\r
        static X: Float64Array = new Float64Array([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169])\r
@@ -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])\r
        static XY: Float64Array = new Float64Array([0xdd90, 0xa5b7, 0x8ab3, 0x6dde, 0x52f5, 0x7751, 0x9f80, 0x20f0, 0xe37d, 0x64ab, 0x4e8e, 0x66ea, 0x7665, 0xd78b, 0x5f0f, 0xe787])\r
 \r
-\r
        static vn (x: Uint8Array, xi: number, y: Uint8Array, yi: number, n: number): number {\r
                let d = 0\r
                for (let i = 0; i < n; i++) {\r
@@ -297,7 +291,7 @@ export class NanoNaCl {
        }\r
 \r
        static scalarbase (p: Float64Array[], s: Uint8Array): void {\r
-               const q: Float64Array[] = this.gf4()\r
+               const q: Float64Array[] = [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)]\r
                q[0].set(this.X, 0)\r
                q[1].set(this.Y, 0)\r
                q[2].set([1], 0)\r
@@ -347,7 +341,7 @@ export class NanoNaCl {
        }\r
 \r
        static crypto_sign (sm: Uint8Array, m: Uint8Array, n: number, sk: Uint8Array, pk: Uint8Array): void {\r
-               const p: Float64Array[] = this.gf4()\r
+               const p: Float64Array[] = [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)]\r
 \r
                const d = new Blake2b(64).update(sk).digest()\r
                d[0] &= 248\r
@@ -423,8 +417,8 @@ export class NanoNaCl {
 \r
        static crypto_sign_open (m: Uint8Array, sm: Uint8Array, n: number, pk: Uint8Array): number {\r
                const t = new Uint8Array(32)\r
-               const p: Float64Array[] = this.gf4()\r
-               const q: Float64Array[] = this.gf4()\r
+               const p: Float64Array[] = [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)]\r
+               const q: Float64Array[] = [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)]\r
 \r
                if (n < 64) return -1\r
 \r
@@ -484,7 +478,7 @@ export class NanoNaCl {
                                throw new Error('Invalid seed size to convert to public key')\r
                        }\r
                        const pk = new Uint8Array(this.crypto_sign_PUBLICKEYBYTES)\r
-                       const p: Float64Array[] = this.gf4()\r
+                       const p: Float64Array[] = [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)]\r
 \r
                        const hash = new Blake2b(64).update(s).digest()\r
                        hash[0] &= 248\r