summaryrefslogtreecommitdiff
path: root/ext/node/ops/crypto/cipher.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-08-28 18:34:18 +0530
committerGitHub <noreply@github.com>2024-08-28 18:34:18 +0530
commit3394c4df751229b6ce2349e84dccdee26faecb67 (patch)
treeff18b6c9489e7e04ea7e3689e316698d5932f858 /ext/node/ops/crypto/cipher.rs
parent44238955fb3c70074e7bc8191efdf3e0143bed16 (diff)
fix(ext/node): update aead-gcm-stream to 0.3 (#25261)
Fixes https://github.com/denoland/deno/issues/25260 Fixes https://github.com/denoland/deno/issues/25254 Fixes https://github.com/denoland/deno/issues/23693 Verified that `web-push` GCM decryption works in the browser. See `aead-gcm-stream` changes [here](https://github.com/littledivy/aead-gcm-stream/commit/a9ffd0c07c14e4b566c87bf51a20ff799b9e7f5e)
Diffstat (limited to 'ext/node/ops/crypto/cipher.rs')
-rw-r--r--ext/node/ops/crypto/cipher.rs36
1 files changed, 24 insertions, 12 deletions
diff --git a/ext/node/ops/crypto/cipher.rs b/ext/node/ops/crypto/cipher.rs
index ca13fdcd8..94bd5780e 100644
--- a/ext/node/ops/crypto/cipher.rs
+++ b/ext/node/ops/crypto/cipher.rs
@@ -137,16 +137,22 @@ impl Cipher {
"aes-192-ecb" => Aes192Ecb(Box::new(ecb::Encryptor::new(key.into()))),
"aes-256-ecb" => Aes256Ecb(Box::new(ecb::Encryptor::new(key.into()))),
"aes-128-gcm" => {
- let mut cipher =
- aead_gcm_stream::AesGcm::<aes::Aes128>::new(key.into());
- cipher.init(iv.try_into()?);
+ if iv.len() != 12 {
+ return Err(type_error("IV length must be 12 bytes"));
+ }
+
+ let cipher =
+ aead_gcm_stream::AesGcm::<aes::Aes128>::new(key.into(), iv);
Aes128Gcm(Box::new(cipher))
}
"aes-256-gcm" => {
- let mut cipher =
- aead_gcm_stream::AesGcm::<aes::Aes256>::new(key.into());
- cipher.init(iv.try_into()?);
+ if iv.len() != 12 {
+ return Err(type_error("IV length must be 12 bytes"));
+ }
+
+ let cipher =
+ aead_gcm_stream::AesGcm::<aes::Aes256>::new(key.into(), iv);
Aes256Gcm(Box::new(cipher))
}
@@ -320,16 +326,22 @@ impl Decipher {
"aes-192-ecb" => Aes192Ecb(Box::new(ecb::Decryptor::new(key.into()))),
"aes-256-ecb" => Aes256Ecb(Box::new(ecb::Decryptor::new(key.into()))),
"aes-128-gcm" => {
- let mut decipher =
- aead_gcm_stream::AesGcm::<aes::Aes128>::new(key.into());
- decipher.init(iv.try_into()?);
+ if iv.len() != 12 {
+ return Err(type_error("IV length must be 12 bytes"));
+ }
+
+ let decipher =
+ aead_gcm_stream::AesGcm::<aes::Aes128>::new(key.into(), iv);
Aes128Gcm(Box::new(decipher))
}
"aes-256-gcm" => {
- let mut decipher =
- aead_gcm_stream::AesGcm::<aes::Aes256>::new(key.into());
- decipher.init(iv.try_into()?);
+ if iv.len() != 12 {
+ return Err(type_error("IV length must be 12 bytes"));
+ }
+
+ let decipher =
+ aead_gcm_stream::AesGcm::<aes::Aes256>::new(key.into(), iv);
Aes256Gcm(Box::new(decipher))
}