*/
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)
}
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)
}
}
/**
- *
* `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
*/
}
/**
- * `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
}
/**
- * `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 {