-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: make timingSafeEqual faster for Uint8Array
Add a fast API that V8 can use if the user supplies Uint8Arrays (including Buffers) to timingSafeEqual. PR-URL: #52341 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
1 parent
1b4d281
commit 0f784c9
Showing
3 changed files
with
52 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const assert = require('node:assert'); | ||
const { randomBytes, timingSafeEqual } = require('node:crypto'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e5], | ||
bufferSize: [10, 100, 200, 2_100, 22_023], | ||
}); | ||
|
||
function main({ n, bufferSize }) { | ||
const bufs = [randomBytes(bufferSize), randomBytes(bufferSize)]; | ||
bench.start(); | ||
let count = 0; | ||
for (let i = 0; i < n; i++) { | ||
const ret = timingSafeEqual(bufs[i % 2], bufs[1]); | ||
if (ret) count++; | ||
} | ||
bench.end(n); | ||
assert.strictEqual(count, Math.floor(n / 2)); | ||
} |
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