From: Chris Duncan Date: Fri, 30 Oct 2026 21:40:07 +0000 (-0700) Subject: Use short form for vartime negated byte decoding to save mul and sq calls while getti... X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=4b25d05af6ba3f5a192817ecc5253a19aa1c2cc8;p=nano25519.git Use short form for vartime negated byte decoding to save mul and sq calls while getting the same result. --- diff --git a/src/assembly/ed25519/ge.ts b/src/assembly/ed25519/ge.ts index 175b141..2adc9d5 100644 --- a/src/assembly/ed25519/ge.ts +++ b/src/assembly/ed25519/ge.ts @@ -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, ): 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, // 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)