]> git.codecow.com Git - libnemo.git/commitdiff
Keep loop variable lifetimes scoped to the loop to which they belong.
authorChris Duncan <chris@zoso.dev>
Thu, 14 Aug 2025 13:57:45 +0000 (06:57 -0700)
committerChris Duncan <chris@zoso.dev>
Thu, 14 Aug 2025 13:57:45 +0000 (06:57 -0700)
src/lib/crypto/nano-nacl.ts

index 0e867480b0c4bb8ab40be65da43692282eeeba61..9a0a2eddb6045887bf03569a6a9746f3be808649 100644 (file)
@@ -301,27 +301,27 @@ export class NanoNaCl {
        ])\r
 \r
        static modL (r: Uint8Array, x: BigInt64Array): void {\r
-               let carry: bigint, i, j, k\r
-               for (i = 63; i >= 32; --i) {\r
-                       carry = 0n\r
-                       for (j = i - 32, k = i - 12; j < k; ++j) {\r
-                               x[j] += carry - 16n * x[i] * this.L[j - (i - 32)]\r
-                               carry = (x[j] + 128n) / 256n\r
-                               x[j] -= carry * 256n\r
+               let c: bigint, v: bigint\r
+               for (let i = 63; i >= 32; --i) {\r
+                       c = 0n\r
+                       for (let j = i - 32, k = i - 12; j < k; j++) {\r
+                               x[j] += c - 16n * x[i] * this.L[j - (i - 32)]\r
+                               c = (x[j] + 128n) / 256n\r
+                               x[j] -= c * 256n\r
                        }\r
-                       x[j] += carry\r
+                       x[i - 12] += c\r
                        x[i] = 0n\r
                }\r
-               carry = 0n\r
-               for (j = 0; j < 32; j++) {\r
-                       x[j] += carry - (x[31] >> 4n) * this.L[j]\r
-                       carry = x[j] >> 8n\r
+               c = 0n\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
                }\r
-               for (j = 0; j < 32; j++) {\r
-                       x[j] -= carry * this.L[j]\r
+               for (let j = 0; j < 32; j++) {\r
+                       x[j] -= c * this.L[j]\r
                }\r
-               for (i = 0; i < 32; i++) {\r
+               for (let i = 0; i < 32; i++) {\r
                        x[i + 1] += x[i] >> 8n\r
                        r[i] = Number(x[i] & 255n)\r
                }\r