/**
* `r = p + q`
*
- * `p.Z` is doubled and stored to itself because its value is not referenced
- * again before being reassigned at all three call sites of this function.
+ * ```
+ * X = (Y₁ + X₁)(Y₂ + X₂) - (Y₁ - X₁)(Y₂ - X₂)
+ * Y = (Y₁ + X₁)(Y₂ + X₂) + (Y₁ - X₁)(Y₂ - X₂)
+ * Z = 2Z₁ + 2dT₁X₂Y₂
+ * T = 2Z₁ - 2dT₁X₂Y₂
+ * ```
*/
export function ge_add_precomp (r: ge_p1p1, p: ge_p3, q: ge_precomp): void {
fe_add(r.X, p.Y, p.X)
fe_sub(r.Y, p.Y, p.X)
- fe_mul_dual(r.Z, r.X, q.yplusx, r.Y, r.Y, q.yminusx)
+ fe_mul_dual(r.X, r.X, q.yplusx, r.Y, r.Y, q.yminusx)
+ fe_dbl(r.Z, p.Z)
fe_mul(r.T, q.xy2d, p.T)
- fe_dbl(p.Z, p.Z)
- fe_sub(r.X, r.Z, r.Y)
- fe_add(r.Y, r.Z, r.Y)
- fe_add(r.Z, p.Z, r.T)
- fe_sub(r.T, p.Z, r.T)
+ fe_subadd(r.X, r.Y)
+ fe_addsub(r.Z, r.T)
}
/**
/**
* `r = p - q`
*
+ * ```
+ * X = (Y₁ + X₁)(Y₂ - X₂) - (Y₁ - X₁)(Y₂ + X₂)
+ * Y = (Y₁ + X₁)(Y₂ - X₂) + (Y₁ - X₁)(Y₂ + X₂)
+ * Z = 2Z₁ - 2dT₁X₂Y₂
+ * T = 2Z₁ + 2dT₁X₂Y₂
+ * ```
+ *
* `p.Z` is doubled and stored to itself because its value is not referenced
* again before being reassigned at the only call site of this function.
*/
export function ge_sub_precomp (r: ge_p1p1, p: ge_p3, q: ge_precomp): void {
fe_add(r.X, p.Y, p.X)
fe_sub(r.Y, p.Y, p.X)
- fe_mul_dual(r.Z, r.X, q.yminusx, r.Y, r.Y, q.yplusx)
+ fe_mul_dual(r.X, r.X, q.yminusx, r.Y, r.Y, q.yplusx)
+ fe_dbl(r.Z, p.Z)
fe_mul(r.T, q.xy2d, p.T)
- fe_dbl(p.Z, p.Z)
- fe_sub(r.X, r.Z, r.Y)
- fe_add(r.Y, r.Z, r.Y)
- fe_sub(r.Z, p.Z, r.T)
- fe_add(r.T, p.Z, r.T)
+ fe_subadd(r.X, r.Y)
+ fe_subadd(r.Z, r.T)
}
export function ge_p3_tobytes (s: StaticArray<u8>, h: ge_p3,
//! SPDX-FileCopyrightText: 2026 Chris Duncan <chris@codecow.com>
//! SPDX-License-Identifier: ISC
-import { FieldElement, fe_add, fe_dbl, fe_invert, fe_isnegative, fe_mul, fe_mul_dual, fe_sub, fe_tobytes } from './fe'
+import { FieldElement, fe_add, fe_addsub, fe_dbl, fe_invert, fe_isnegative, fe_mul, fe_mul_dual, fe_sub, fe_subadd, fe_tobytes } from './fe'
import { FieldElementPair, fep, fep_add, fep_addsub, fep_blend, fep_mul, fep_mul2, fep_mul_lane, fep_pack, fep_sq, fep_sq2, fep_sub, fep_subadd, fep_swap, fep_unpack, fep_unpack_a } from './fep'
import { ge_cached, ge_p1p1, ge_p2, ge_p3, ge_precomp } from './p'
/**
* `r = p + q`
*
- * `p.Z` is doubled and stored to itself because its value is not referenced
- * again before being reassigned at all three call sites of this function.
+ * ```
+ * X = (Y₁ + X₁)(Y₂ + X₂) - (Y₁ - X₁)(Y₂ - X₂)
+ * Y = (Y₁ + X₁)(Y₂ + X₂) + (Y₁ - X₁)(Y₂ - X₂)
+ * Z = 2Z₁ + 2dT₁X₂Y₂
+ * T = 2Z₁ - 2dT₁X₂Y₂
+ * ```
*/
export function gepair_add_precomp (r: ge_p1p1, p: ge_p3, q: ge_precomp): void {
fe_add(r.X, p.Y, p.X)
fe_sub(r.Y, p.Y, p.X)
- fe_mul_dual(r.Z, r.X, q.yplusx, r.Y, r.Y, q.yminusx)
+ fe_mul_dual(r.X, r.X, q.yplusx, r.Y, r.Y, q.yminusx)
+ fe_dbl(r.Z, p.Z)
fe_mul(r.T, q.xy2d, p.T)
- fe_dbl(p.Z, p.Z)
- fe_sub(r.X, r.Z, r.Y)
- fe_add(r.Y, r.Z, r.Y)
- fe_add(r.Z, p.Z, r.T)
- fe_sub(r.T, p.Z, r.T)
+ fe_subadd(r.X, r.Y)
+ fe_addsub(r.Z, r.T)
}
const gepair_sub_cached_pA = fep()
/**
* `r = p - q`
*
+ * ```
+ * X = (Y₁ + X₁)(Y₂ - X₂) - (Y₁ - X₁)(Y₂ + X₂)
+ * Y = (Y₁ + X₁)(Y₂ - X₂) + (Y₁ - X₁)(Y₂ + X₂)
+ * Z = 2Z₁ - 2dT₁X₂Y₂
+ * T = 2Z₁ + 2dT₁X₂Y₂
+ * ```
+ *
* `p.Z` is doubled and stored to itself because its value is not referenced
* again before being reassigned at the only call site of this function.
*/
export function gepair_sub_precomp (r: ge_p1p1, p: ge_p3, q: ge_precomp): void {
fe_add(r.X, p.Y, p.X)
fe_sub(r.Y, p.Y, p.X)
- fe_mul_dual(r.Z, r.X, q.yminusx, r.Y, r.Y, q.yplusx)
+ fe_mul_dual(r.X, r.X, q.yminusx, r.Y, r.Y, q.yplusx)
+ fe_dbl(r.Z, p.Z)
fe_mul(r.T, q.xy2d, p.T)
- fe_dbl(p.Z, p.Z)
- fe_sub(r.X, r.Z, r.Y)
- fe_add(r.Y, r.Z, r.Y)
- fe_sub(r.Z, p.Z, r.T)
- fe_add(r.T, p.Z, r.T)
+ fe_subadd(r.X, r.Y)
+ fe_subadd(r.Z, r.T)
}
function ge_p3_tobytes (s: StaticArray<u8>, h: gepair_p3,