From: Chris Duncan Date: Thu, 27 Aug 2026 04:56:13 +0000 (-0700) Subject: Max out message buffer by allowing 341 blocks instead of 256. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=272b308c3d5356ef93162d4bc95dd8c83c840d0d;p=nano25519.git Max out message buffer by allowing 341 blocks instead of 256. --- diff --git a/src/assembly/index.ts b/src/assembly/index.ts index 348ee37..10af850 100644 --- a/src/assembly/index.ts +++ b/src/assembly/index.ts @@ -12,7 +12,7 @@ export const SIGNATURE_BYTELENGTH: i32 = 64 export const MESSAGE_BUFFER_BYTELENGTH: i32 = BLOCKHASH_BYTELENGTH << 10 export const PRV_BUFFER_BYTELENGTH: i32 = KEY_BYTELENGTH export const PUB_BUFFER_BYTELENGTH: i32 = KEY_BYTELENGTH -export const OUTPUT_BUFFER_BYTELENGTH: i32 = 256 +export const OUTPUT_BUFFER_BYTELENGTH: i32 = 341 export const SIGNATURE_BUFFER_BYTELENGTH: i32 = SIGNATURE_BYTELENGTH // Static I/O buffers @@ -27,7 +27,7 @@ export function getMessagePointer (): usize { return changetype(MESSAGE_BUFFER) } -/** Returns the pointer to the static output buffer (256 bytes). */ +/** Returns the pointer to the static output buffer (341 bytes). */ export function getOutputPointer (): usize { return changetype(OUTPUT_BUFFER) } @@ -173,12 +173,12 @@ const verify_blocks_out = new StaticArray(OUTPUT_BUFFER_BYTELENGTH) * * The message buffer holds both the block hash and the signature buffer as a * 96-byte concatenated value. The 32 KiB message buffer cannot be divided - * evenly by 96, so a conservative 24 KiB is used which supports up to 256 block - * hash/signature pairs. + * evenly by 96, so up to 341 block hash/signature pairs are supported with an + * extra 32 bytes left at the end. * * All pairs are verified against a single public key. The results are written * to the output buffer in the same order they were received. - * @param {i32} count Number of signatures to verify, up to 256 + * @param {i32} count Number of signatures to verify, up to 341 */ export function verify_blocks (count: i32): void { if (count < 1 || OUTPUT_BUFFER_BYTELENGTH < count) { diff --git a/src/index.ts b/src/index.ts index 822c44b..8dbb672 100644 --- a/src/index.ts +++ b/src/index.ts @@ -85,7 +85,7 @@ export function verify (sig: string | Uint8Array, msg: string | Uin /** * Nano block signature bulk verification using WebAssembly. * @param {Uint8Array} publicKey - 32-byte public key - * @param {object[]} blocks - Array of up to 256 block hash/signature pairs + * @param {object[]} blocks - Array of up to 341 block hash/signature pairs * @param {Uint8Array} blocks.hash - 32-byte block hash * @param {Uint8Array} blocks.signature - 64-byte block signature * @returns Array of results with, for each case, true if signature matches block hash and public key, else false @@ -94,7 +94,7 @@ export function verify_blocks (publicKey: Uint8Array, blocks: { has /** * Nano block signature bulk verification using WebAssembly. * @param {string} publicKey - 64-character hexadecimal public key - * @param {object[]} blocks - Array of up to 256 block hash/signature pairs + * @param {object[]} blocks - Array of up to 341 block hash/signature pairs * @param {string} blocks.hash - 64-character hexadecimal block hash * @param {string} blocks.signature - 128-character hexadecimal block signature * @returns Array of results with, for each case, true if signature matches block hash and public key, else false diff --git a/test/index.html b/test/index.html index 5f511f8..80a14d6 100644 --- a/test/index.html +++ b/test/index.html @@ -382,7 +382,7 @@ SPDX-License-Identifier: GPL-3.0-or-later publicKey = derive(privateKey, 'nano25519') signature = sign(blockHash, privateKey, publicKey, 'nano25519') const blocks = [] - for (let i = 0; i < 256; i++) { + for (let i = 0; i < 341; i++) { blocks[i] = { hash: blockHash, signature } } start = performance.now() @@ -391,7 +391,7 @@ SPDX-License-Identifier: GPL-3.0-or-later if (verified.some(v => v !== true)) { throw new Error(`invalid result\nsignature: ${signature}\nblock hash: ${blockHash}\npublic key: ${publicKey}`) } - duration = (end - start) / 256 + duration = (end - start) / 341 deriveTimes[i].push(0) signTimes[i].push(0) verifyTimes[i].push(duration) diff --git a/test/node.mjs b/test/node.mjs index d3ea7aa..3f646bc 100644 --- a/test/node.mjs +++ b/test/node.mjs @@ -385,7 +385,7 @@ failures += +!test try { const blocks = [] - for (let i = 0; i < 256; i++) { + for (let i = 0; i < 341; i++) { blocks[i] = { hash: NANO_ORG_VECTOR.blockHashBytes, signature: NANO_ORG_VECTOR.signatureBytes } } const verified = verify_blocks(NANO_ORG_VECTOR.publicKeyBytes, blocks) @@ -395,7 +395,7 @@ try { result = false } test = result === true -check(`verify_blocks 256 max`, test) +check(`verify_blocks 341 max`, test) passes += +test failures += +!test @@ -420,14 +420,14 @@ failures += +!test try { const blocks = [] - for (let i = 0; i < 257; i++) { + for (let i = 0; i < 342; i++) { blocks[i] = { hash: NANO_ORG_VECTOR.blockHashBytes, signature: NANO_ORG_VECTOR.signatureBytes } } verify_blocks(NANO_ORG_VECTOR.publicKeyBytes, blocks) result = false } catch (err) { if (err != null && typeof err === 'object' && 'message' in err) { - result = err.message === 'Bulk Nano block verification must be no more than 256 blocks' + result = err.message === 'Bulk Nano block verification must be no more than 341 blocks' } else { result = false }