mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
crypto: fix webcrypto deriveBits for non-byte lengths
PR-URL: https://github.com/nodejs/node/pull/43431 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
e0fedcfb18
commit
3ee0bb8d03
3 files changed
+6
-6
No files matched your search
@@ -3,7 +3,7 @@
|
||||
const {
|
||||
ArrayBufferPrototypeSlice,
|
||||
FunctionPrototypeCall,
|
||||
MathFloor,
|
||||
MathCeil,
|
||||
ObjectDefineProperty,
|
||||
Promise,
|
||||
SafeSet,
|
||||
@@ -386,9 +386,9 @@ async function asyncDeriveBitsECDH(algorithm, baseKey, length) {
|
||||
if (length === null)
|
||||
return bits;
|
||||
|
||||
// If the length is not a multiple of 8, it will be truncated
|
||||
// down to the nearest multiple of 8.
|
||||
length = MathFloor(length / 8);
|
||||
// If the length is not a multiple of 8 the nearest ceiled
|
||||
// multiple of 8 is sliced.
|
||||
length = MathCeil(length / 8);
|
||||
const { byteLength } = bits;
|
||||
|
||||
// If the length is larger than the derived secret, throw.
|
||||
|
||||
@@ -133,7 +133,7 @@ async function prepareKeys() {
|
||||
|
||||
assert.strictEqual(
|
||||
Buffer.from(bits).toString('hex'),
|
||||
result.slice(0, -4));
|
||||
result.slice(0, -2));
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ async function prepareKeys() {
|
||||
|
||||
assert.strictEqual(
|
||||
Buffer.from(bits).toString('hex'),
|
||||
result.slice(0, -4));
|
||||
result.slice(0, -2));
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
Reference in new issue
Block a user