Missing parameters for key generation
Context used for key generation is associated with NULL parameters
Description
This defect occurs when you perform a key generation step with a context object without first associating the object with required parameters.
For instance, you associate a EVP_PKEY_CTX context object with an
            empty EVP_PKEY object params before key generation
            :
            
EVP_PKEY * params = EVP_PKEY_new(); ... EVP_PKEY_CTX * ctx = EVP_PKEY_CTX_new(params, NULL); ... EVP_PKEY_keygen(ctx, &pkey);
Risk
Without appropriate parameters, the key generation step does not occur. The redundant operation often indicates a coding error.
Fix
Check the placement of the key generation step. If the operation is intended, make sure that the parameters are set before key generation.
Certain algorithms use default parameters. For instance, if you specify the DSA
                algorithm when creating the EVP_PKEY_CTX object, a default key
                length of 1024 bits is
                used:
kctx = EVP_PKEY_CTX_new_id(EVP_PKEY_DSA, NULL);
However, the default parameters can generate keys that are too weak for encryption. Weak parameters can trigger another defect. To change default parameters, use functions specific to the algorithm. For instance, to set parameters, you can use these functions:
- Diffie-Hellman (DH): Use - EVP_PKEY_CTX_set_dh_paramgen_prime_lenand- EVP_PKEY_CTX_set_dh_paramgen_generator.
- Digital Signature Algorithm (DSA): Use - EVP_PKEY_CTX_set_dsa_paramgen_bits.
- RSA: Use - EVP_PKEY_CTX_set_rsa_padding,- EVP_PKEY_CTX_set_rsa_pss_saltlen,- EVP_PKEY_CTX_set_rsa_rsa_keygen_bits, and- EVP_PKEY_CTX_set_rsa_keygen_pubexp.
- Elliptic curve (EC): Use - EVP_PKEY_CTX_set_ec_paramgen_curve_nidand- EVP_PKEY_CTX_set_ec_param_enc.
Examples
Result Information
| Group: Cryptography | 
| Language: C | C++ | 
| Default: Off | 
| Command-Line Syntax: CRYPTO_PKEY_NO_PARAMS | 
| Impact: Medium | 
Version History
Introduced in R2018a
See Also
Context
                initialized incorrectly for cryptographic operation | Incorrect key for
                cryptographic algorithm | Missing data for
                encryption, decryption or signing | Missing peer
                key | Missing private
                key | Missing public
                key | Nonsecure
                parameters for key generation | Find defects (-checkers)
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)