From: Chris Duncan Date: Tue, 3 Nov 2026 14:46:12 +0000 (-0800) Subject: Write pow22523 output directly back to input buffer. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=694aabd4da68573a6139abdf45376fceccdf501a;p=nano25519.git Write pow22523 output directly back to input buffer. --- diff --git a/src/assembly/ed25519/ge.ts b/src/assembly/ed25519/ge.ts index 8321464..745c689 100644 --- a/src/assembly/ed25519/ge.ts +++ b/src/assembly/ed25519/ge.ts @@ -113,7 +113,7 @@ export function ge_frombytes (h: p3, s: StaticArray): i32 { // x = uv fe_mul(h.X, u, v) // x = (uv)⁽𐞥⁻⁵⁾⸍⁸ - fe_pow22523(h.X, h.X) + fe_pow22523(h.X) // x = u(uv)⁽𐞥⁻⁵⁾⸍⁸ fe_mul(h.X, u, h.X) diff --git a/src/assembly/ed25519/pow22523.ts b/src/assembly/ed25519/pow22523.ts index 015b476..1a3951a 100644 --- a/src/assembly/ed25519/pow22523.ts +++ b/src/assembly/ed25519/pow22523.ts @@ -45,7 +45,7 @@ function fe_pow22501 (out: FieldElement, z: FieldElement): void { /** * Inversion - sets `out` = 0 if `z` == 0 * - * Depends on `pow22501` setting `t = z¹¹`. Do not change this assignment. + * Depends on `fe_pow22501` setting `t = z¹¹`. Do not change this assignment. */ export function fe_invert (out: FieldElement, z: FieldElement): void { fe_pow22501(out, z) @@ -58,12 +58,14 @@ export function fe_invert (out: FieldElement, z: FieldElement): void { * * Used to compute square roots since we have p = 5 (mod 8); see Cohen and Frey. * - * Does not need intermediate `z¹¹` result, so `t` is overwritable and thus - * reused for intermediate `pow22501` result since `out` can and does alias `z` - * and must not be used until the very last output step. + * Does not need intermediate `z¹¹` result, so module-scoped `t` is overwritable + * and thus reused for intermediate `fe_pow22501` result. + * + * `z` is overwritten with the final result, ergo it must not be used to hold + * output until the very last step. */ -export function fe_pow22523 (out: FieldElement, z: FieldElement): void { +export function fe_pow22523 (z: FieldElement): void { fe_pow22501(t, z) fe_sq_n(t, t, 2) - fe_mul(out, t, z) + fe_mul(z, t, z) }