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`
}
}
/** @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 } */
* @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
}
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)
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 }
}
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)
}
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
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
})
<option>TweetNaCl.js</option>
</select>
</span>
+ <label for="bytes">Message Bytes</label>
+ <input id="bytes" type="number" value="32" min="1" max="65536" />
<label for="runs">Test Runs</label>
- <input id="runs" type="number" value="100" min="1" autofocus />
+ <input id="runs" type="number" value="100" min="1" />
<label for="size">Test Size</label>
- <input id="size" type="number" value="100" min="1" autofocus />
+ <input id="size" type="number" value="100" min="1" />
<button id="btnStartTest" disabled>Go</button>
<hr />
<h3 id="status">LOADING</h3>