]> git.codecow.com Git - nano25519.git/commitdiff
Share check buffer since they aren't needed in parallel when variable time.
authorChris Duncan <chris@codecow.com>
Fri, 30 Oct 2026 19:38:24 +0000 (12:38 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 30 Oct 2026 19:38:24 +0000 (12:38 -0700)
src/assembly/ed25519/ge.ts

index 6a67ab346a5c3ba8e7287d418fd04de96d97c18a..2ef2506708c709a00bf67181f31ad9d173cdd792 100644 (file)
@@ -75,8 +75,7 @@ const ge_frombytes_negate_vartime_u: FieldElement = fe()
 const ge_frombytes_negate_vartime_v: FieldElement = fe()
 const ge_frombytes_negate_vartime_v3: FieldElement = fe()
 const ge_frombytes_negate_vartime_vxx: FieldElement = fe()
-const ge_frombytes_negate_vartime_m_root_check: FieldElement = fe()
-const ge_frombytes_negate_vartime_p_root_check: FieldElement = fe()
+const ge_frombytes_negate_vartime_check: FieldElement = fe()
 /**
  * Variable-time point negation converted from byte representation.
  *
@@ -91,8 +90,7 @@ export function ge_frombytes_negate_vartime (h: p3, s: StaticArray<u8>,
        const v = ge_frombytes_negate_vartime_v
        const v3 = ge_frombytes_negate_vartime_v3
        const vxx = ge_frombytes_negate_vartime_vxx
-       const m_root_check = ge_frombytes_negate_vartime_m_root_check
-       const p_root_check = ge_frombytes_negate_vartime_p_root_check
+       const check = ge_frombytes_negate_vartime_check
 
        fe_frombytes(h.Y, s)
        fe_1(h.Z)
@@ -113,10 +111,10 @@ export function ge_frombytes_negate_vartime (h: p3, s: StaticArray<u8>,
        fe_mul(h.X, h.X, v)
        fe_mul(h.X, h.X, u)
 
-       // x = (uv⁷)^((q-5)/8)
+       // x = (uv⁷)⁽𐞥⁻⁵⁾⸍⁸
        fe_pow22523(h.X, h.X, t_fe_0, t_fe_1, t_fe_2)
 
-       // x = uv³((uv⁷)^((q-5)/8))
+       // x = uv³((uv⁷)⁽𐞥⁻⁵⁾⸍⁸) = u⁽𐞥⁺³⁾⸍⁸v⁽⁷𐞥⁻¹¹⁾⸍⁸
        fe_mul(h.X, h.X, v3)
        fe_mul(h.X, h.X, u)
 
@@ -125,11 +123,11 @@ export function ge_frombytes_negate_vartime (h: p3, s: StaticArray<u8>,
        fe_mul(vxx, vxx, v)
 
        // m = vx²-u
-       fe_sub(m_root_check, vxx, u)
-       if (fe_iszero(m_root_check, t_fe_0, t_u8x32) == 0) {
+       fe_sub(check, vxx, u)
+       if (fe_iszero(check, t_fe_0, t_u8x32) == 0) {
                // p = vx²+u
-               fe_add(p_root_check, vxx, u)
-               if (fe_iszero(p_root_check, t_fe_0, t_u8x32) == 0) {
+               fe_add(check, vxx, u)
+               if (fe_iszero(check, t_fe_0, t_u8x32) == 0) {
                        return -1
                }
                fe_mul_sqrtm1(h.X, h.X)