summaryrefslogtreecommitdiff
path: root/ext/crypto/00_crypto.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/crypto/00_crypto.js')
-rw-r--r--ext/crypto/00_crypto.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js
index 0a78bff2f..5d216dbf4 100644
--- a/ext/crypto/00_crypto.js
+++ b/ext/crypto/00_crypto.js
@@ -126,10 +126,12 @@
"encrypt": {
"RSA-OAEP": "RsaOaepParams",
"AES-CBC": "AesCbcParams",
+ "AES-CTR": "AesCtrParams",
},
"decrypt": {
"RSA-OAEP": "RsaOaepParams",
"AES-CBC": "AesCbcParams",
+ "AES-CTR": "AesCtrParams",
},
"get key length": {
"AES-CBC": "AesDerivedKeyParams",
@@ -605,6 +607,39 @@
// 6.
return plainText.buffer;
}
+ case "AES-CTR": {
+ normalizedAlgorithm.counter = copyBuffer(normalizedAlgorithm.counter);
+
+ // 1.
+ if (normalizedAlgorithm.counter.byteLength !== 16) {
+ throw new DOMException(
+ "Counter vector must be 16 bytes",
+ "OperationError",
+ );
+ }
+
+ // 2.
+ if (
+ normalizedAlgorithm.length === 0 || normalizedAlgorithm.length > 128
+ ) {
+ throw new DOMException(
+ "Counter length must not be 0 or greater than 128",
+ "OperationError",
+ );
+ }
+
+ // 3.
+ const cipherText = await core.opAsync("op_crypto_decrypt", {
+ key: keyData,
+ algorithm: "AES-CTR",
+ keyLength: key[_algorithm].length,
+ counter: normalizedAlgorithm.counter,
+ ctrLength: normalizedAlgorithm.length,
+ }, data);
+
+ // 4.
+ return cipherText.buffer;
+ }
default:
throw new DOMException("Not implemented", "NotSupportedError");
}
@@ -3431,6 +3466,39 @@
// 4.
return cipherText.buffer;
}
+ case "AES-CTR": {
+ normalizedAlgorithm.counter = copyBuffer(normalizedAlgorithm.counter);
+
+ // 1.
+ if (normalizedAlgorithm.counter.byteLength !== 16) {
+ throw new DOMException(
+ "Counter vector must be 16 bytes",
+ "OperationError",
+ );
+ }
+
+ // 2.
+ if (
+ normalizedAlgorithm.length == 0 || normalizedAlgorithm.length > 128
+ ) {
+ throw new DOMException(
+ "Counter length must not be 0 or greater than 128",
+ "OperationError",
+ );
+ }
+
+ // 3.
+ const cipherText = await core.opAsync("op_crypto_encrypt", {
+ key: keyData,
+ algorithm: "AES-CTR",
+ keyLength: key[_algorithm].length,
+ counter: normalizedAlgorithm.counter,
+ ctrLength: normalizedAlgorithm.length,
+ }, data);
+
+ // 4.
+ return cipherText.buffer;
+ }
default:
throw new DOMException("Not implemented", "NotSupportedError");
}