Incorrect key for cryptographic algorithm
Public key cryptography operation is not supported by the algorithm used in context initialization
Description
This defect occurs when you initialize a context object with a key for a specific algorithm but perform an operation that the algorithm does not support.
For instance, you initialize the context with a key for the DSA algorithm.
ret = EVP_PKEY_set1_DSA(pkey,dsa); ctx = EVP_PKEY_CTX_new(pkey, NULL);
ret = EVP_PKEY_encrypt(ctx,out, &out_len, in, in_len);
Risk
If the algorithm does not support your cryptographic operation, you do not see the expected results. For instance, if you use the DSA algorithm for encryption, you might get unexpected ciphertext.
Fix
Use the algorithm that is appropriate for the cryptographic operation that you want to perform:
Diffie-Hellman (DH): For key derivation.
Digital Signature Algorithm (DSA): For signature.
RSA: For encryption and signature.
Elliptic curve (EC): For key derivation and signature.
Examples
Result Information
Group: Cryptography |
Language: C | C++ |
Default: Off |
Command-Line Syntax:
CRYPTO_PKEY_INCORRECT_KEY |
Impact: Medium |
Version History
Introduced in R2018a
See Also
Context
initialized incorrectly for cryptographic operation
| 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
| 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)