diff options
author | Tobias Nießen <tniessen@tnie.de> | 2018-10-09 09:36:46 +1100 |
---|---|---|
committer | Tobias Nießen <tniessen@tnie.de> | 2019-09-25 15:58:15 -0300 |
commit | 61743063cccf5b9ec6e1bc85f453bf9d3f83250a (patch) | |
tree | 3565076af52faee203bf55c878af2f64bcd81b12 /test | |
parent | 7333c7163abdf58ffddb8dcbd3f0b43ad1885fdc (diff) | |
download | node-new-61743063cccf5b9ec6e1bc85f453bf9d3f83250a.tar.gz |
crypto: use byteLength in timingSafeEqual
PR-URL: https://github.com/nodejs/node/pull/29657
Co-authored-by: ZaneHannanAU <ZaneHannanAU@users.noreply.github.com>
Co-authored-by: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/sequential/test-crypto-timing-safe-equal.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/test/sequential/test-crypto-timing-safe-equal.js b/test/sequential/test-crypto-timing-safe-equal.js index dcebef29d7..75385e5f88 100644 --- a/test/sequential/test-crypto-timing-safe-equal.js +++ b/test/sequential/test-crypto-timing-safe-equal.js @@ -18,12 +18,26 @@ assert.strictEqual( false ); +{ + // Test TypedArrays with different lengths but equal byteLengths. + const buf = crypto.randomBytes(16).buffer; + const a1 = new Uint8Array(buf); + const a2 = new Uint16Array(buf); + const a3 = new Uint32Array(buf); + + for (const left of [a1, a2, a3]) { + for (const right of [a1, a2, a3]) { + assert.strictEqual(crypto.timingSafeEqual(left, right), true); + } + } +} + common.expectsError( () => crypto.timingSafeEqual(Buffer.from([1, 2, 3]), Buffer.from([1, 2])), { code: 'ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH', type: RangeError, - message: 'Input buffers must have the same length' + message: 'Input buffers must have the same byte length' } ); |