From 52e26a724628f9091d3e027877e78bd5a4125661 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 1 Oct 2026 22:20:38 -0700 Subject: [PATCH] Eliminate another scratch buffer. --- src/assembly/ed25519/p.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/assembly/ed25519/p.ts b/src/assembly/ed25519/p.ts index e36a98e..e98adb8 100644 --- a/src/assembly/ed25519/p.ts +++ b/src/assembly/ed25519/p.ts @@ -229,30 +229,31 @@ export function ge_sub_p3 (r: ge_p3, p: ge_p3, q: ge_p3): void { ge_p1p1_to_p3(r, p1p1) } -const ge_sub_cached_t0: FieldElement = fe() /** - * r = p - q + * `r = p - q` + * + * `r.X` is doubled and stored to `p.X` because `p` is not referenced again + * before being reassigned at the only call site of this function. */ export function ge_sub_cached (r: ge_p1p1, p: ge_p3, q: ge_cached): void { - const t0 = ge_sub_cached_t0 fe_add(r.X, p.Y, p.X) fe_sub(r.Y, p.Y, p.X) fe_mul(r.Z, r.X, q.YminusX) fe_mul(r.Y, r.Y, q.YplusX) fe_mul(r.T, q.T2d, p.T) fe_mul(r.X, p.Z, q.Z) - fe_dbl(t0, r.X) + fe_dbl(p.X, r.X) fe_sub(r.X, r.Z, r.Y) fe_add(r.Y, r.Z, r.Y) - fe_sub(r.Z, t0, r.T) - fe_add(r.T, t0, r.T) + fe_sub(r.Z, p.X, r.T) + fe_add(r.T, p.X, r.T) } /** * `r = p - q` * - * `p.Z` is doubled and stored to itself because its value is not used again - * before being reassigned at the only call site of this function. + * `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) -- 2.52.0