Context initialized incorrectly for cryptographic operation
Context used for public key cryptography operation is initialized for a different operation
Description
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
.
Risk
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.
Fix
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 withEVP_PKEY_encrypt_init
.For signature verification with
EVP_PKEY_verify
, initialize the context withEVP_PKEY_verify_init
.For key generation with
EVP_PKEY_keygen
, initialize the context withEVP_PKEY_keygen_init
.
If you want to reuse an existing context object for a different family of operations, reinitialize the context.
Examples
Result Information
Group: Cryptography |
Language: C | C++ |
Default: Off |
Command-Line Syntax:
CRYPTO_PKEY_INCORRECT_INIT |
Impact: Medium |
Version History
Introduced in R2018a
See Also
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
| 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)