From 9c8a9317721c2de6d7501f976f88c796524e56bd Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 25 Sep 2026 09:48:13 -0700 Subject: [PATCH] Add custom message byte length to speed test page. --- test/index.html | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/test/index.html b/test/index.html index 9dafca9..3ab659e 100644 --- a/test/index.html +++ b/test/index.html @@ -49,6 +49,7 @@ SPDX-License-Identifier: GPL-3.0-or-later if (nano25519 && NANO_ORG_VECTOR && PYTHON_ED25519_BLAKE2B_VECTORS) { console.info('Test vectors loaded') document.getElementById('btnStartTest').disabled = false + document.getElementById('btnStartTest').focus() document.getElementById('status').innerHTML = `READY` } @@ -114,9 +115,11 @@ SPDX-License-Identifier: GPL-3.0-or-later } /** @type { { bytes: Uint8Array, hex: string } } */ - const rand32 = { - get bytes() { return crypto.getRandomValues(new Uint8Array(32)) }, - get hex() { return b2a(this.bytes) } + const rand = (length = 32) => { + return { + get bytes() { return crypto.getRandomValues(new Uint8Array(length)) }, + get hex() { return b2a(this.bytes) } + } } /** @type { (hex: string) => Uint8Array } */ @@ -223,7 +226,13 @@ SPDX-License-Identifier: GPL-3.0-or-later * @param {number} runs * @returns {void} */ - export async function test(api, size, runs) { + export async function test(api, bytes, size, runs) { + if (typeof bytes !== 'number' || bytes < 1) { + bytes = 1 + } + if (bytes > 65536) { + bytes = 65536 + } if (typeof size !== 'number' || size < 1) { size = 1 } @@ -351,7 +360,7 @@ SPDX-License-Identifier: GPL-3.0-or-later passes += +test failures += +!test - result = nano25519.verify(NANO_ORG_VECTOR.signature, rand32.hex, NANO_ORG_VECTOR.publicKey) + result = nano25519.verify(NANO_ORG_VECTOR.signature, rand(32).hex, NANO_ORG_VECTOR.publicKey) console.log(result) test = result === false check(`verify() output for random block hash`, test) @@ -408,11 +417,11 @@ SPDX-License-Identifier: GPL-3.0-or-later try { if (api === 'nano25519 with bulk block verification') { - privateKey = rand32.bytes + privateKey = rand(32).bytes publicKey = derive(privateKey, 'nano25519') const blocks = [] for (let b = 0; b < nano25519.constants.MAX_VERIFY_BLOCKS; b++) { - message = rand32.bytes + message = rand(32).bytes signature = sign(message, privateKey, publicKey, 'nano25519') blocks[b] = { hash: message, signature } } @@ -429,8 +438,8 @@ SPDX-License-Identifier: GPL-3.0-or-later signTimes[i].push(0) verifyTimes[i].push(duration) } else { - privateKey = rand32.bytes - message = crypto.getRandomValues(new Uint8Array(32768)) + privateKey = rand(32).bytes + message = rand(bytes).bytes start = performance.now() publicKey = derive(privateKey, api) @@ -484,13 +493,17 @@ SPDX-License-Identifier: GPL-3.0-or-later } function startValidation(event) { + const bytes = document.getElementById('bytes') const size = document.getElementById('size') const api = document.getElementById('api')?.value if (api === 'nano25519 with bulk block verification') { + bytes.value = nano25519.constants.BLOCKHASH_BYTELENGTH + bytes.disabled = true size.value = nano25519.constants.MAX_VERIFY_BLOCKS size.dataset.value = 1 size.disabled = true } else { + bytes.disabled = false size.value = 100 size.dataset.value = 0 size.disabled = false @@ -517,9 +530,10 @@ SPDX-License-Identifier: GPL-3.0-or-later function startTest(event) { event.target.disabled = true const api = document.getElementById('api') + const bytes = document.getElementById('bytes') const size = document.getElementById('size') const runs = document.getElementById('runs') - test(api.value, +size.dataset.value ? 1 : +size.value, +runs.value) + test(api.value, +bytes.value, +size.dataset.value ? 1 : +size.value, +runs.value) .then(() => { event.target.disabled = false }) @@ -579,10 +593,12 @@ SPDX-License-Identifier: GPL-3.0-or-later + + - + - +

LOADING

-- 2.52.0