From: Chris Duncan Date: Fri, 30 Oct 2026 21:38:53 +0000 (-0700) Subject: Add doc comments. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=89bcdebdf1bad43c2ba8edc84a4b7aad1a68c71c;p=nano25519.git Add doc comments. --- diff --git a/src/assembly/ed25519/ge.ts b/src/assembly/ed25519/ge.ts index 83c163f..175b141 100644 --- a/src/assembly/ed25519/ge.ts +++ b/src/assembly/ed25519/ge.ts @@ -94,14 +94,17 @@ export function ge_frombytes_negate_vartime (h: p3, s: StaticArray, const vx2 = ge_frombytes_negate_vartime_vx2 const check = ge_frombytes_negate_vartime_check + // Decode bytes to y-coordinate fe_frombytes(h.Y, s) fe_1(h.Z) - // u = y²-1 - // v = dy²+1 + // u = y² fe_sq(u, h.Y) + // v = dy² fe_mul_d(v, u) + // u = y²-1 u[0] -= 1 + // v = dy²+1 v[0] += 1 // v2 = v² @@ -133,14 +136,18 @@ export function ge_frombytes_negate_vartime (h: p3, s: StaticArray, // p = vx²+u fe_add(check, vx2, u) if (fe_iszero(check, t_fe_0, t_u8x32) == 0) { + // Reject invalid point return -1 } + // x = x√-1 fe_mul_sqrtm1(h.X, h.X) } + // x = |x| if (fe_isnegative(h.X, t_fe_0) == (s[31] >> 7)) { fe_neg(h.X, h.X) } + // Create point projection fe_mul(h.T, h.X, h.Y) return 0 @@ -175,21 +182,24 @@ export function ge_frombytes (h: p3, s: StaticArray, fe_frombytes(h.Y, s) fe_1(h.Z) - // u = y²-1 - // v = dy²+1 + // u = y² fe_sq(u, h.Y) + // v = dy² fe_mul_d(v, u) + // u = y²-1 u[0] -= 1 + // v = dy²+1 v[0] += 1 - // x = u(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 = u(uv)⁽𐞥⁻⁵⁾⸍⁸ fe_mul(h.X, u, h.X) // vx2 = x² fe_sq(vx2, h.X) - // vx2 = vx², x_sqrtm1 = x√-1 fe_mul_pair_sqrtm1(vx2, vx2, v, x_sqrtm1, h.X) @@ -199,10 +209,15 @@ export function ge_frombytes (h: p3, s: StaticArray, has_p_root = fe_iszero(p_root_check, t_fe_0, t_u8x32) has_m_root = fe_iszero(m_root_check, t_fe_0, t_u8x32) + // x = x√-1 if vx² = -u, else x fe_cmov(h.X, x_sqrtm1, 1 - has_m_root) + // negx = -x fe_neg(negx, h.X) + // x = |x| fe_cmov(h.X, negx, fe_isnegative(h.X, t_fe_0) ^ (s[31] >> 7)) + + // Create point projection fe_mul(h.T, h.X, h.Y) return i32(has_m_root | has_p_root) - 1