]> git.codecow.com Git - libnemo.git/commitdiff
Unroll loop to eliminate branching.
authorChris Duncan <chris@zoso.dev>
Sun, 17 Aug 2025 09:55:00 +0000 (02:55 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 17 Aug 2025 09:55:00 +0000 (02:55 -0700)
src/lib/crypto/nano-nacl.ts

index c1e401d67096496ed0ad9bde80bff4054b4bc9c1..104e5af075e4a51b903a54a8a5e6100ae9e8c7f3 100644 (file)
@@ -62,12 +62,18 @@ export class NanoNaCl {
        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
+               for (let a = 0; a < 249; a++) {\r
                        this.Square(c, c)\r
-                       if (a !== 2 && a !== 4) {\r
-                               this.Multiply(c, c, i)\r
-                       }\r
+                       this.Multiply(c, c, i)\r
                }\r
+               this.Square(c, c)\r
+               this.Square(c, c)\r
+               this.Multiply(c, c, i)\r
+               this.Square(c, c)\r
+               this.Square(c, c)\r
+               this.Multiply(c, c, i)\r
+               this.Square(c, c)\r
+               this.Multiply(c, c, i)\r
                out.set(c, 0)\r
        }\r
 \r