Skip to content

Commit

Permalink
fix(ext/crypto): ECDH and X25519 non byte length and 0 length fixes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Oct 4, 2022
1 parent 8d20784 commit fd08b13
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions ext/crypto/00_crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 27,7 @@
Int8ArrayPrototype,
JSONParse,
JSONStringify,
MathCeil,
ObjectAssign,
ObjectPrototypeIsPrototypeOf,
StringPrototypeToLowerCase,
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit fd08b13

Please sign in to comment.