From: Chris Duncan Date: Fri, 2 Oct 2026 10:04:10 +0000 (-0700) Subject: Enforce function-specific names for module-scoped variable. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=76e52f89e263faa9fd5baed3c7c5c72ee3e3a71c;p=nano25519.git Enforce function-specific names for module-scoped variable. --- diff --git a/src/assembly/ed25519/ge.ts b/src/assembly/ed25519/ge.ts index cfd0df1..402213b 100644 --- a/src/assembly/ed25519/ge.ts +++ b/src/assembly/ed25519/ge.ts @@ -85,16 +85,16 @@ function ge_cmov8_base (t: ge_precomp, bp: usize, b: i8): void { v128.store_lane(td, v128.bitselect(v128.neg(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(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): 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): i32 return 0 } -const ge_frombytes_u8x32_scratch = new StaticArray(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(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): 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): 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(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)