From: Chris Duncan Date: Sat, 22 Aug 2026 06:28:17 +0000 (-0700) Subject: Revert to retrieving message buffer directly in wasm since it is fully synchronous... X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=165e9953d7f954450f2d26fae19436445e7504e0;p=nano25519.git Revert to retrieving message buffer directly in wasm since it is fully synchronous, has no re-entry points from host JS, and is never written but only read by Blake2b. --- diff --git a/src/assembly/index.ts b/src/assembly/index.ts index 38f8250..3541dc2 100644 --- a/src/assembly/index.ts +++ b/src/assembly/index.ts @@ -63,7 +63,6 @@ export function derive (): void { derive_pub.fill(0) } -const sign_msg = new StaticArray(MESSAGE_BUFFER_BYTES) const sign_prv = new StaticArray(PRIVATEKEY_BYTES) const sign_pub = new StaticArray(PUBLICKEY_BYTES) const sign_sig = new StaticArray(SIGNATURE_BYTES) @@ -86,7 +85,6 @@ export function sign (mlen: i32): void { } // Clear local buffers - sign_msg.fill(0) sign_prv.fill(0) sign_pub.fill(0) sign_sig.fill(0) @@ -97,12 +95,10 @@ export function sign (mlen: i32): void { INPUT_BUFFER.fill(0) // Copy message buffer to local variable, then clear message buffer - memory.copy(changetype(sign_msg), changetype(MESSAGE_BUFFER), mlen) - MESSAGE_BUFFER.fill(0) // Sign, then clear local input - crypto_sign(sign_sig, sign_msg, mlen, sign_prv, sign_pub) - sign_msg.fill(0) + crypto_sign(sign_sig, MESSAGE_BUFFER, mlen, sign_prv, sign_pub) + MESSAGE_BUFFER.fill(0) sign_prv.fill(0) sign_pub.fill(0) @@ -114,7 +110,6 @@ export function sign (mlen: i32): void { sign_sig.fill(0) } -const verify_msg = new StaticArray(MESSAGE_BUFFER_BYTES) const verify_pub = new StaticArray(PUBLICKEY_BYTES) const verify_sig = new StaticArray(SIGNATURE_BYTES) /** @@ -137,7 +132,6 @@ export function verify (mlen: i32): i32 { } // Clear local buffers - verify_msg.fill(0) verify_pub.fill(0) verify_sig.fill(0) @@ -147,12 +141,10 @@ export function verify (mlen: i32): i32 { INPUT_BUFFER.fill(0) // Copy message buffer to local variable, then clear message buffer - memory.copy(changetype(verify_msg), changetype(MESSAGE_BUFFER), mlen) - MESSAGE_BUFFER.fill(0) // Verify, then clear local input - const verified = crypto_verify(verify_sig, verify_msg, mlen, verify_pub) - verify_msg.fill(0) + const verified = crypto_verify(verify_sig, MESSAGE_BUFFER, mlen, verify_pub) + MESSAGE_BUFFER.fill(0) verify_pub.fill(0) verify_sig.fill(0)