-
-
Save panva/7d4c54c9e2de3c4daa310ba6719cf98b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { sign, verify, generateKeyPairSync } = require('crypto') | |
const Benchmark = require('benchmark') | |
const ecdsaSignatures = require('./lib/help/ecdsa_signatures') | |
const { privateKey, publicKey } = generateKeyPairSync('ec', { namedCurve: 'P-256' }) | |
let suite = new Benchmark.Suite() | |
const PAYLOAD = Buffer.from('foo') | |
const SIGNATURE = sign('sha256', PAYLOAD, { | |
key: privateKey, | |
dsaEncoding: 'ieee-p1363' | |
}) | |
suite.add('sign ieee-p1363 via dsaEncoding', () => { | |
sign('sha256', PAYLOAD, { | |
key: privateKey, | |
dsaEncoding: 'ieee-p1363' | |
}) | |
}) | |
.add('sign ieee-p1363 via module', () => { | |
ecdsaSignatures.derToJose(sign('sha256', PAYLOAD, { | |
key: privateKey | |
}), 'ES256') | |
}) | |
.on('cycle', (event) => { | |
console.log(String(event.target)) | |
}) | |
.on('complete', function () { | |
console.log('Fastest is ' + this.filter('fastest').map('name')) | |
}) | |
.run() | |
suite = new Benchmark.Suite() | |
suite.add('verify ieee-p1363 via dsaEncoding', () => { | |
verify('sha256', PAYLOAD, { | |
key: publicKey, | |
dsaEncoding: 'ieee-p1363' | |
}, SIGNATURE) | |
}) | |
.add('verify ieee-p1363 via module', () => { | |
verify('sha256', PAYLOAD, { | |
key: publicKey | |
}, ecdsaSignatures.joseToDer(SIGNATURE, 'ES256')) | |
}) | |
.on('cycle', (event) => { | |
console.log(String(event.target)) | |
}) | |
.on('complete', function () { | |
console.log('Fastest is ' + this.filter('fastest').map('name')) | |
}) | |
.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment