]> git.codecow.com Git - libnemo.git/commitdiff
Expand operation function names for clarity over brevity.
authorChris Duncan <chris@zoso.dev>
Sun, 3 Aug 2025 09:05:15 +0000 (02:05 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 3 Aug 2025 09:05:15 +0000 (02:05 -0700)
src/lib/nano-nacl.ts

index 5cad82813212c59146816f2e617e828278e3f68b..789f52adffeae0e29a43ab4819a8d03330033242 100644 (file)
@@ -126,19 +126,19 @@ export class NanoNaCl {
                o[15] &= (1 << 15) - 1\r
        }\r
 \r
-       static A (o: Float64Array, a: Float64Array, b: Float64Array): void {\r
+       static Add (o: Float64Array, a: Float64Array, b: Float64Array): void {\r
                for (let i = 0; i < 16; i++) {\r
                        o[i] = a[i] + b[i]\r
                }\r
        }\r
 \r
-       static Z (o: Float64Array, a: Float64Array, b: Float64Array): void {\r
+       static Subtract (o: Float64Array, a: Float64Array, b: Float64Array): void {\r
                for (let i = 0; i < 16; i++) {\r
                        o[i] = a[i] - b[i]\r
                }\r
        }\r
 \r
-       static M (o: Float64Array, a: Float64Array, b: Float64Array): void {\r
+       static Multiply (o: Float64Array, a: Float64Array, b: Float64Array): void {\r
                let v, c, s = 1 << 16\r
                const t = new Array(31)\r
                t.fill(0)\r
@@ -177,17 +177,17 @@ export class NanoNaCl {
                o.set(t.slice(0, 16), 0)\r
        }\r
 \r
-       static S (o: Float64Array, a: Float64Array): void {\r
-               this.M(o, a, a)\r
+       static Square (o: Float64Array, a: Float64Array): void {\r
+               this.Multiply(o, a, a)\r
        }\r
 \r
        static inv25519 (o: 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.S(c, c)\r
+                       this.Square(c, c)\r
                        if (a !== 2 && a !== 4) {\r
-                               this.M(c, c, i)\r
+                               this.Multiply(c, c, i)\r
                        }\r
                }\r
                o.set(c, 0)\r
@@ -197,9 +197,9 @@ export class NanoNaCl {
                const c: Float64Array = this.gf()\r
                c.set(i.subarray(0, 16), 0)\r
                for (let a = 250; a >= 0; a--) {\r
-                       this.S(c, c)\r
+                       this.Square(c, c)\r
                        if (a !== 1) {\r
-                               this.M(c, c, i)\r
+                               this.Multiply(c, c, i)\r
                        }\r
                }\r
                o.set(c, 0)\r
@@ -216,25 +216,25 @@ export class NanoNaCl {
                const h: Float64Array = this.gf()\r
                const t: Float64Array = this.gf()\r
 \r
-               this.Z(a, p[1], p[0])\r
-               this.Z(t, q[1], q[0])\r
-               this.M(a, a, t)\r
-               this.A(b, p[0], p[1])\r
-               this.A(t, q[0], q[1])\r
-               this.M(b, b, t)\r
-               this.M(c, p[3], q[3])\r
-               this.M(c, c, this.D2)\r
-               this.M(d, p[2], q[2])\r
-               this.A(d, d, d)\r
-               this.Z(e, b, a)\r
-               this.Z(f, d, c)\r
-               this.A(g, d, c)\r
-               this.A(h, b, a)\r
-\r
-               this.M(p[0], e, f)\r
-               this.M(p[1], h, g)\r
-               this.M(p[2], g, f)\r
-               this.M(p[3], e, h)\r
+               this.Subtract(a, p[1], p[0])\r
+               this.Subtract(t, q[1], q[0])\r
+               this.Multiply(a, a, t)\r
+               this.Add(b, p[0], p[1])\r
+               this.Add(t, q[0], q[1])\r
+               this.Multiply(b, b, t)\r
+               this.Multiply(c, p[3], q[3])\r
+               this.Multiply(c, c, this.D2)\r
+               this.Multiply(d, p[2], q[2])\r
+               this.Add(d, d, d)\r
+               this.Subtract(e, b, a)\r
+               this.Subtract(f, d, c)\r
+               this.Add(g, d, c)\r
+               this.Add(h, b, a)\r
+\r
+               this.Multiply(p[0], e, f)\r
+               this.Multiply(p[1], h, g)\r
+               this.Multiply(p[2], g, f)\r
+               this.Multiply(p[3], e, h)\r
        }\r
 \r
        static cswap (p: Float64Array[], q: Float64Array[], b: number): void {\r
@@ -248,8 +248,8 @@ export class NanoNaCl {
                const ty: Float64Array = this.gf()\r
                const zi: Float64Array = this.gf()\r
                this.inv25519(zi, p[2])\r
-               this.M(tx, p[0], zi)\r
-               this.M(ty, p[1], zi)\r
+               this.Multiply(tx, p[0], zi)\r
+               this.Multiply(ty, p[1], zi)\r
                this.pack25519(r, ty)\r
                r[31] ^= this.par25519(tx) << 7\r
        }\r
@@ -360,34 +360,34 @@ export class NanoNaCl {
 \r
                this.set25519(r[2], this.gf([1]))\r
                this.unpack25519(r[1], p)\r
-               this.S(num, r[1])\r
-               this.M(den, num, this.D)\r
-               this.Z(num, num, r[2])\r
-               this.A(den, r[2], den)\r
+               this.Square(num, r[1])\r
+               this.Multiply(den, num, this.D)\r
+               this.Subtract(num, num, r[2])\r
+               this.Add(den, r[2], den)\r
 \r
-               this.S(den2, den)\r
-               this.S(den4, den2)\r
-               this.M(den6, den4, den2)\r
-               this.M(t, den6, num)\r
-               this.M(t, t, den)\r
+               this.Square(den2, den)\r
+               this.Square(den4, den2)\r
+               this.Multiply(den6, den4, den2)\r
+               this.Multiply(t, den6, num)\r
+               this.Multiply(t, t, den)\r
 \r
                this.pow2523(t, t)\r
-               this.M(t, t, num)\r
-               this.M(t, t, den)\r
-               this.M(t, t, den)\r
-               this.M(r[0], t, den)\r
+               this.Multiply(t, t, num)\r
+               this.Multiply(t, t, den)\r
+               this.Multiply(t, t, den)\r
+               this.Multiply(r[0], t, den)\r
 \r
-               this.S(chk, r[0])\r
-               this.M(chk, chk, den)\r
-               if (this.neq25519(chk, num)) this.M(r[0], r[0], this.I)\r
+               this.Square(chk, r[0])\r
+               this.Multiply(chk, chk, den)\r
+               if (this.neq25519(chk, num)) this.Multiply(r[0], r[0], this.I)\r
 \r
-               this.S(chk, r[0])\r
-               this.M(chk, chk, den)\r
+               this.Square(chk, r[0])\r
+               this.Multiply(chk, chk, den)\r
 \r
                if (this.neq25519(chk, num)) return -1\r
 \r
-               if (this.par25519(r[0]) === (p[31] >> 7)) this.Z(r[0], this.gf(), r[0])\r
-               this.M(r[3], r[0], r[1])\r
+               if (this.par25519(r[0]) === (p[31] >> 7)) this.Subtract(r[0], this.gf(), r[0])\r
+               this.Multiply(r[3], r[0], r[1])\r
                return 0\r
        }\r
 \r