From: Chris Duncan Date: Wed, 23 Sep 2026 19:41:27 +0000 (-0700) Subject: Clear WASM I/O buffers with host-side call to export instead of using setters and... X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=72974c02ffc4a5bdc23beefca4ab4f821d317d18;p=nano25519.git Clear WASM I/O buffers with host-side call to export instead of using setters and getters. --- diff --git a/src/assembly/index.ts b/src/assembly/index.ts index 5eaf811..d300801 100644 --- a/src/assembly/index.ts +++ b/src/assembly/index.ts @@ -19,6 +19,17 @@ const OUTPUT_DERIVE = new StaticArray(KEY_BYTELENGTH) const OUTPUT_SIGN = new StaticArray(SIGNATURE_BYTELENGTH) const OUTPUT_VERIFY = new StaticArray(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) { diff --git a/src/lib/wasm.ts b/src/lib/wasm.ts index 16e67d2..cb62d4b 100644 --- a/src/lib/wasm.ts +++ b/src/lib/wasm.ts @@ -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 }