]> git.codecow.com Git - nano25519.git/commitdiff
Clear temporary buffers after inverting or powering.
authorChris Duncan <chris@codecow.com>
Tue, 3 Nov 2026 21:15:10 +0000 (13:15 -0800)
committerChris Duncan <chris@codecow.com>
Tue, 3 Nov 2026 21:15:10 +0000 (13:15 -0800)
src/assembly/ed25519/pow22523.ts

index 1a3951aa5d30c3f10bcef6d7197d37b38c7df4b9..082432a33edea484693230a21df38ab15a51f87b 100644 (file)
@@ -1,13 +1,20 @@
 //! SPDX-FileCopyrightText: 2026 Chris Duncan <chris@codecow.com>
 //! SPDX-License-Identifier: GPL-3.0-or-later
 
-import { FieldElement, fe, fe_mul, fe_sq, fe_sq_n } from './fe'
+import { FieldElement, fe, fe_0, fe_mul, fe_sq, fe_sq_n } from './fe'
 
 const a = fe()
 const b = fe()
 const c = fe()
 const t = fe()
 
+function clear (): void {
+       fe_0(a)
+       fe_0(b)
+       fe_0(c)
+       fe_0(t)
+}
+
 /**
  * Holds z¹¹ in `t` for final multiplication step of inversion.
  */
@@ -51,6 +58,7 @@ export function fe_invert (out: FieldElement, z: FieldElement): void {
        fe_pow22501(out, z)
        fe_sq_n(out, out, 5)
        fe_mul(out, t, out)
+       clear()
 }
 
 /**
@@ -68,4 +76,5 @@ export function fe_pow22523 (z: FieldElement): void {
        fe_pow22501(t, z)
        fe_sq_n(t, t, 2)
        fe_mul(z, t, z)
+       clear()
 }