]> git.codecow.com Git - nano25519.git/commitdiff
Use short form for vartime negated byte decoding to save mul and sq calls while getti...
authorChris Duncan <chris@codecow.com>
Fri, 30 Oct 2026 21:40:07 +0000 (14:40 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 30 Oct 2026 21:40:07 +0000 (14:40 -0700)
src/assembly/ed25519/ge.ts

index 175b14199b247360d1904b4008a14f25a24daa5d..2adc9d534828878aec62fb0359e8f7a7cf73a266 100644 (file)
@@ -73,8 +73,6 @@ function ge_cmov8_base (t: p_precomp, bp: usize, b: i8): void {
 
 const ge_frombytes_negate_vartime_u: FieldElement = fe()
 const ge_frombytes_negate_vartime_v: FieldElement = fe()
-const ge_frombytes_negate_vartime_v2: FieldElement = fe()
-const ge_frombytes_negate_vartime_uv3: FieldElement = fe()
 const ge_frombytes_negate_vartime_vx2: FieldElement = fe()
 const ge_frombytes_negate_vartime_check: FieldElement = fe()
 /**
@@ -89,8 +87,6 @@ export function ge_frombytes_negate_vartime (h: p3, s: StaticArray<u8>,
 ): i32 {
        const u = ge_frombytes_negate_vartime_u
        const v = ge_frombytes_negate_vartime_v
-       const v2 = ge_frombytes_negate_vartime_v2
-       const uv3 = ge_frombytes_negate_vartime_uv3
        const vx2 = ge_frombytes_negate_vartime_vx2
        const check = ge_frombytes_negate_vartime_check
 
@@ -107,23 +103,12 @@ export function ge_frombytes_negate_vartime (h: p3, s: StaticArray<u8>,
        // v = dy²+1
        v[0] += 1
 
-       // v2 = v²
-       fe_sq(v2, v)
-       // uv3 = v³
-       fe_mul(uv3, v2, v)
-       // uv3 = uv³
-       fe_mul(uv3, uv3, u)
-
-       // x = v⁴
-       fe_sq(h.X, v2)
-       // x = uv⁷
-       fe_mul(h.X, h.X, uv3)
-
-       // x = (uv⁷)⁽𐞥⁻⁵⁾⸍⁸
+       // x = uv
+       fe_mul(h.X, u, v)
+       // x = (uv)⁽𐞥⁻⁵⁾⸍⁸
        fe_pow22523(h.X, h.X, t_fe_0, t_fe_1, t_fe_2)
-
-       // x = uv³((uv⁷)⁽𐞥⁻⁵⁾⸍⁸) = u⁽𐞥⁺³⁾⸍⁸v⁽⁷𐞥⁻¹¹⁾⸍⁸
-       fe_mul(h.X, h.X, uv3)
+       // x = u(uv)⁽𐞥⁻⁵⁾⸍⁸
+       fe_mul(h.X, u, h.X)
 
        // vx2 = x²
        fe_sq(vx2, h.X)