@@ -256,7 +256,10 @@ int AesCbcEncryptDecrypt(EncryptOrDecrypt mode,
256256 const rtc::ArrayView<uint8_t > input,
257257 std::vector<uint8_t >* output) {
258258 const EVP_CIPHER* cipher = GetAesCbcAlgorithmFromKeySize (raw_key.size ());
259- RTC_DCHECK (cipher); // Already handled in Init();
259+ if (!cipher) {
260+ RTC_LOG (LS_ERROR) << " Invalid AES-CBC key size." ;
261+ return ErrorUnexpected;
262+ }
260263 RTC_DCHECK_EQ (EVP_CIPHER_iv_length (cipher), iv.size ());
261264 RTC_DCHECK_EQ (EVP_CIPHER_key_length (cipher), raw_key.size ());
262265
@@ -297,9 +300,13 @@ int AesEncryptDecrypt(EncryptOrDecrypt mode,
297300 switch (algorithm) {
298301 case webrtc::FrameCryptorTransformer::Algorithm::kAesGcm : {
299302 unsigned int tag_length_bits = 128 ;
303+ const EVP_AEAD* cipher = GetAesGcmAlgorithmFromKeySize (raw_key.size ());
304+ if (!cipher) {
305+ RTC_LOG (LS_ERROR) << " Invalid AES-GCM key size." ;
306+ return ErrorUnexpected;
307+ }
300308 return AesGcmEncryptDecrypt (
301- mode, raw_key, data, tag_length_bits / 8 , iv, additional_data,
302- GetAesGcmAlgorithmFromKeySize (raw_key.size ()), buffer);
309+ mode, raw_key, data, tag_length_bits / 8 , iv, additional_data, cipher, buffer);
303310 }
304311 case webrtc::FrameCryptorTransformer::Algorithm::kAesCbc :
305312 return AesCbcEncryptDecrypt (mode, raw_key, iv, data, buffer);
0 commit comments