]> git.codecow.com Git - nano25519.git/commitdiff
Add doc comments.
authorChris Duncan <chris@codecow.com>
Fri, 30 Oct 2026 21:38:53 +0000 (14:38 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 30 Oct 2026 21:38:53 +0000 (14:38 -0700)
src/assembly/ed25519/ge.ts

index 83c163f5346a3bf18c636a8a54a9cf67f2aeee19..175b14199b247360d1904b4008a14f25a24daa5d 100644 (file)
@@ -94,14 +94,17 @@ export function ge_frombytes_negate_vartime (h: p3, s: StaticArray<u8>,
        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<u8>,
                // 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<u8>,
        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<u8>,
        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