Skip to content

Add AES CBC cipher to speed.cc #2315

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

Merged
merged 2 commits into from
Apr 23, 2025
Merged
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
11 changes: 8 additions & 3 deletions tool/speed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,9 @@ static bool SpeedEvpGenericChunk(const EVP_CIPHER *cipher, std::string name,
result &= EVP_EncryptUpdate(ctx.get(), NULL, len_ptr, ad.get(), ad_len);
}
result &= EVP_EncryptUpdate(ctx.get(), ciphertext, len_ptr, plaintext, chunk_byte_len);
int ciphertext_len = *len_ptr;
result &= EVP_EncryptFinal_ex(ctx.get(), ciphertext + *len_ptr, len_ptr);
ciphertext_len += *len_ptr;
if(isAead) {
result &= EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_GET_TAG, 16, tag);
}
Expand All @@ -580,16 +582,16 @@ static bool SpeedEvpGenericChunk(const EVP_CIPHER *cipher, std::string name,
ERR_print_errors_fp(stderr);
return false;
}
if (!TimeFunction(&decryptResults, [&ctx, chunk_byte_len, plaintext, ciphertext, len_ptr, tag, &nonce, &ad, ad_len, &isAead, &result]() -> bool {
if (!TimeFunction(&decryptResults, [&ctx, plaintext, ciphertext, len_ptr, tag, &nonce, &ad, ad_len, &isAead, &result, &ciphertext_len]() -> bool {
result = EVP_DecryptInit_ex(ctx.get(), NULL, NULL, NULL, nonce.get());
if(isAead) {
result &= EVP_DecryptUpdate(ctx.get(), NULL, len_ptr, ad.get(), ad_len);
}
result &= EVP_DecryptUpdate(ctx.get(), plaintext, len_ptr, ciphertext, chunk_byte_len);
result &= EVP_DecryptUpdate(ctx.get(), plaintext, len_ptr, ciphertext, ciphertext_len);
if (isAead) {
result &= EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_SET_TAG, 16, tag);
}
result &= EVP_DecryptFinal_ex(ctx.get(), ciphertext + *len_ptr, len_ptr);
result &= EVP_DecryptFinal_ex(ctx.get(), plaintext + *len_ptr, len_ptr);
return result;
})) {
fprintf(stderr, "%s failed.\n", decryptName.c_str());
Expand Down Expand Up @@ -2875,6 +2877,9 @@ bool Speed(const std::vector<std::string> &args) {
!SpeedEvpCipherGeneric(EVP_aes_128_ctr(), "EVP-AES-128-CTR", kTLSADLen, selected) ||
!SpeedEvpCipherGeneric(EVP_aes_192_ctr(), "EVP-AES-192-CTR", kTLSADLen, selected) ||
!SpeedEvpCipherGeneric(EVP_aes_256_ctr(), "EVP-AES-256-CTR", kTLSADLen, selected) ||
!SpeedEvpCipherGeneric(EVP_aes_128_cbc(), "EVP-AES-128-CBC", kTLSADLen, selected) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what padding is used here? ISO10126 or PKCSv1.5?

Not a concern for this change, but ACCP supports ISO10126 for CBC, and if we could offload that padding to an AWS-LC API, it'd be a nice simplification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out this isn't obvious what is used: cipher.h says standard padding is used. Reading the code this uses RFC 5652/PKCS 7 padding (each padding byte value is the number of padding bytes).

!SpeedEvpCipherGeneric(EVP_aes_192_cbc(), "EVP-AES-192-CBC", kTLSADLen, selected) ||
!SpeedEvpCipherGeneric(EVP_aes_256_cbc(), "EVP-AES-256-CBC", kTLSADLen, selected) ||
!SpeedAES256XTS("AES-256-XTS", selected) ||
#if !defined(OPENSSL_3_0_BENCHMARK)
// OpenSSL 3.0 deprecated RC4
Expand Down
Loading