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')
|
2016-11-07 11:37:32 +01:00
|
|
|
|
2016-09-13 13:23:11 +02:00
|
|
|
const crypto = require('../src')
|
|
|
|
|
|
|
|
const suite = new Benchmark.Suite('key-stretcher')
|
|
|
|
|
|
|
|
const keys = []
|
|
|
|
|
|
|
|
const ciphers = ['AES-128', 'AES-256', 'Blowfish']
|
|
|
|
const hashes = ['SHA1', 'SHA256', 'SHA512']
|
|
|
|
|
2019-07-10 17:15:26 +01:00
|
|
|
;(async () => {
|
|
|
|
const res = await crypto.keys.generateEphemeralKeyPair('P-256')
|
|
|
|
const secret = await res.genSharedKey(res.key)
|
2016-09-13 13:23:11 +02:00
|
|
|
|
2016-11-07 11:37:32 +01:00
|
|
|
ciphers.forEach((cipher) => hashes.forEach((hash) => {
|
|
|
|
setup(cipher, hash, secret)
|
|
|
|
}))
|
|
|
|
|
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 })
|
2019-07-10 17:15:26 +01:00
|
|
|
})()
|
2016-10-03 23:15:21 +11:00
|
|
|
|
2016-11-07 11:37:32 +01:00
|
|
|
function setup (cipher, hash, secret) {
|
2019-07-10 17:15:26 +01:00
|
|
|
suite.add(`keyStretcher ${cipher} ${hash}`, async (d) => {
|
|
|
|
const k = await crypto.keys.keyStretcher(cipher, hash, secret)
|
|
|
|
keys.push(k)
|
|
|
|
d.resolve()
|
2017-07-22 10:57:27 -07:00
|
|
|
}, { defer: true })
|
2016-11-07 11:37:32 +01:00
|
|
|
}
|