]> git.codecow.com Git - nano25519.git/commitdiff
Enforce function-specific names for module-scoped variable.
authorChris Duncan <chris@zoso.dev>
Fri, 2 Oct 2026 10:04:10 +0000 (03:04 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 2 Oct 2026 10:04:10 +0000 (03:04 -0700)
src/assembly/ed25519/ge.ts

index cfd0df13d972db25515bed171f03ae585d53980c..402213b3fc45458a5d1b5f778cf00c43bd31860e 100644 (file)
@@ -85,16 +85,16 @@ function ge_cmov8_base (t: ge_precomp, bp: usize, b: i8): void {
        v128.store_lane<u64>(td, v128.bitselect(v128.neg<i32>(d2), d2, n), 0, 32)
 }
 
+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_u8x32_scratch = new StaticArray<u8>(32)
 const ge_frombytes_negate_vartime_fe_scratch_0: FieldElement = fe()
 const ge_frombytes_negate_vartime_fe_scratch_1: FieldElement = fe()
 const ge_frombytes_negate_vartime_fe_scratch_2: FieldElement = fe()
-const u: FieldElement = fe()
-const v: FieldElement = fe()
-const v3: FieldElement = fe()
-const vxx: FieldElement = fe()
-const m_root_check: FieldElement = fe()
-const p_root_check: FieldElement = fe()
 /**
  * Variable-time point negation converted from byte representation.
  *
@@ -103,10 +103,18 @@ const p_root_check: FieldElement = fe()
  * @returns {i32} 0 if `s` decodes to a valid point, else -1
  */
 export function ge_frombytes_negate_vartime (h: ge_p3, s: StaticArray<u8>): i32 {
+       const u = ge_frombytes_negate_vartime_u
+       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 u8x32_scratch = ge_frombytes_negate_vartime_u8x32_scratch
        const fe_scratch_0 = ge_frombytes_negate_vartime_fe_scratch_0
        const fe_scratch_1 = ge_frombytes_negate_vartime_fe_scratch_1
        const fe_scratch_2 = ge_frombytes_negate_vartime_fe_scratch_2
+
        fe_frombytes(h.Y, s)
        fe_1(h.Z)
 
@@ -156,33 +164,36 @@ export function ge_frombytes_negate_vartime (h: ge_p3, s: StaticArray<u8>): i32
        return 0
 }
 
-const ge_frombytes_u8x32_scratch = new StaticArray<u8>(32)
-const ge_frombytes_fe_scratch_0: FieldElement = fe()
-const ge_frombytes_fe_scratch_1: FieldElement = fe()
-const ge_frombytes_fe_scratch_2: FieldElement = fe()
 const ge_frombytes_u: FieldElement = fe()
 const ge_frombytes_v: FieldElement = fe()
 const ge_frombytes_vxx: FieldElement = fe()
 const ge_frombytes_m_root_check: FieldElement = fe()
 const ge_frombytes_p_root_check: FieldElement = fe()
 const ge_frombytes_negx: FieldElement = fe()
-const x_sqrtm1: FieldElement = fe()
+const ge_frombytes_x_sqrtm1: FieldElement = fe()
+const ge_frombytes_u8x32_scratch = new StaticArray<u8>(32)
+const ge_frombytes_fe_scratch_0: FieldElement = fe()
+const ge_frombytes_fe_scratch_1: FieldElement = fe()
+const ge_frombytes_fe_scratch_2: FieldElement = fe()
 /**
  * Constant-time point negation converted from byte representation.
  *
  * @returns {i32} 0 if `s` decodes to a valid point, else -1
  */
 export function ge_frombytes (h: ge_p3, s: StaticArray<u8>): i32 {
-       const u8x32_scratch = ge_frombytes_u8x32_scratch
-       const fe_scratch_0 = ge_frombytes_fe_scratch_0
-       const fe_scratch_1 = ge_frombytes_fe_scratch_1
-       const fe_scratch_2 = ge_frombytes_fe_scratch_2
        const u = ge_frombytes_u
        const v = ge_frombytes_v
        const vxx = ge_frombytes_vxx
        const m_root_check = ge_frombytes_m_root_check
        const p_root_check = ge_frombytes_p_root_check
        const negx = ge_frombytes_negx
+       const x_sqrtm1 = ge_frombytes_x_sqrtm1
+
+       const u8x32_scratch = ge_frombytes_u8x32_scratch
+       const fe_scratch_0 = ge_frombytes_fe_scratch_0
+       const fe_scratch_1 = ge_frombytes_fe_scratch_1
+       const fe_scratch_2 = ge_frombytes_fe_scratch_2
+
        let has_m_root: u8
        let has_p_root: u8
 
@@ -224,14 +235,21 @@ export function ge_frombytes (h: ge_p3, s: StaticArray<u8>): i32 {
        return i32(has_m_root | has_p_root) - 1
 }
 
+const ge_has_small_order_y_sqrtm1: FieldElement = fe()
+const ge_has_small_order_c: FieldElement = fe()
 const ge_has_small_order_u8x32_scratch = new StaticArray<u8>(32)
 const ge_has_small_order_fe_scratch: FieldElement = fe()
-const y_sqrtm1: FieldElement = fe()
-const c: FieldElement = fe()
-/** return 1 if p has small order else return 0 */
+/**
+ * @param {ge_p3} p
+ * @returns 1 if `p` has small order, else 0
+ */
 export function ge_has_small_order (p: ge_p3): i32 {
+       const y_sqrtm1 = ge_has_small_order_y_sqrtm1
+       const c = ge_has_small_order_c
+
        const u8x32_scratch = ge_has_small_order_u8x32_scratch
        const fe_scratch = ge_has_small_order_fe_scratch
+
        let ret: i32 = 0
 
        ret |= fe_iszero(p.X, u8x32_scratch, fe_scratch)