]> git.codecow.com Git - nano25519.git/commitdiff
Eliminate a scratch buffer by reusing parameter.
authorChris Duncan <chris@zoso.dev>
Fri, 2 Oct 2026 05:16:26 +0000 (22:16 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 2 Oct 2026 05:16:26 +0000 (22:16 -0700)
src/assembly/ed25519/p.ts

index c1a7abb9216ecbb548e92025b2f2e529523df5f6..e36a98eb4f0dc461a876633aa52261a3ea84129d 100644 (file)
@@ -248,20 +248,21 @@ export function ge_sub_cached (r: ge_p1p1, p: ge_p3, q: ge_cached): void {
        fe_add(r.T, t0, r.T)
 }
 
-const ge_sub_precomp_t0: FieldElement = fe()
 /**
- * r = p - q
+ * `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.
  */
 export function ge_sub_precomp (r: ge_p1p1, p: ge_p3, q: ge_precomp): void {
-       const t0 = ge_sub_precomp_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.xy2d, p.T)
-       fe_dbl(t0, p.Z)
+       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, t0, r.T)
-       fe_add(r.T, t0, r.T)
+       fe_sub(r.Z, p.Z, r.T)
+       fe_add(r.T, p.Z, r.T)
 }