]> git.codecow.com Git - libnemo.git/commitdiff
Revert nacl to floats now that I understand the algorithm a little better.
authorChris Duncan <chris@zoso.dev>
Sun, 17 Aug 2025 07:36:47 +0000 (00:36 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 17 Aug 2025 07:36:47 +0000 (00:36 -0700)
src/lib/crypto/nano-nacl.ts

index 04c17f9bd77ff21d1965f725652471109e098b32..0649861df7e6c97ec1fc2ec8c33fc8218927eb59 100644 (file)
@@ -19,12 +19,12 @@ export class NanoNaCl {
        static crypto_sign_PUBLICKEYBYTES: 32 = 32\r
        static crypto_sign_PRIVATEKEYBYTES: 32 = 32\r
        static crypto_sign_SEEDBYTES: 32 = 32\r
-       static D: BigInt64Array = new BigInt64Array([0x78a3n, 0x1359n, 0x4dcan, 0x75ebn, 0xd8abn, 0x4141n, 0x0a4dn, 0x0070n, 0xe898n, 0x7779n, 0x4079n, 0x8cc7n, 0xfe73n, 0x2b6fn, 0x6ceen, 0x5203n])\r
-       static D2: BigInt64Array = new BigInt64Array([0xf159n, 0x26b2n, 0x9b94n, 0xebd6n, 0xb156n, 0x8283n, 0x149an, 0x00e0n, 0xd130n, 0xeef3n, 0x80f2n, 0x198en, 0xfce7n, 0x56dfn, 0xd9dcn, 0x2406n])\r
-       static X: BigInt64Array = new BigInt64Array([0xd51an, 0x8f25n, 0x2d60n, 0xc956n, 0xa7b2n, 0x9525n, 0xc760n, 0x692cn, 0xdc5cn, 0xfdd6n, 0xe231n, 0xc0a4n, 0x53fen, 0xcd6en, 0x36d3n, 0x2169n])\r
-       static Y: BigInt64Array = new BigInt64Array([0x6658n, 0x6666n, 0x6666n, 0x6666n, 0x6666n, 0x6666n, 0x6666n, 0x6666n, 0x6666n, 0x6666n, 0x6666n, 0x6666n, 0x6666n, 0x6666n, 0x6666n, 0x6666n])\r
-       static I: BigInt64Array = new BigInt64Array([0xa0b0n, 0x4a0en, 0x1b27n, 0xc4een, 0xe478n, 0xad2fn, 0x1806n, 0x2f43n, 0xd7a7n, 0x3dfbn, 0x0099n, 0x2b4dn, 0xdf0bn, 0x4fc1n, 0x2480n, 0x2b83n])\r
-       static XY: BigInt64Array = new BigInt64Array([0xdd90n, 0xa5b7n, 0x8ab3n, 0x6dden, 0x52f5n, 0x7751n, 0x9f80n, 0x20f0n, 0xe37dn, 0x64abn, 0x4e8en, 0x66ean, 0x7665n, 0xd78bn, 0x5f0fn, 0xe787n])\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
+       static Y: Float64Array = new Float64Array([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666])\r
+       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
        static #vn (x: Uint8Array, xi: number, y: Uint8Array, yi: number, n: number): number {\r
                let d: number = 0\r
@@ -34,8 +34,8 @@ export class NanoNaCl {
                return (1 & ((d - 1) >>> 8)) - 1\r
        }\r
 \r
-       static pow2523 (out: BigInt64Array, i: BigInt64Array): void {\r
-               const c: BigInt64Array = new BigInt64Array(16)\r
+       static pow2523 (out: Float64Array, i: Float64Array): void {\r
+               const c: Float64Array = new Float64Array(16)\r
                c.set(i.subarray(0, 16), 0)\r
                for (let a = 0; a < 249; a++) {\r
                        this.Square(c, c)\r
@@ -47,20 +47,20 @@ export class NanoNaCl {
                out.set(c, 0)\r
        }\r
 \r
-       static car25519 (out: BigInt64Array): void {\r
-               let v: bigint, c: bigint\r
-               const s: bigint = 1n << 16n\r
-               c = 0n\r
+       static car25519 (out: Float64Array): void {\r
+               let v, c\r
+               const s = 1 << 16\r
+               c = 0\r
                for (let i = 0; i < 16; i++) {\r
                        v = out[i] + c + s\r
                        out[i] = v % s\r
-                       c = v / s - 1n\r
+                       c = (v / s - 1) | 0\r
                }\r
-               out[0] += 38n * c\r
+               out[0] += 38 * c\r
        }\r
 \r
-       static inv25519 (out: BigInt64Array, i: BigInt64Array): void {\r
-               const c: BigInt64Array = new BigInt64Array(16)\r
+       static inv25519 (out: Float64Array, i: Float64Array): void {\r
+               const c: Float64Array = new Float64Array(16)\r
                c.set(i.subarray(0, 16), 0)\r
                for (let a = 253; a >= 0; a--) {\r
                        this.Square(c, c)\r
@@ -71,7 +71,7 @@ export class NanoNaCl {
                out.set(c, 0)\r
        }\r
 \r
-       static neq25519 (a: BigInt64Array, b: BigInt64Array): number {\r
+       static neq25519 (a: Float64Array, b: Float64Array): number {\r
                const c: Uint8Array = new Uint8Array(32)\r
                const d: Uint8Array = new Uint8Array(32)\r
                this.pack25519(c, a)\r
@@ -79,40 +79,40 @@ export class NanoNaCl {
                return this.#vn(c, 0, d, 0, 32)\r
        }\r
 \r
-       static pack25519 (out: Uint8Array, n: BigInt64Array): void {\r
-               let b: bigint\r
-               const m: BigInt64Array = new BigInt64Array(16)\r
-               const t: BigInt64Array = new BigInt64Array(16)\r
+       static pack25519 (out: Uint8Array, n: Float64Array): void {\r
+               let b: number\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
                this.car25519(t)\r
                for (let j = 0; j < 2; j++) {\r
-                       m[0] = t[0] - 0xffedn\r
+                       m[0] = t[0] - 0xffed\r
                        for (let i = 1; i < 15; i++) {\r
-                               m[i] = t[i] - 0xffffn - ((m[i - 1] >> 16n) & 1n)\r
-                               m[i - 1] &= 0xffffn\r
+                               m[i] = t[i] - 0xffff - ((m[i - 1] >> 16) & 1)\r
+                               m[i - 1] &= 0xffff\r
                        }\r
-                       m[15] = t[15] - 0x7fffn - ((m[14] >> 16n) & 1n)\r
-                       b = (m[15] >> 16n) & 1n\r
-                       m[14] &= 0xffffn\r
-                       this.sel25519(t, m, 1n - b)\r
+                       m[15] = t[15] - 0x7fff - ((m[14] >> 16) & 1)\r
+                       b = (m[15] >> 16) & 1\r
+                       m[14] &= 0xffff\r
+                       this.sel25519(t, m, 1 - b)\r
                }\r
                for (let i = 0; i < 16; i++) {\r
-                       out[2 * i] = Number(t[i] & 0xffn)\r
-                       out[2 * i + 1] = Number(t[i] >> 8n)\r
+                       out[2 * i] = t[i] & 0xff\r
+                       out[2 * i + 1] = t[i] >> 8\r
                }\r
        }\r
 \r
-       static par25519 (a: BigInt64Array): number {\r
+       static par25519 (a: Float64Array): number {\r
                const d: Uint8Array = new Uint8Array(32)\r
                this.pack25519(d, a)\r
                return d[0] & 1\r
        }\r
 \r
-       static sel25519 (p: BigInt64Array, q: BigInt64Array, b: bigint): void {\r
-               let t: bigint\r
-               const c: bigint = ~(b - 1n)\r
+       static sel25519 (p: Float64Array, q: Float64Array, b: number): void {\r
+               let t\r
+               const c = ~(b - 1)\r
                for (let i = 0; i < 16; i++) {\r
                        t = c & (p[i] ^ q[i])\r
                        p[i] ^= t\r
@@ -120,30 +120,30 @@ export class NanoNaCl {
                }\r
        }\r
 \r
-       static unpack25519 (out: BigInt64Array, n: Uint8Array): void {\r
+       static unpack25519 (out: Float64Array, n: Uint8Array): void {\r
                for (let i = 0; i < 16; i++) {\r
-                       out[i] = BigInt(n[2 * i]) + (BigInt(n[2 * i + 1]) << 8n)\r
+                       out[i] = n[2 * i] + (n[2 * i + 1] << 8)\r
                }\r
-               out[15] &= (1n << 15n) - 1n\r
+               out[15] &= (1 << 15) - 1\r
        }\r
 \r
-       static Add (out: BigInt64Array, a: BigInt64Array, b: BigInt64Array): void {\r
+       static Add (out: Float64Array, a: Float64Array, b: Float64Array): void {\r
                for (let i = 0; i < 16; i++) {\r
                        out[i] = a[i] + b[i]\r
                }\r
        }\r
 \r
-       static Subtract (out: BigInt64Array, a: BigInt64Array, b: BigInt64Array): void {\r
+       static Subtract (out: Float64Array, a: Float64Array, b: Float64Array): void {\r
                for (let i = 0; i < 16; i++) {\r
                        out[i] = a[i] - b[i]\r
                }\r
        }\r
 \r
-       static Multiply (out: BigInt64Array, a: BigInt64Array, b: BigInt64Array): void {\r
-               let v: bigint, c: bigint\r
-               const s: bigint = 1n << 16n\r
-               const t: BigInt64Array = new BigInt64Array(31)\r
-               t.fill(0n)\r
+       static Multiply (out: Float64Array, a: Float64Array, b: Float64Array): void {\r
+               let v, c\r
+               const s = 1 << 16\r
+               const t = new Float64Array(31)\r
+               t.fill(0)\r
 \r
                // init t values\r
                for (let i = 0; i < 16; i++) {\r
@@ -153,83 +153,83 @@ export class NanoNaCl {
                }\r
 \r
                for (let i = 0; i < 15; i++) {\r
-                       t[i] += 38n * t[i + 16]\r
+                       t[i] += 38 * t[i + 16]\r
                }\r
                // t15 left as is\r
 \r
                // first carry\r
-               c = 0n\r
+               c = 0\r
                for (let i = 0; i < 16; i++) {\r
                        v = t[i] + c\r
                        t[i] = v % s\r
-                       c = v / s\r
+                       c = (v / s) | 0\r
                }\r
-               t[0] += 38n * c\r
+               t[0] += 38 * c\r
 \r
                // second carry\r
-               c = 0n\r
+               c = 0\r
                for (let i = 0; i < 16; i++) {\r
                        v = t[i] + c\r
                        t[i] = v % s\r
-                       c = v / s\r
+                       c = (v / s) | 0\r
                }\r
-               t[0] += 38n * c\r
+               t[0] += 38 * c\r
 \r
                // assign result to output\r
                out.set(t.slice(0, 16), 0)\r
        }\r
 \r
-       static Square (out: BigInt64Array, a: BigInt64Array): void {\r
-               let v: bigint, c: bigint\r
-               const s: bigint = 1n << 16n\r
-               const t: BigInt64Array = new BigInt64Array(31)\r
-               t.fill(0n)\r
+       static Square (out: Float64Array, a: Float64Array): void {\r
+               let v, c\r
+               const s = 1 << 16\r
+               const t = new Float64Array(31)\r
+               t.fill(0)\r
 \r
                // init t values, same as Multiply except we can skip some iterations of\r
                // the inner loop since a[x]*a[y] + a[y]*a[x] = 2*a[x]*a[y]\r
                for (let i = 0; i < 16; i++) {\r
                        for (let j = i; j < 16; j++) {\r
-                               t[i + j] += a[i] * a[j] * (i < j ? 2n : 1n)\r
+                               t[i + j] += a[i] * a[j] * (i < j ? 2 : 1)\r
                        }\r
                }\r
 \r
                for (let i = 0; i < 15; i++) {\r
-                       t[i] += 38n * t[i + 16]\r
+                       t[i] += 38 * t[i + 16]\r
                }\r
                // t15 left as is\r
 \r
                // first carry\r
-               c = 0n\r
+               c = 0\r
                for (let i = 0; i < 16; i++) {\r
                        v = t[i] + c\r
                        t[i] = v % s\r
-                       c = v / s\r
+                       c = (v / s) | 0\r
                }\r
-               t[0] += 38n * c\r
+               t[0] += 38 * c\r
 \r
                // second carry\r
-               c = 0n\r
+               c = 0\r
                for (let i = 0; i < 16; i++) {\r
                        v = t[i] + c\r
                        t[i] = v % s\r
-                       c = v / s\r
+                       c = (v / s) | 0\r
                }\r
-               t[0] += 38n * c\r
+               t[0] += 38 * c\r
 \r
                // assign result to output\r
                out.set(t.slice(0, 16), 0)\r
        }\r
 \r
-       static add (p: BigInt64Array[], q: BigInt64Array[]): void {\r
-               const a: BigInt64Array = new BigInt64Array(16)\r
-               const b: BigInt64Array = new BigInt64Array(16)\r
-               const c: BigInt64Array = new BigInt64Array(16)\r
-               const d: BigInt64Array = new BigInt64Array(16)\r
-               const e: BigInt64Array = new BigInt64Array(16)\r
-               const f: BigInt64Array = new BigInt64Array(16)\r
-               const g: BigInt64Array = new BigInt64Array(16)\r
-               const h: BigInt64Array = new BigInt64Array(16)\r
-               const t: BigInt64Array = new BigInt64Array(16)\r
+       static add (p: Float64Array[], q: Float64Array[]): void {\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
@@ -252,16 +252,16 @@ export class NanoNaCl {
                this.Multiply(p[3], e, h)\r
        }\r
 \r
-       static cswap (p: BigInt64Array[], q: BigInt64Array[], b: bigint): void {\r
+       static cswap (p: Float64Array[], q: Float64Array[], b: number): void {\r
                for (let i = 0; i < 4; i++) {\r
                        this.sel25519(p[i], q[i], b)\r
                }\r
        }\r
 \r
-       static pack (r: Uint8Array, p: BigInt64Array[]): void {\r
-               const tx: BigInt64Array = new BigInt64Array(16)\r
-               const ty: BigInt64Array = new BigInt64Array(16)\r
-               const zi: BigInt64Array = new BigInt64Array(16)\r
+       static pack (r: Uint8Array, p: Float64Array[]): void {\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
@@ -269,14 +269,13 @@ export class NanoNaCl {
                r[31] ^= this.par25519(tx) << 7\r
        }\r
 \r
-       static scalarmult (p: BigInt64Array[], q: BigInt64Array[], s: Uint8Array): void {\r
-               let b: bigint\r
-               p[0].fill(0n)\r
-               p[1].fill(0n).set([1n], 0)\r
-               p[2].fill(0n).set([1n], 0)\r
-               p[3].fill(0n)\r
+       static scalarmult (p: Float64Array[], q: Float64Array[], s: Uint8Array): void {\r
+               p[0].fill(0)\r
+               p[1].fill(0).set([1], 0)\r
+               p[2].fill(0).set([1], 0)\r
+               p[3].fill(0)\r
                for (let i = 255; i >= 0; --i) {\r
-                       b = (BigInt(s[(i / 8) | 0]) >> (BigInt(i) & 7n)) & 1n\r
+                       const b = (s[(i / 8) | 0] >> (i & 7)) & 1\r
                        this.cswap(p, q, b)\r
                        this.add(q, p)\r
                        this.add(p, p)\r
@@ -284,69 +283,67 @@ export class NanoNaCl {
                }\r
        }\r
 \r
-       static scalarbase (p: BigInt64Array[], s: Uint8Array): void {\r
-               const q: BigInt64Array[] = [new BigInt64Array(16), new BigInt64Array(16), new BigInt64Array(16), new BigInt64Array(16)]\r
+       static scalarbase (p: Float64Array[], s: Uint8Array): void {\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([1n], 0)\r
+               q[2].set([1], 0)\r
                q[3].set(this.XY, 0)\r
                this.scalarmult(p, q, s)\r
        }\r
 \r
-       static L = new BigInt64Array([\r
-               0xedn, 0xd3n, 0xf5n, 0x5cn, 0x1an, 0x63n, 0x12n, 0x58n,\r
-               0xd6n, 0x9cn, 0xf7n, 0xa2n, 0xden, 0xf9n, 0xden, 0x14n,\r
-               0x00n, 0x00n, 0x00n, 0x00n, 0x00n, 0x00n, 0x00n, 0x00n,\r
-               0x00n, 0x00n, 0x00n, 0x00n, 0x00n, 0x00n, 0x00n, 0x10n\r
+       static L = new Float64Array([\r
+               0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,\r
+               0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,\r
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10\r
        ])\r
 \r
-       static modL (r: Uint8Array, x: BigInt64Array): void {\r
-               let c: bigint, t: bigint, v: bigint\r
+       static modL (r: Uint8Array, x: Float64Array): void {\r
+               let c, t, v\r
                for (let i = 63; i >= 32; --i) {\r
-                       c = 0n\r
+                       c = 0\r
                        for (let j = i - 32, k = i - 12; j < k; j++) {\r
-                               t = 16n * x[i] * this.L[j - (i - 32)]\r
+                               t = 16 * x[i] * this.L[j - (i - 32)]\r
                                v = x[j] + c - t\r
-                               c = (v + 128n) / 256n\r
-                               x[j] = v - (c * 256n)\r
+                               c = ((v + 128) / 256) | 0\r
+                               x[j] = v - (c * 256)\r
                        }\r
                        x[i - 12] += c\r
-                       x[i] = 0n\r
+                       x[i] = 0\r
                }\r
-               c = 0n\r
+               c = 0\r
                for (let j = 0; j < 32; j++) {\r
-                       x[j] += c - (x[31] >> 4n) * this.L[j]\r
-                       c = x[j] >> 8n\r
-                       x[j] &= 255n\r
+                       x[j] += c - (x[31] >> 4) * this.L[j]\r
+                       c = x[j] >> 8\r
+                       x[j] &= 255\r
                }\r
                for (let j = 0; j < 32; j++) {\r
                        x[j] -= c * this.L[j]\r
                }\r
                for (let i = 0; i < 32; i++) {\r
-                       x[i + 1] += x[i] >> 8n\r
-                       r[i] = Number(x[i] & 255n)\r
+                       x[i + 1] += x[i] >> 8\r
+                       r[i] = x[i] & 255\r
                }\r
        }\r
 \r
        static reduce (r: Uint8Array): void {\r
-               const x: BigInt64Array = new BigInt64Array(64)\r
-               for (let i = 0; i < 64; i++) {\r
-                       x[i] = BigInt(r[i])\r
-               }\r
+               let x = new Float64Array(64)\r
+               x.set(r, 0)\r
                r.fill(0)\r
                this.modL(r, x)\r
        }\r
 \r
-       static unpackneg (r: BigInt64Array[], p: Uint8Array): -1 | 0 {\r
-               const t: BigInt64Array = new BigInt64Array(16)\r
-               const chk: BigInt64Array = new BigInt64Array(16)\r
-               const num: BigInt64Array = new BigInt64Array(16)\r
-               const den: BigInt64Array = new BigInt64Array(16)\r
-               const den2: BigInt64Array = new BigInt64Array(16)\r
-               const den4: BigInt64Array = new BigInt64Array(16)\r
-               const den6: BigInt64Array = new BigInt64Array(16)\r
+       static unpackneg (r: Float64Array[], p: Uint8Array): -1 | 0 {\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(0n).set([1n], 0)\r
+               r[2].fill(0).set([1], 0)\r
                this.unpack25519(r[1], p)\r
                this.Square(num, r[1])\r
                this.Multiply(den, num, this.D)\r
@@ -375,14 +372,14 @@ 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], new BigInt64Array(16), 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
        }\r
 \r
        static crypto_sign (sm: Uint8Array, m: Uint8Array, n: number, sk: Uint8Array, pk: Uint8Array): void {\r
-               const p: BigInt64Array[] = [new BigInt64Array(16), new BigInt64Array(16), new BigInt64Array(16), new BigInt64Array(16)]\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
@@ -401,11 +398,11 @@ export class NanoNaCl {
                const h = new Blake2b(64).update(sm).digest()\r
                this.reduce(h)\r
 \r
-               const x = new BigInt64Array(64)\r
-               for (let i = 0; i < 32; i++) x[i] = BigInt(r[i])\r
+               const x = new Float64Array(64)\r
+               x.set(r.subarray(0, 32))\r
                for (let i = 0; i < 32; i++) {\r
                        for (let j = 0; j < 32; j++) {\r
-                               x[i + j] += BigInt(h[i]) * BigInt(d[j])\r
+                               x[i + j] += h[i] * d[j]\r
                        }\r
                }\r
 \r
@@ -414,8 +411,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: BigInt64Array[] = [new BigInt64Array(16), new BigInt64Array(16), new BigInt64Array(16), new BigInt64Array(16)]\r
-               const q: BigInt64Array[] = [new BigInt64Array(16), new BigInt64Array(16), new BigInt64Array(16), new BigInt64Array(16)]\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
@@ -475,7 +472,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: BigInt64Array[] = [new BigInt64Array(16), new BigInt64Array(16), new BigInt64Array(16), new BigInt64Array(16)]\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