]> git.codecow.com Git - nano25519.git/commitdiff
Eliminate some redundant computations.
authorChris Duncan <chris@codecow.com>
Thu, 22 Oct 2026 04:50:34 +0000 (21:50 -0700)
committerChris Duncan <chris@codecow.com>
Thu, 22 Oct 2026 04:50:34 +0000 (21:50 -0700)
src/assembly/ed25519/fe.ts

index 9918c70100dbf40f8541527b316815f7eab4ea4e..87d09c9fa7f621019dd8162150f1675529810983 100644 (file)
@@ -1032,14 +1032,12 @@ export function fe_sq (h: FieldElement, f: FieldElement): void {
        const f6_2: i64 = f6 + f6
        const f7_2: i64 = f7 + f7
 
-       const f5_19: i64 = f5 * 19 /* 1.959375*2²⁹ */
        const f6_19: i64 = f6 * 19 /* 1.959375*2³⁰ */
-       const f7_19: i64 = f7 * 19 /* 1.959375*2²⁹ */
        const f8_19: i64 = f8 * 19 /* 1.959375*2³⁰ */
-       const f9_19: i64 = f9 * 19 /* 1.959375*2²⁹ */
 
-       const f7_38: i64 = f7_19 + f7_19 /* 1.959375*2³⁰ */
-       const f9_38: i64 = f9_19 + f9_19 /* 1.959375*2³⁰ */
+       const f5_38: i64 = f5 * 38 /* 1.959375*2³⁰ */
+       const f7_38: i64 = f7 * 38 /* 1.959375*2³⁰ */
+       const f9_38: i64 = f9 * 38 /* 1.959375*2³⁰ */
 
        let h0: i64 = f0 * f0
        let h1: i64 = f0_2 * f1
@@ -1069,7 +1067,7 @@ export function fe_sq (h: FieldElement, f: FieldElement): void {
        h8 += f2_2 * f6
        h9 += f2_2 * f7
        h0 += f2_2 * f8_19
-       h1 += f2_2 * f9_19
+       h1 += f2 * f9_38
 
        h6 += f3_2 * f3
        h7 += f3_2 * f4
@@ -1082,22 +1080,22 @@ export function fe_sq (h: FieldElement, f: FieldElement): void {
        h8 += f4 * f4
        h9 += f4_2 * f5
        h0 += f4_2 * f6_19
-       h1 += f4_2 * f7_19
+       h1 += f4 * f7_38
        h2 += f4_2 * f8_19
-       h3 += f4_2 * f9_19
+       h3 += f4 * f9_38
 
-       h0 += f5_2 * f5_19
+       h0 += f5 * f5_38
        h1 += f5_2 * f6_19
        h2 += f5_2 * f7_38
        h3 += f5_2 * f8_19
        h4 += f5_2 * f9_38
 
        h2 += f6 * f6_19
-       h3 += f6_2 * f7_19
+       h3 += f6 * f7_38
        h4 += f6_2 * f8_19
-       h5 += f6_2 * f9_19
+       h5 += f6 * f9_38
 
-       h4 += f7_2 * f7_19
+       h4 += f7 * f7_38
        h5 += f7_2 * f8_19
        h6 += f7_2 * f9_38