]> git.codecow.com Git - nano25519.git/commitdiff
Clear WASM I/O buffers with host-side call to export instead of using setters and...
authorChris Duncan <chris@zoso.dev>
Wed, 23 Sep 2026 19:41:27 +0000 (12:41 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 23 Sep 2026 19:41:27 +0000 (12:41 -0700)
src/assembly/index.ts
src/lib/wasm.ts

index 5eaf811630555e64e46f1d112b3d1234c62578a0..d300801ddd0d95a0c4b7220039d08a795fde56a4 100644 (file)
@@ -19,6 +19,17 @@ const OUTPUT_DERIVE = new StaticArray<u8>(KEY_BYTELENGTH)
 const OUTPUT_SIGN = new StaticArray<u8>(SIGNATURE_BYTELENGTH)
 const OUTPUT_VERIFY = new StaticArray<u8>(MAX_VERIFY_BLOCKS)
 
+/** Clears all input and output buffers. */
+export function clearMemory (): void {
+       INPUT_MSG.fill(0)
+       INPUT_PRV.fill(0)
+       INPUT_PUB.fill(0)
+       INPUT_SIG.fill(0)
+       OUTPUT_DERIVE.fill(0)
+       OUTPUT_SIGN.fill(0)
+       OUTPUT_VERIFY.fill(0)
+}
+
 /** Sets a byte in the static message input buffer. */
 export function setInputMsgByte (index: i32, v0: i32): i32 {
        if (index < 0 || MAX_MESSAGE_BYTELENGTH <= index) {
index 16e67d2bce1f496bc2815e6634feb9f6e58e2de8..cb62d4bc23ec034009b32f1f4b004f34ff75b6f9 100644 (file)
@@ -6,6 +6,7 @@ import nano25519_wasm from '../../build/nano25519.wasm'
 import { Nano25519TypeError, copy } from './primordials'
 
 type Exports = WebAssembly.Instance['exports'] & {
+       clearMemory: () => void
        derive: () => void
        sign: (mlen: number) => number
        verify: (mlen: number) => number
@@ -91,18 +92,7 @@ export class MemoryBuffers {
 }
 
 export function clearMemory (): void {
-       for (let i = 0; i < MAX_MESSAGE_BYTELENGTH; i++) {
-               MemoryBuffers.INPUT_MSG(i)(0)
-       }
-       for (let i = 0; i < KEY_BYTELENGTH; i++) {
-               MemoryBuffers.INPUT_PRV(i)(0)
-       }
-       for (let i = 0; i < KEY_BYTELENGTH; i++) {
-               MemoryBuffers.INPUT_PUB(i)(0)
-       }
-       for (let i = 0; i < SIGNATURE_BYTELENGTH; i++) {
-               MemoryBuffers.INPUT_SIG(i)(0)
-       }
+       exports.clearMemory()
        locked = false
 }