2018-11-01 14:55:52 +01:00
|
|
|
/* eslint-disable no-console */
|
2016-09-13 13:23:11 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const Benchmark = require('benchmark')
|
|
|
|
const crypto = require('../src')
|
|
|
|
|
|
|
|
const suite = new Benchmark.Suite('ephemeral-keys')
|
|
|
|
|
|
|
|
const secrets = []
|
|
|
|
const curves = ['P-256', 'P-384', 'P-521']
|
|
|
|
|
|
|
|
curves.forEach((curve) => {
|
|
|
|
suite.add(`ephemeral key with secrect ${curve}`, (d) => {
|
2017-07-22 10:57:27 -07:00
|
|
|
crypto.keys.generateEphemeralKeyPair('P-256', (err, res) => {
|
|
|
|
if (err) { throw err }
|
2016-09-13 13:23:11 +02:00
|
|
|
res.genSharedKey(res.key, (err, secret) => {
|
2017-07-22 10:57:27 -07:00
|
|
|
if (err) { throw err }
|
2016-09-13 13:23:11 +02:00
|
|
|
secrets.push(secret)
|
|
|
|
|
|
|
|
d.resolve()
|
|
|
|
})
|
|
|
|
})
|
2017-07-22 10:57:27 -07:00
|
|
|
}, { defer: true })
|
2016-09-13 13:23:11 +02:00
|
|
|
})
|
|
|
|
|
2017-09-05 15:28:43 +02:00
|
|
|
suite
|
|
|
|
.on('cycle', (event) => console.log(String(event.target)))
|
2019-01-03 08:13:07 -08:00
|
|
|
.run({ async: true })
|