From b033a7a6d4ac6f1d3e20b5d113cca2fd85cacfc3 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 6 Oct 2021 14:54:41 +0530 Subject: fix(ext/crypto): key generation based on AES key length (#12146) --- ext/crypto/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ext/crypto/lib.rs') diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs index 2db629c94..948ef53a1 100644 --- a/ext/crypto/lib.rs +++ b/ext/crypto/lib.rs @@ -222,7 +222,8 @@ pub async fn op_crypto_generate_key( | Algorithm::AesGcm | Algorithm::AesKw => { let length = args.length.ok_or_else(not_supported)?; - let mut key_data = vec![0u8; length]; + // Caller must guarantee divisibility by 8 + let mut key_data = vec![0u8; length / 8]; let rng = RingRand::SystemRandom::new(); rng.fill(&mut key_data).map_err(|_| { custom_error("DOMExceptionOperationError", "Key generation failed") -- cgit v1.2.3