Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove aes cbc for framecryptor. #145

Open
wants to merge 1 commit into
base: m125_release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 3 additions & 44 deletions api/crypto/frame_crypto_transformer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,46 +250,6 @@ int AesGcmEncryptDecrypt(EncryptOrDecrypt mode,
return Success;
}

int AesCbcEncryptDecrypt(EncryptOrDecrypt mode,
const std::vector<uint8_t>& raw_key,
rtc::ArrayView<uint8_t> iv,
const rtc::ArrayView<uint8_t> input,
std::vector<uint8_t>* output) {
const EVP_CIPHER* cipher = GetAesCbcAlgorithmFromKeySize(raw_key.size());
if (!cipher) {
RTC_LOG(LS_ERROR) << "Invalid AES-CBC key size.";
return ErrorUnexpected;
}
RTC_DCHECK_EQ(EVP_CIPHER_iv_length(cipher), iv.size());
RTC_DCHECK_EQ(EVP_CIPHER_key_length(cipher), raw_key.size());

bssl::ScopedEVP_CIPHER_CTX ctx;
if (!EVP_CipherInit_ex(ctx.get(), cipher, nullptr,
reinterpret_cast<const uint8_t*>(raw_key.data()),
iv.data(),
mode == EncryptOrDecrypt::kEncrypt ? 1 : 0)) {
return OperationError;
}

// Encrypting needs a block size of space to allow for any padding.
output->resize(input.size() +
(mode == EncryptOrDecrypt::kEncrypt ? iv.size() : 0));
int out_len;
if (!EVP_CipherUpdate(ctx.get(), output->data(), &out_len, input.data(),
input.size()))
return OperationError;

// Write out the final block plus padding (if any) to the end of the data
// just written.
int tail_len;
if (!EVP_CipherFinal_ex(ctx.get(), output->data() + out_len, &tail_len))
return OperationError;

out_len += tail_len;
RTC_CHECK_LE(out_len, static_cast<int>(output->size()));
return Success;
}

int AesEncryptDecrypt(EncryptOrDecrypt mode,
webrtc::FrameCryptorTransformer::Algorithm algorithm,
const std::vector<uint8_t>& raw_key,
Expand All @@ -308,8 +268,9 @@ int AesEncryptDecrypt(EncryptOrDecrypt mode,
return AesGcmEncryptDecrypt(
mode, raw_key, data, tag_length_bits / 8, iv, additional_data, cipher, buffer);
}
case webrtc::FrameCryptorTransformer::Algorithm::kAesCbc:
return AesCbcEncryptDecrypt(mode, raw_key, iv, data, buffer);
default:
RTC_LOG(LS_ERROR) << "Unsupported algorithm.";
return ErrorUnexpected;
}
}
namespace webrtc {
Expand Down Expand Up @@ -724,8 +685,6 @@ uint8_t FrameCryptorTransformer::getIvSize() {
switch (algorithm_) {
case Algorithm::kAesGcm:
return 12;
case Algorithm::kAesCbc:
return 16;
default:
return 0;
}
Expand Down
1 change: 0 additions & 1 deletion sdk/android/api/org/webrtc/FrameCryptorAlgorithm.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@

public enum FrameCryptorAlgorithm {
AES_GCM,
AES_CBC,
}
2 changes: 0 additions & 2 deletions sdk/android/src/jni/pc/frame_cryptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ webrtc::FrameCryptorTransformer::Algorithm AlgorithmFromIndex(int index) {
switch (index) {
case 0:
return webrtc::FrameCryptorTransformer::Algorithm::kAesGcm;
case 1:
return webrtc::FrameCryptorTransformer::Algorithm::kAesCbc;
default:
return webrtc::FrameCryptorTransformer::Algorithm::kAesGcm;
}
Expand Down
1 change: 0 additions & 1 deletion sdk/objc/api/peerconnection/RTCFrameCryptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, RTCCryptorAlgorithm) {
RTCCryptorAlgorithmAesGcm = 0,
RTCCryptorAlgorithmAesCbc,
};

typedef NS_ENUM(NSInteger, FrameCryptionState) {
Expand Down
2 changes: 0 additions & 2 deletions sdk/objc/api/peerconnection/RTCFrameCryptor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ @implementation RTC_OBJC_TYPE (RTCFrameCryptor) {
switch (algorithm) {
case RTCCryptorAlgorithmAesGcm:
return webrtc::FrameCryptorTransformer::Algorithm::kAesGcm;
case RTCCryptorAlgorithmAesCbc:
return webrtc::FrameCryptorTransformer::Algorithm::kAesCbc;
default:
return webrtc::FrameCryptorTransformer::Algorithm::kAesGcm;
}
Expand Down