1
0
mirror of https://github.com/fluencelabs/js-libp2p-crypto synced 2025-03-31 18:31:20 +00:00

41 lines
941 B
JavaScript
Raw Normal View History

2018-11-01 14:55:52 +01:00
/* eslint-disable no-console */
'use strict'
const Benchmark = require('benchmark')
2016-11-07 11:37:32 +01:00
const async = require('async')
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']
2016-11-07 11:37:32 +01:00
async.waterfall([
2017-07-22 10:57:27 -07:00
(cb) => crypto.keys.generateEphemeralKeyPair('P-256', cb),
2016-11-07 11:37:32 +01:00
(res, cb) => res.genSharedKey(res.key, cb)
], (err, secret) => {
2017-07-22 10:57:27 -07:00
if (err) { throw err }
2016-11-07 11:37:32 +01:00
ciphers.forEach((cipher) => hashes.forEach((hash) => {
setup(cipher, hash, secret)
}))
suite
.on('cycle', (event) => console.log(String(event.target)))
.run({async: true})
})
2016-11-07 11:37:32 +01:00
function setup (cipher, hash, secret) {
suite.add(`keyStretcher ${cipher} ${hash}`, (d) => {
2017-07-22 10:57:27 -07:00
crypto.keys.keyStretcher(cipher, hash, secret, (err, k) => {
if (err) { throw err }
2016-11-07 11:37:32 +01:00
keys.push(k)
d.resolve()
})
2017-07-22 10:57:27 -07:00
}, { defer: true })
2016-11-07 11:37:32 +01:00
}