Context used for public key cryptography operation is initialized for a different operation
This defect occurs when you initialize an EVP_PKEY_CTX
object for a specific public key cryptography operation but use the object for a
different operation.
For instance, you initialize the context for encryption.
ret = EVP_PKEY_encrypt_init(ctx);
ret = EVP_PKEY_decrypt(ctx, out, &out_len, in, in_len);
The checker detects if the context object used in these functions has been initialized
by using the corresponding initialization functions:
EVP_PKEY_paramgen, EVP_PKEY_keygen,
EVP_PKEY_encrypt, EVP_PKEY_verify,
EVP_PKEY_verify_recover,EVP_PKEY_decrypt,
EVP_PKEY_sign, EVP_PKEY_derive,and
EVP_PKEY_derive_set_peer.
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 encryption, decryption, signature, or another operation. The mixup can also lead to a failure in the operation or unexpected ciphertext.
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 usage of the EVP_PKEY_CTX context object.
For encryption with EVP_PKEY_encrypt, initialize
the context with EVP_PKEY_encrypt_init.
For signature verification with EVP_PKEY_verify,
initialize the context with EVP_PKEY_verify_init.
For key generation with EVP_PKEY_keygen, initialize
the context with EVP_PKEY_keygen_init.
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_PKEY_INCORRECT_INIT |
| Impact: Medium |
| CWE ID: 310, 325, 372, 573, 664 |
Find defects (-checkers) | Incorrect key for
cryptographic algorithm | Missing data for
encryption, decryption or signing operation | Missing
parameters for key generation | Missing peer
key | Missing private
key | Missing public
key | Nonsecure
parameters for key generation