-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Add AES-CFB8 cipher support #28526
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
Open
robobun
wants to merge
4
commits into
main
Choose a base branch
from
farm/d8bec1d7/aes-cfb8-cipher
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add AES-CFB8 cipher support #28526
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7a81d19
Add AES-CFB8 cipher support for all key sizes
robobun 983a387
[autofix.ci] apply automated fixes
autofix-ci[bot] 0220074
Address review feedback: scope to CFB8 only, move tests to module
robobun 8c38a62
[autofix.ci] apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| --- a/crypto/cipher/get_cipher.cc | ||
|
Check warning on line 1 in patches/boringssl/expose_aes-cfb8.patch
|
||
| +++ b/crypto/cipher/get_cipher.cc | ||
| @@ -32,17 +32,20 @@ | ||
| } kCiphers[] = { | ||
| {NID_aes_128_cbc, "aes-128-cbc", EVP_aes_128_cbc}, | ||
| {NID_aes_128_cfb128, "aes-128-cfb", EVP_aes_128_cfb128}, | ||
| + {NID_aes_128_cfb8, "aes-128-cfb8", EVP_aes_128_cfb8}, | ||
| {NID_aes_128_ctr, "aes-128-ctr", EVP_aes_128_ctr}, | ||
| {NID_aes_128_ecb, "aes-128-ecb", EVP_aes_128_ecb}, | ||
| {NID_aes_128_gcm, "aes-128-gcm", EVP_aes_128_gcm}, | ||
| {NID_aes_128_ofb128, "aes-128-ofb", EVP_aes_128_ofb}, | ||
| {NID_aes_192_cbc, "aes-192-cbc", EVP_aes_192_cbc}, | ||
| + {NID_aes_192_cfb8, "aes-192-cfb8", EVP_aes_192_cfb8}, | ||
| {NID_aes_192_ctr, "aes-192-ctr", EVP_aes_192_ctr}, | ||
| {NID_aes_192_ecb, "aes-192-ecb", EVP_aes_192_ecb}, | ||
| {NID_aes_192_gcm, "aes-192-gcm", EVP_aes_192_gcm}, | ||
| {NID_aes_192_ofb128, "aes-192-ofb", EVP_aes_192_ofb}, | ||
| {NID_aes_256_cbc, "aes-256-cbc", EVP_aes_256_cbc}, | ||
| {NID_aes_256_cfb128, "aes-256-cfb", EVP_aes_256_cfb128}, | ||
| + {NID_aes_256_cfb8, "aes-256-cfb8", EVP_aes_256_cfb8}, | ||
| {NID_aes_256_ctr, "aes-256-ctr", EVP_aes_256_ctr}, | ||
| {NID_aes_256_ecb, "aes-256-ecb", EVP_aes_256_ecb}, | ||
| {NID_aes_256_gcm, "aes-256-gcm", EVP_aes_256_gcm}, | ||
| --- a/decrepit/cfb/cfb.cc | ||
| +++ b/decrepit/cfb/cfb.cc | ||
| @@ -19,6 +19,7 @@ | ||
| #include <openssl/aes.h> | ||
| #include <openssl/obj.h> | ||
|
|
||
| +#include "../../crypto/fipsmodule/aes/internal.h" | ||
| #include "../../crypto/fipsmodule/cipher/internal.h" | ||
| #include "../../crypto/internal.h" | ||
|
|
||
| @@ -102,3 +103,74 @@ | ||
| const EVP_CIPHER *EVP_aes_192_cfb() { return &aes_192_cfb128; } | ||
| const EVP_CIPHER *EVP_aes_256_cfb128() { return &aes_256_cfb128; } | ||
| const EVP_CIPHER *EVP_aes_256_cfb() { return &aes_256_cfb128; } | ||
| + | ||
| +// CFB8 mode — processes 8 bits (1 byte) at a time. | ||
| + | ||
| +static void aes_encrypt_block(const uint8_t in[16], uint8_t out[16], | ||
| + const AES_KEY *key) { | ||
| + AES_encrypt(in, out, key); | ||
| +} | ||
| + | ||
| +static int aes_cfb8_cipher_update(EVP_CIPHER_CTX *ctx, uint8_t *out, | ||
| + const uint8_t *in, size_t len) { | ||
| + if (!out || !in) { | ||
| + return 0; | ||
| + } | ||
| + | ||
| + EVP_CFB_CTX *cfb_ctx = reinterpret_cast<EVP_CFB_CTX *>(ctx->cipher_data); | ||
| + unsigned num = 0; | ||
| + bssl::CRYPTO_cfb128_8_encrypt(in, out, len, &cfb_ctx->ks, ctx->iv, &num, | ||
| + ctx->encrypt ? AES_ENCRYPT : AES_DECRYPT, | ||
| + aes_encrypt_block); | ||
| + | ||
| + return 1; | ||
| +} | ||
| + | ||
| +static const EVP_CIPHER aes_128_cfb8 = { | ||
| + /* nid= */ NID_aes_128_cfb8, | ||
| + /* block_size= */ 1, | ||
| + /* key_len= */ 16, | ||
| + /* iv_len= */ 16, | ||
| + /* ctx_size= */ sizeof(EVP_CFB_CTX), | ||
| + /* flags= */ EVP_CIPH_CFB_MODE, | ||
| + /* init= */ aes_cfb_init_key, | ||
| + /* cipher_update= */ aes_cfb8_cipher_update, | ||
| + /* cipher_final= */ nullptr, | ||
| + /* update_aad= */ nullptr, | ||
| + /* cleanup= */ nullptr, | ||
| + /* ctrl= */ nullptr, | ||
| +}; | ||
| + | ||
| +static const EVP_CIPHER aes_192_cfb8 = { | ||
| + /* nid= */ NID_aes_192_cfb8, | ||
| + /* block_size= */ 1, | ||
| + /* key_len= */ 24, | ||
| + /* iv_len= */ 16, | ||
| + /* ctx_size= */ sizeof(EVP_CFB_CTX), | ||
| + /* flags= */ EVP_CIPH_CFB_MODE, | ||
| + /* init= */ aes_cfb_init_key, | ||
| + /* cipher_update= */ aes_cfb8_cipher_update, | ||
| + /* cipher_final= */ nullptr, | ||
| + /* update_aad= */ nullptr, | ||
| + /* cleanup= */ nullptr, | ||
| + /* ctrl= */ nullptr, | ||
| +}; | ||
| + | ||
| +static const EVP_CIPHER aes_256_cfb8 = { | ||
| + /* nid= */ NID_aes_256_cfb8, | ||
| + /* block_size= */ 1, | ||
| + /* key_len= */ 32, | ||
| + /* iv_len= */ 16, | ||
| + /* ctx_size= */ sizeof(EVP_CFB_CTX), | ||
| + /* flags= */ EVP_CIPH_CFB_MODE, | ||
| + /* init= */ aes_cfb_init_key, | ||
| + /* cipher_update= */ aes_cfb8_cipher_update, | ||
| + /* cipher_final= */ nullptr, | ||
| + /* update_aad= */ nullptr, | ||
| + /* cleanup= */ nullptr, | ||
| + /* ctrl= */ nullptr, | ||
| +}; | ||
| + | ||
| +const EVP_CIPHER *EVP_aes_128_cfb8() { return &aes_128_cfb8; } | ||
| +const EVP_CIPHER *EVP_aes_192_cfb8() { return &aes_192_cfb8; } | ||
| +const EVP_CIPHER *EVP_aes_256_cfb8() { return &aes_256_cfb8; } | ||
| --- a/decrepit/evp/evp_do_all.cc | ||
| +++ b/decrepit/evp/evp_do_all.cc | ||
| @@ -23,17 +23,20 @@ | ||
| // Cipher lookups are case-insensitive, so uppercase names are not needed. | ||
| callback(EVP_aes_128_cbc(), "aes-128-cbc", nullptr, arg); | ||
| callback(EVP_aes_128_cfb128(), "aes-128-cfb", nullptr, arg); | ||
| + callback(EVP_aes_128_cfb8(), "aes-128-cfb8", nullptr, arg); | ||
| callback(EVP_aes_128_ctr(), "aes-128-ctr", nullptr, arg); | ||
| callback(EVP_aes_128_ecb(), "aes-128-ecb", nullptr, arg); | ||
| callback(EVP_aes_128_gcm(), "aes-128-gcm", nullptr, arg); | ||
| callback(EVP_aes_128_ofb(), "aes-128-ofb", nullptr, arg); | ||
| callback(EVP_aes_192_cbc(), "aes-192-cbc", nullptr, arg); | ||
| + callback(EVP_aes_192_cfb8(), "aes-192-cfb8", nullptr, arg); | ||
| callback(EVP_aes_192_ctr(), "aes-192-ctr", nullptr, arg); | ||
| callback(EVP_aes_192_ecb(), "aes-192-ecb", nullptr, arg); | ||
| callback(EVP_aes_192_gcm(), "aes-192-gcm", nullptr, arg); | ||
| callback(EVP_aes_192_ofb(), "aes-192-ofb", nullptr, arg); | ||
| callback(EVP_aes_256_cbc(), "aes-256-cbc", nullptr, arg); | ||
| callback(EVP_aes_256_cfb128(), "aes-256-cfb", nullptr, arg); | ||
| + callback(EVP_aes_256_cfb8(), "aes-256-cfb8", nullptr, arg); | ||
| callback(EVP_aes_256_ctr(), "aes-256-ctr", nullptr, arg); | ||
| callback(EVP_aes_256_ecb(), "aes-256-ecb", nullptr, arg); | ||
| callback(EVP_aes_256_gcm(), "aes-256-gcm", nullptr, arg); | ||
| --- a/include/openssl/cipher.h | ||
| +++ b/include/openssl/cipher.h | ||
| @@ -572,6 +572,15 @@ | ||
| // decrepit. | ||
| OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_256_cfb(void); | ||
|
|
||
| +// EVP_aes_128_cfb8 is only available in decrepit. | ||
| +OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_128_cfb8(void); | ||
| + | ||
| +// EVP_aes_192_cfb8 is only available in decrepit. | ||
| +OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_192_cfb8(void); | ||
| + | ||
| +// EVP_aes_256_cfb8 is only available in decrepit. | ||
| +OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_256_cfb8(void); | ||
| + | ||
| // EVP_bf_ecb is Blowfish in ECB mode and is only available in decrepit. | ||
| OPENSSL_EXPORT const EVP_CIPHER *EVP_bf_ecb(void); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.