1EVP_PKEY_DECRYPT(3ossl)             OpenSSL            EVP_PKEY_DECRYPT(3ossl)
2
3
4

NAME

6       EVP_PKEY_decrypt_init, EVP_PKEY_decrypt_init_ex, EVP_PKEY_decrypt -
7       decrypt using a public key algorithm
8

SYNOPSIS

10        #include <openssl/evp.h>
11
12        int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx);
13        int EVP_PKEY_decrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
14        int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx,
15                             unsigned char *out, size_t *outlen,
16                             const unsigned char *in, size_t inlen);
17

DESCRIPTION

19       The EVP_PKEY_decrypt_init() function initializes a public key algorithm
20       context using key pkey for a decryption operation.
21
22       The EVP_PKEY_decrypt_init_ex() function initializes a public key
23       algorithm context using key pkey for a decryption operation and sets
24       the algorithm specific params.
25
26       The EVP_PKEY_decrypt() function performs a public key decryption
27       operation using ctx. The data to be decrypted is specified using the in
28       and inlen parameters. If out is NULL then the minimum required size of
29       the output buffer is written to the *outlen parameter.
30
31       If out is not NULL then before the call the *outlen parameter must
32       contain the length of the out buffer. If the call is successful the
33       decrypted data is written to out and the amount of the decrypted data
34       written to *outlen, otherwise an error is returned.
35

NOTES

37       After the call to EVP_PKEY_decrypt_init() algorithm specific control
38       operations can be performed to set any appropriate parameters for the
39       operation.  These operations can be included in the
40       EVP_PKEY_decrypt_init_ex() call.
41
42       The function EVP_PKEY_decrypt() can be called more than once on the
43       same context if several operations are performed using the same
44       parameters.
45

RETURN VALUES

47       EVP_PKEY_decrypt_init(), EVP_PKEY_decrypt_init_ex() and
48       EVP_PKEY_decrypt() return 1 for success and 0 or a negative value for
49       failure. In particular a return value of -2 indicates the operation is
50       not supported by the public key algorithm.
51

WARNINGS

53       In OpenSSL versions before 3.1.0, when used in PKCS#1 v1.5 padding,
54       both the return value from the EVP_PKEY_decrypt() and the outlen
55       provided information useful in mounting a Bleichenbacher attack against
56       the used private key. They had to processed in a side-channel free way.
57
58       Since version 3.1.0, the EVP_PKEY_decrypt() method when used with
59       PKCS#1 v1.5 padding doesn't return an error in case it detects an error
60       in padding, instead it returns a pseudo-randomly generated message,
61       removing the need of side-channel secure code from applications using
62       OpenSSL.
63

EXAMPLES

65       Decrypt data using OAEP (for RSA keys):
66
67        #include <openssl/evp.h>
68        #include <openssl/rsa.h>
69
70        EVP_PKEY_CTX *ctx;
71        ENGINE *eng;
72        unsigned char *out, *in;
73        size_t outlen, inlen;
74        EVP_PKEY *key;
75
76        /*
77         * NB: assumes key, eng, in, inlen are already set up
78         * and that key is an RSA private key
79         */
80        ctx = EVP_PKEY_CTX_new(key, eng);
81        if (!ctx)
82            /* Error occurred */
83        if (EVP_PKEY_decrypt_init(ctx) <= 0)
84            /* Error */
85        if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0)
86            /* Error */
87
88        /* Determine buffer length */
89        if (EVP_PKEY_decrypt(ctx, NULL, &outlen, in, inlen) <= 0)
90            /* Error */
91
92        out = OPENSSL_malloc(outlen);
93
94        if (!out)
95            /* malloc failure */
96
97        if (EVP_PKEY_decrypt(ctx, out, &outlen, in, inlen) <= 0)
98            /* Error */
99
100        /* Decrypted data is outlen bytes written to buffer out */
101

SEE ALSO

103       EVP_PKEY_CTX_new(3), EVP_PKEY_encrypt(3), EVP_PKEY_sign(3),
104       EVP_PKEY_verify(3), EVP_PKEY_verify_recover(3), EVP_PKEY_derive(3)
105

HISTORY

107       These functions were added in OpenSSL 1.0.0.
108
110       Copyright 2006-2022 The OpenSSL Project Authors. All Rights Reserved.
111
112       Licensed under the Apache License 2.0 (the "License").  You may not use
113       this file except in compliance with the License.  You can obtain a copy
114       in the file LICENSE in the source distribution or at
115       <https://www.openssl.org/source/license.html>.
116
117
118
1193.0.9                             2023-07-27           EVP_PKEY_DECRYPT(3ossl)
Impressum