]> git.codecow.com Git - nano25519.git/commitdiff
Max out message buffer by allowing 341 blocks instead of 256.
authorChris Duncan <chris@codecow.com>
Thu, 27 Aug 2026 04:56:13 +0000 (21:56 -0700)
committerChris Duncan <chris@codecow.com>
Thu, 27 Aug 2026 04:56:13 +0000 (21:56 -0700)
src/assembly/index.ts
src/index.ts
test/index.html
test/node.mjs

index 348ee372e8ed30d62346a4051b03b8dfe89e6b9b..10af85051ca3aca61773a823affdc8a5bb545084 100644 (file)
@@ -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<usize>(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<usize>(OUTPUT_BUFFER)
 }
@@ -173,12 +173,12 @@ const verify_blocks_out = new StaticArray<u8>(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) {
index 822c44baf0f08aa14efee0ba822c37cbcb4c7d73..8dbb67298575f57b789c818c9f35de46e368c950 100644 (file)
@@ -85,7 +85,7 @@ export function verify (sig: string | Uint8Array<ArrayBuffer>, msg: string | Uin
 /**
  * Nano block signature bulk verification using WebAssembly.
  * @param {Uint8Array<ArrayBuffer>} 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<ArrayBuffer>} blocks.hash - 32-byte block hash
  * @param {Uint8Array<ArrayBuffer>} 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<ArrayBuffer>, 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
index 5f511f863bf282f2eb1d4231316ca3f874c3012a..80a14d6ae159c5877dd8d16fa2de8beb354b5b97 100644 (file)
@@ -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)
index d3ea7aaf42039a2b99d5cd2b9fb52a284f090d07..3f646bc5bce957de0bc6e6e3df3b167c13940a93 100644 (file)
@@ -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
        }