-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
260 additions
and
290 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import compare from 'micro-bmark/compare.js'; | ||
import crypto from 'node:crypto'; | ||
// Noble | ||
import { hkdf } from '@noble/hashes/hkdf'; | ||
import { sha256 } from '@noble/hashes/sha256'; | ||
import { sha512 } from '@noble/hashes/sha512'; | ||
// Others | ||
import { HKDF as stableHKDF } from '@stablelib/hkdf'; | ||
import stable256 from '@stablelib/sha256'; | ||
import stable512 from '@stablelib/sha512'; | ||
|
||
const [password, salt] = [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])]; | ||
|
||
const HKDF = { | ||
'HKDF-SHA256': { | ||
node: (len) => crypto.hkdfSync('sha256', password, salt, new Uint8Array(), len), | ||
stable: (len) => new stableHKDF(stable256.SHA256, password, salt, undefined).expand(len), | ||
noble: (len) => hkdf(sha256, salt, password, undefined, len), | ||
}, | ||
'HKDF-SHA512': { | ||
node: (len) => crypto.hkdfSync('sha512', password, salt, new Uint8Array(), len), | ||
stable: (len) => new stableHKDF(stable512.SHA512, password, salt, undefined).expand(len), | ||
noble: (len) => hkdf(sha512, salt, password, undefined, len), | ||
}, | ||
}; | ||
|
||
async function main() { | ||
// Usage: | ||
// - basic: node hkdf.js | ||
// - sha256 only: MBENCH_FILTER=SHA256 node hkdf.js | ||
// - full: MBENCH_DIMS='length,algorithm,library' MBENCH_FILTER=SHA256 node hkdf.js | ||
await compare('Hashes', { length: { 32: 32, 64: 64, 256: 256 } }, HKDF, { | ||
libDims: ['algorithm', 'library'], | ||
defaults: { library: 'noble', buffer: '32B' }, | ||
samples: (length) => { | ||
if (length <= 64) return 100_000; | ||
return 25_000; | ||
}, | ||
}); | ||
} | ||
|
||
import url from 'node:url'; | ||
if (import.meta.url === url.pathToFileURL(process.argv[1]).href) { | ||
main(); | ||
} |
Oops, something went wrong.