11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common.js'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst { 61cb0ef41Sopenharmony_ci hkdf, 71cb0ef41Sopenharmony_ci hkdfSync, 81cb0ef41Sopenharmony_ci} = require('crypto'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 111cb0ef41Sopenharmony_ci sync: [0, 1], 121cb0ef41Sopenharmony_ci size: [10, 64, 1024], 131cb0ef41Sopenharmony_ci key: ['a', 'secret', 'this-is-a-much-longer-secret'], 141cb0ef41Sopenharmony_ci salt: ['', 'salt'], 151cb0ef41Sopenharmony_ci info: ['', 'info'], 161cb0ef41Sopenharmony_ci hash: ['sha256', 'sha512'], 171cb0ef41Sopenharmony_ci n: [1e3], 181cb0ef41Sopenharmony_ci}); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cifunction measureSync(n, size, salt, info, hash, key) { 211cb0ef41Sopenharmony_ci bench.start(); 221cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) 231cb0ef41Sopenharmony_ci hkdfSync(hash, key, salt, info, size); 241cb0ef41Sopenharmony_ci bench.end(n); 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_cifunction measureAsync(n, size, salt, info, hash, key) { 281cb0ef41Sopenharmony_ci let remaining = n; 291cb0ef41Sopenharmony_ci function done(err) { 301cb0ef41Sopenharmony_ci assert.ifError(err); 311cb0ef41Sopenharmony_ci if (--remaining === 0) 321cb0ef41Sopenharmony_ci bench.end(n); 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci bench.start(); 351cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) 361cb0ef41Sopenharmony_ci hkdf(hash, key, salt, info, size, done); 371cb0ef41Sopenharmony_ci} 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_cifunction main({ n, sync, size, salt, info, hash, key }) { 401cb0ef41Sopenharmony_ci if (sync) 411cb0ef41Sopenharmony_ci measureSync(n, size, salt, info, hash, key); 421cb0ef41Sopenharmony_ci else 431cb0ef41Sopenharmony_ci measureAsync(n, size, salt, info, hash, key); 441cb0ef41Sopenharmony_ci} 45