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

index e16ea3aacd990ebe1e5bea859afde22486f965e1..9ec8ff3130aa0fb98bb2ba838d6616f1252a2fcd 100644 (file)
@@ -24,12 +24,6 @@ export class NanoNaCl {
        static crypto_sign_PRIVATEKEYBYTES: 32 = 32\r
        static crypto_sign_SEEDBYTES: 32 = 32\r
 \r
-       static gf (init: number[] = []): Float64Array {\r
-               const r = new Float64Array(16)\r
-               r.set(init)\r
-               return r\r
-       }\r
-\r
        static gf4 (): Float64Array[] {\r
                return [new Float64Array(16), new Float64Array(16), new Float64Array(16), new Float64Array(16)]\r
        }\r
@@ -76,8 +70,8 @@ export class NanoNaCl {
 \r
        static pack25519 (o: Uint8Array, n: Float64Array): void {\r
                let b: number\r
-               const m: Float64Array = this.gf()\r
-               const t: Float64Array = this.gf()\r
+               const m: Float64Array = new Float64Array(16)\r
+               const t: Float64Array = new Float64Array(16)\r
                t.set(n.subarray(0, 16), 0)\r
                this.car25519(t)\r
                this.car25519(t)\r
@@ -228,7 +222,7 @@ export class NanoNaCl {
        }\r
 \r
        static pow2523 (o: Float64Array, i: Float64Array): void {\r
-               const c: Float64Array = this.gf()\r
+               const c: Float64Array = new Float64Array(16)\r
                c.set(i.subarray(0, 16), 0)\r
                for (let a = 250; a >= 0; a--) {\r
                        this.Square(c, c)\r
@@ -240,15 +234,15 @@ export class NanoNaCl {
        }\r
 \r
        static add (p: Float64Array[], q: Float64Array[]): void {\r
-               const a: Float64Array = this.gf()\r
-               const b: Float64Array = this.gf()\r
-               const c: Float64Array = this.gf()\r
-               const d: Float64Array = this.gf()\r
-               const e: Float64Array = this.gf()\r
-               const f: Float64Array = this.gf()\r
-               const g: Float64Array = this.gf()\r
-               const h: Float64Array = this.gf()\r
-               const t: Float64Array = this.gf()\r
+               const a: Float64Array = new Float64Array(16)\r
+               const b: Float64Array = new Float64Array(16)\r
+               const c: Float64Array = new Float64Array(16)\r
+               const d: Float64Array = new Float64Array(16)\r
+               const e: Float64Array = new Float64Array(16)\r
+               const f: Float64Array = new Float64Array(16)\r
+               const g: Float64Array = new Float64Array(16)\r
+               const h: Float64Array = new Float64Array(16)\r
+               const t: Float64Array = new Float64Array(16)\r
 \r
                this.Subtract(a, p[1], p[0])\r
                this.Subtract(t, q[1], q[0])\r
@@ -278,9 +272,9 @@ export class NanoNaCl {
        }\r
 \r
        static pack (r: Uint8Array, p: Float64Array[]): void {\r
-               const tx: Float64Array = this.gf()\r
-               const ty: Float64Array = this.gf()\r
-               const zi: Float64Array = this.gf()\r
+               const tx: Float64Array = new Float64Array(16)\r
+               const ty: Float64Array = new Float64Array(16)\r
+               const zi: Float64Array = new Float64Array(16)\r
                this.inv25519(zi, p[2])\r
                this.Multiply(tx, p[0], zi)\r
                this.Multiply(ty, p[1], zi)\r
@@ -384,13 +378,13 @@ export class NanoNaCl {
        }\r
 \r
        static unpackneg (r: Float64Array[], p: Uint8Array): -1 | 0 {\r
-               const t: Float64Array = this.gf()\r
-               const chk: Float64Array = this.gf()\r
-               const num: Float64Array = this.gf()\r
-               const den: Float64Array = this.gf()\r
-               const den2: Float64Array = this.gf()\r
-               const den4: Float64Array = this.gf()\r
-               const den6: Float64Array = this.gf()\r
+               const t: Float64Array = new Float64Array(16)\r
+               const chk: Float64Array = new Float64Array(16)\r
+               const num: Float64Array = new Float64Array(16)\r
+               const den: Float64Array = new Float64Array(16)\r
+               const den2: Float64Array = new Float64Array(16)\r
+               const den4: Float64Array = new Float64Array(16)\r
+               const den6: Float64Array = new Float64Array(16)\r
 \r
                r[2].fill(0).set([1], 0)\r
                this.unpack25519(r[1], p)\r
@@ -421,7 +415,7 @@ export class NanoNaCl {
                if (this.neq25519(chk, num)) return -1\r
 \r
                if (this.par25519(r[0]) === (p[31] >> 7)) {\r
-                       this.Subtract(r[0], this.gf(), r[0])\r
+                       this.Subtract(r[0], new Float64Array(16), r[0])\r
                }\r
                this.Multiply(r[3], r[0], r[1])\r
                return 0\r