}
/**
+ *
+ * `f = a²ⁿ`
+ *
* Square a FieldElement and store the result.
*
* Some iterations of the inner loop can be skipped since
- * `f[x]*f[y] + f[y]*f[x] = 2*f[x]*f[y]`
+ * `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++) {
- * h[i + j] += f[i] * g[j]
+ * f[i + j] += a[i] * b[j]
* if (i < j) {
- * h[i + j] *= 2
+ * f[i + j] *= 2
* }
* }
* }
* ```
*
- * h = f * f
- * Can overlap h with f.
+ * Can overlap `f` with `a`.
*
* Preconditions:
- * |f| bounded by 1.65*2²⁶,1.65*2²⁵,1.65*2²⁶,1.65*2²⁵,etc.
+ * |a| 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.
+ * |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
*/
export function fe_sq (f: FieldElement, a: FieldElement): void {
+ fe_sq_n(f, a, 1)
+}
+
+/**
+ * f = a²`
+ *
+ * Can overlap `f` with `a`.
+ *
+ * Square a FieldElement `n` times and store the final result.
+ *
+ * Some iterations of the inner loop can be skipped since
+ * `a[x]*f[y] + a[y]*f[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 FieldElement power destination
+ * @param a FieldElement base source
+ */
+export function fe_sq_n (f: FieldElement, a: FieldElement, n: i32): void {
const a_ptr: usize = changetype<usize>(a)
const a0: i64 = i64(load<i32>(a_ptr, 0 << 2))
const a1: i64 = i64(load<i32>(a_ptr, 1 << 2))