Context used for cryptography operation is associated with NULL public key or not associated with a public key at all
This defect occurs when you use a context object for encryption or signature authentication but you have not previously associated the object with a non-NULL public key.
For instance, you initialize the context object with a NULL public key and use the object for encryption later.
ctx = EVP_PKEY_CTX_new(pkey, NULL); ... ret = EVP_PKEY_encrypt_init(ctx); ... ret = EVP_PKEY_encrypt(ctx, out, &out_len, in, in_len);
The counterpart checker Missing private
key checks for a private key in decryption and signature
operations.
Without a public key, the encryption or signature authentication step does not happen. The redundant operation often indicates a coding error.
Check the placement of the operation (encryption or signature authentication). If the operation is intended to happen, make sure you have done these steps prior to the operation:
You generated a non-NULL public key.
For instance:
EVP_PKEY *pkey = NULL; kctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL); EVP_PKEY_keygen_init(kctx); EVP_PKEY_CTX_set_rsa_keygen_bits(kctx, RSA_2048BITS); EVP_PKEY_keygen(kctx, &pkey);
You associated a non-NULL context object with the public key.
For instance:
ctx = EVP_PKEY_CTX_new(pkey, NULL);
Note: If you use EVP_PKEY_CTX_new_id instead of
EVP_PKEY_CTX_new, you are not associating the
context object with a public key.
| Group: Cryptography |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax:
CRYPTO_PKEY_NO_PUBLIC_KEY |
| Impact: Medium |
| CWE ID: 310, 320, 573, 664 |
Context
initialized incorrectly for cryptographic operation | Find defects (-checkers) | Incorrect key for
cryptographic algorithm | Missing data for
encryption, decryption or signing | Missing
parameters for key generation | Missing peer
key | Missing private
key | Nonsecure
parameters for key generation