Context used for digest operation is initialized for a different digest operation
This defect
occurs when you initialize an EVP_MD_CTX context object for a
specific digest operation but use the context for a different operation.
For instance, you initialize the context for creating a message digest only.
ret = EVP_DigestInit(ctx, EVP_sha256())
ret = EVP_SignFinal(&ctx, out, &out_len, pkey);
EVP_DigestUpdate works identically to
EVP_SignUpdate.Mixing up different operations on the same context can lead to obscure code. It is difficult to determine at a glance whether the current object is used for message digest creation, signing, or verification. The mixup can also lead to a failure in the operation or unexpected message digest.
After you set up a context for a certain family of operations, use the context for only that family of operations. For instance, use these pairs of functions for initialization and final steps.
EVP_DigestInit :
EVP_DigestFinal
EVP_DigestInit_ex :
EVP_DigestFinal_ex
EVP_DigestSignInit :
EVP_DigestSignFinal
If you want to reuse an existing context object for a different family of operations, reinitialize the context.
| Group: Cryptography |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax:
CRYPTO_MD_BAD_FUNCTION |
| Impact: Medium |
| CWE ID: 310, 353, 354, 372, 573, 664 |