summaryrefslogtreecommitdiff
path: root/ext/crypto/00_crypto.js
diff options
context:
space:
mode:
authorFilip Skokan <panva.ip@gmail.com>2022-10-04 13:24:05 +0200
committerGitHub <noreply@github.com>2022-10-04 16:54:05 +0530
commitfd08b13dff9743926c0f6045ca0c7958d55048da (patch)
treeae768698751420258370f1b4e4f2be08a2d816c2 /ext/crypto/00_crypto.js
parent8d20784f7adc1eee6cd58f1b797263fc19d07327 (diff)
fix(ext/crypto): ECDH and X25519 non byte length and 0 length fixes (#16146)
Diffstat (limited to 'ext/crypto/00_crypto.js')
-rw-r--r--ext/crypto/00_crypto.js15
1 files changed, 6 insertions, 9 deletions
diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js
index 5826132d2..907308325 100644
--- a/ext/crypto/00_crypto.js
+++ b/ext/crypto/00_crypto.js
@@ -27,6 +27,7 @@
Int8ArrayPrototype,
JSONParse,
JSONStringify,
+ MathCeil,
ObjectAssign,
ObjectPrototypeIsPrototypeOf,
StringPrototypeToLowerCase,
@@ -4396,14 +4397,11 @@
// 8.
if (length === null) {
return buf.buffer;
- }
- if (
- length === 0 || buf.buffer.byteLength * 8 < length ||
- length % 8 !== 0
- ) {
+ } else if (buf.buffer.byteLength * 8 < length) {
throw new DOMException("Invalid length", "OperationError");
+ } else {
+ return buf.buffer.slice(0, MathCeil(length / 8));
}
- return buf.buffer.slice(0, length / 8);
} else {
throw new DOMException("Not implemented", "NotSupportedError");
}
@@ -4469,12 +4467,11 @@
if (length === null) {
return secret.buffer;
} else if (
- length === 0 || secret.buffer.byteLength * 8 < length ||
- secret.length * 8 < length
+ secret.buffer.byteLength * 8 < length
) {
throw new DOMException("Invalid length", "OperationError");
} else {
- return secret.subarray(0, length / 8).buffer;
+ return secret.buffer.slice(0, MathCeil(length / 8));
}
}
default: