Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 42ed07a

Browse files
authoredNov 30, 2021
chore: precompute table before benchmark (#217)
`@noble/ed25519` precomputes a wNAF table of scalar multiplication on the first invocation of `getPublicKey` so do that ahead of time to stop it affecting the relative margin of error.
1 parent b792d48 commit 42ed07a

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed
 

‎benchmarks/ed25519/index.js

+32-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require('node-forge/lib/ed25519')
1010
const forge = require('node-forge/lib/forge')
1111
const stable = require('@stablelib/ed25519')
1212
const supercopWasm = require('supercop.wasm')
13+
const ed25519WasmPro = require('ed25519-wasm-pro')
1314

1415
const suite = new Benchmark.Suite('ed25519 implementations')
1516

@@ -62,7 +63,21 @@ suite.add('supercop.wasm', async (d) => {
6263
const isSigned = await supercopWasm.verify(signature, message, keys.publicKey)
6364

6465
if (!isSigned) {
65-
throw new Error('could not verify noble signature')
66+
throw new Error('could not verify supercop.wasm signature')
67+
}
68+
69+
d.resolve()
70+
}, { defer: true })
71+
72+
suite.add('ed25519-wasm-pro', async (d) => {
73+
const message = Buffer.from('hello world ' + Math.random())
74+
const seed = ed25519WasmPro.createSeed()
75+
const keys = ed25519WasmPro.createKeyPair(seed)
76+
const signature = ed25519WasmPro.sign(message, keys.publicKey, keys.secretKey)
77+
const isSigned = await ed25519WasmPro.verify(signature, message, keys.publicKey)
78+
79+
if (!isSigned) {
80+
throw new Error('could not verify ed25519-wasm-pro signature')
6681
}
6782

6883
d.resolve()
@@ -100,14 +115,22 @@ suite.add('node.js web-crypto', async (d) => {
100115
}, { defer: true })
101116

102117
async function main () {
103-
supercopWasm.ready(() => {
104-
suite
105-
.on('cycle', (event) => console.log(String(event.target)))
106-
.on('complete', function () {
107-
console.log('fastest is ' + this.filter('fastest').map('name'))
108-
})
109-
.run({ async: true })
110-
})
118+
await Promise.all([
119+
new Promise((resolve) => {
120+
supercopWasm.ready(() => resolve())
121+
}),
122+
new Promise((resolve) => {
123+
ed25519WasmPro.ready(() => resolve())
124+
})
125+
])
126+
noble.utils.precompute(8)
127+
128+
suite
129+
.on('cycle', (event) => console.log(String(event.target)))
130+
.on('complete', function () {
131+
console.log('fastest is ' + this.filter('fastest').map('name'))
132+
})
133+
.run({ async: true })
111134
}
112135

113136
main()

‎benchmarks/ed25519/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@stablelib/ed25519": "^1.0.2",
1313
"benchmark": "^2.1.4",
1414
"ed25519": "^0.0.5",
15+
"ed25519-wasm-pro": "^1.1.1",
1516
"iso-random-stream": "^2.0.0",
1617
"node-forge": "^0.10.0",
1718
"supercop.wasm": "^5.0.1"

0 commit comments

Comments
 (0)
This repository has been archived.