]> git.codecow.com Git - nano25519.git/commitdiff
Improve and consolidate doc comments. Whitespace for legibility.
authorChris Duncan <chris@codecow.com>
Sat, 31 Oct 2026 23:05:38 +0000 (16:05 -0700)
committerChris Duncan <chris@codecow.com>
Sat, 31 Oct 2026 23:05:38 +0000 (16:05 -0700)
src/assembly/ed25519/fe.ts

index 74da87e8cf6ac6f149bbaf734bfa73ab68054a14..8709623b1933da5f182bc4c32b3b2c509f5e66b7 100644 (file)
@@ -353,26 +353,34 @@ export function fe_frombytes (h: FieldElement, s: StaticArray<u8>): void {
  */
 export function fe_invert (out: FieldElement, z: FieldElement, t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement, t_fe_3: FieldElement): void {
        fe_sq(t_fe_0, z)
-       fe_sq(t_fe_1, t_fe_0)
-       fe_sq(t_fe_1, t_fe_1)
+       fe_sq_n(t_fe_1, t_fe_0, 2)
        fe_mul(t_fe_1, z, t_fe_1)
        fe_mul(t_fe_0, t_fe_0, t_fe_1)
+
        fe_sq(t_fe_2, t_fe_0)
        fe_mul(t_fe_1, t_fe_1, t_fe_2)
+
        fe_sq_n(t_fe_2, t_fe_1, 5)
        fe_mul(t_fe_1, t_fe_2, t_fe_1)
+
        fe_sq_n(t_fe_2, t_fe_1, 10)
        fe_mul(t_fe_2, t_fe_2, t_fe_1)
+
        fe_sq_n(t_fe_3, t_fe_2, 20)
        fe_mul(t_fe_2, t_fe_3, t_fe_2)
+
        fe_sq_n(t_fe_2, t_fe_2, 10)
        fe_mul(t_fe_1, t_fe_2, t_fe_1)
+
        fe_sq_n(t_fe_2, t_fe_1, 50)
        fe_mul(t_fe_2, t_fe_2, t_fe_1)
+
        fe_sq_n(t_fe_3, t_fe_2, 100)
        fe_mul(t_fe_2, t_fe_3, t_fe_2)
+
        fe_sq_n(t_fe_2, t_fe_2, 50)
        fe_mul(t_fe_1, t_fe_2, t_fe_1)
+
        fe_sq_n(t_fe_1, t_fe_1, 5)
        fe_mul(out, t_fe_1, t_fe_0)
 }
@@ -1193,22 +1201,31 @@ export function fe_pow22523 (out: FieldElement, z: FieldElement, t_fe_0: FieldEl
        fe_sq_n(t_fe_1, t_fe_0, 2)
        fe_mul(t_fe_1, t_fe_1, z)
        fe_mul(t_fe_0, t_fe_1, t_fe_0)
+
        fe_sq(t_fe_0, t_fe_0)
        fe_mul(t_fe_0, t_fe_1, t_fe_0)
+
        fe_sq_n(t_fe_1, t_fe_0, 5)
        fe_mul(t_fe_0, t_fe_1, t_fe_0)
+
        fe_sq_n(t_fe_1, t_fe_0, 10)
        fe_mul(t_fe_1, t_fe_1, t_fe_0)
+
        fe_sq_n(t_fe_2, t_fe_1, 20)
        fe_mul(t_fe_1, t_fe_2, t_fe_1)
+
        fe_sq_n(t_fe_1, t_fe_1, 10)
        fe_mul(t_fe_0, t_fe_1, t_fe_0)
+
        fe_sq_n(t_fe_1, t_fe_0, 50)
        fe_mul(t_fe_1, t_fe_1, t_fe_0)
+
        fe_sq_n(t_fe_2, t_fe_1, 100)
        fe_mul(t_fe_1, t_fe_2, t_fe_1)
+
        fe_sq_n(t_fe_1, t_fe_1, 50)
        fe_mul(t_fe_0, t_fe_1, t_fe_0)
+
        fe_sq_n(t_fe_0, t_fe_0, 2)
        fe_mul(out, t_fe_0, z)
 }
@@ -1312,34 +1329,10 @@ export function fe_reduce (h: FieldElement, f: FieldElement): void {
 }
 
 /**
- *
  * `f = a²`
  *
  * Square a FieldElement and store the result.
  *
- * Some iterations of the inner loop can be skipped since
- * `a[x]*a[y] + a[y]*a[x] = 2*a[x]*a[y]`
- *
- * ```
- * // non-constant-time example
- * for (let i = 0; i < 10; i++) {
- *     for (let j = i; j < 10; j++) {
- *             f[i + j] += a[i] * b[j]
- *             if (i < j) {
- *                     f[i + j] *= 2
- *             }
- *     }
- * }
- * ```
- *
- * Can overlap `f` with `a`.
- *
- * Preconditions:
- * |a| bounded by 1.65*2²⁶,1.65*2²⁵,1.65*2²⁶,1.65*2²⁵,etc.
- *
- * Postconditions:
- * |f| bounded by 1.01*2²⁵,1.01*2²⁴,1.01*2²⁵,1.01*2²⁴,etc.
- *
  * @param f FieldElement power destination
  * @param a FieldElement base source
  */
@@ -1608,33 +1601,10 @@ export function fe_sq_n (f: FieldElement, a: FieldElement, n: i32): void {
 }
 
 /**
- * `f = a²; f = a²`
+ * `f₁ = a₁²; f₂ = a₂²`
  *
  * Square two FieldElement values in parallel and store the results.
  *
- * Can overlap `f` with `a`.
- *
- * Some iterations of the inner loop can be skipped since
- * `a[x]*a[y] + a[y]*a[x] = 2*a[x]*a[y]`
- *
- * ```
- * // non-constant-time example
- * for (let i = 0; i < 10; i++) {
- *     for (let j = i; j < 10; j++) {
- *             f[i + j] += a[i] * b[j]
- *             if (i < j) {
- *                     f[i + j] *= 2
- *             }
- *     }
- * }
- * ```
- *
- * Preconditions:
- * |a| bounded by 1.65*2²⁶,1.65*2²⁵,1.65*2²⁶,1.65*2²⁵,etc.
- *
- * Postconditions:
- * |f| bounded by 1.01*2²⁵,1.01*2²⁴,1.01*2²⁵,1.01*2²⁴,etc.
- *
  * @param f_0 First squaring destination
  * @param a_0 First multiplicand source
  * @param f_1 Second squaring destination
@@ -1761,22 +1731,14 @@ export function fe_sq_pair (f_0: FieldElement, a_0: FieldElement, f_1: FieldElem
 }
 
 /**
- * `f = 2a`
+ * `f₁ = 2a₁; f₂ = 2a₂`
  *
  * Square two FieldElement values in parallel, double the second one, and store
  * the results.
  *
- * Can overlap `f` with `a`.
- *
- * Preconditions:
- * |f| bounded by 1.65*2²⁶,1.65*2²⁵,1.65*2²⁶,1.65*2²⁵,etc.
- *
- * Postconditions:
- * |h| bounded by 1.01*2²⁵,1.01*2²⁴,1.01*2²⁵,1.01*2²⁴,etc.
- *
  * @param f_0 First squaring destination
  * @param a_0 First multiplicand source
- * @param f_1 Second squaring destination
+ * @param f_1 Second squaring destination, doubled
  * @param a_1 Second multiplicand source
  */
 export function fe_sq_pair_dbl (f_0: FieldElement, a_0: FieldElement, f_1: FieldElement, a_1: FieldElement): void {