You perform encryption and decryption steps in succession with the same cipher context without a reinitialization in between
This defect occurs when you perform an encryption and decryption step with the same cipher context. You do not reinitialize the context in between those steps. The checker applies to symmetric encryption only.
For instance, you set up a cipher context for decryption using EVP_DecryptInit_ex.
EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, key, iv);
EVP_EncryptUpdate.EVP_EncryptUpdate(ctx, out_buf, &out_len, src, len);
Mixing up encryption and decryption steps can lead to obscure code. It is difficult to determine at a glance whether the current cipher context is used for encryption or decryption. The mixup can also lead to race conditions, failed encryption, and unexpected ciphertext.
After you set up a cipher context for a certain family of operations, use the context for only that family of operations.
For instance, if you set up a cipher context for decryption
using EVP_DecryptInit_ex, use the context afterward
for decryption only.
| Group: Cryptography |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax: CRYPTO_CIPHER_BAD_FUNCTION |
| Impact: Medium |
| CWE ID: 372, 664 |