Fix migration guide mappings for i2o/o2i_ECPublicKey
[openssl.git] / doc / man3 / EVP_PKEY_decrypt.pod
1 =pod
2
3 =head1 NAME
4
5 EVP_PKEY_decrypt_init, EVP_PKEY_decrypt_init_ex,
6 EVP_PKEY_decrypt - decrypt using a public key algorithm
7
8 =head1 SYNOPSIS
9
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
18 =head1 DESCRIPTION
19
20 The EVP_PKEY_decrypt_init() function initializes a public key algorithm
21 context using key B<pkey> for a decryption operation.
22
23 The EVP_PKEY_decrypt_init_ex() function initializes a public key algorithm
24 context using key B<pkey> for a decryption operation and sets the
25 algorithm specific B<params>.
26
27 The EVP_PKEY_decrypt() function performs a public key decryption operation
28 using B<ctx>. The data to be decrypted is specified using the B<in> and
29 B<inlen> parameters. If B<out> is B<NULL> then the maximum size of the output
30 buffer is written to the B<outlen> parameter. If B<out> is not B<NULL> then
31 before the call the B<outlen> parameter should contain the length of the
32 B<out> buffer, if the call is successful the decrypted data is written to
33 B<out> and the amount of data written to B<outlen>.
34
35 =head1 NOTES
36
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 EVP_PKEY_decrypt_init_ex()
40 call.
41
42 The function EVP_PKEY_decrypt() can be called more than once on the same
43 context if several operations are performed using the same parameters.
44
45 =head1 RETURN VALUES
46
47 EVP_PKEY_decrypt_init(), EVP_PKEY_decrypt_init_ex() and EVP_PKEY_decrypt()
48 return 1 for success and 0 or a negative value for failure. In particular a
49 return value of -2 indicates the operation is not supported by the public key
50 algorithm.
51
52 =head1 EXAMPLES
53
54 Decrypt data using OAEP (for RSA keys):
55
56  #include <openssl/evp.h>
57  #include <openssl/rsa.h>
58
59  EVP_PKEY_CTX *ctx;
60  ENGINE *eng;
61  unsigned char *out, *in;
62  size_t outlen, inlen;
63  EVP_PKEY *key;
64
65  /*
66   * NB: assumes key, eng, in, inlen are already set up
67   * and that key is an RSA private key
68   */
69  ctx = EVP_PKEY_CTX_new(key, eng);
70  if (!ctx)
71      /* Error occurred */
72  if (EVP_PKEY_decrypt_init(ctx) <= 0)
73      /* Error */
74  if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_OAEP_PADDING) <= 0)
75      /* Error */
76
77  /* Determine buffer length */
78  if (EVP_PKEY_decrypt(ctx, NULL, &outlen, in, inlen) <= 0)
79      /* Error */
80
81  out = OPENSSL_malloc(outlen);
82
83  if (!out)
84      /* malloc failure */
85
86  if (EVP_PKEY_decrypt(ctx, out, &outlen, in, inlen) <= 0)
87      /* Error */
88
89  /* Decrypted data is outlen bytes written to buffer out */
90
91 =head1 SEE ALSO
92
93 L<EVP_PKEY_CTX_new(3)>,
94 L<EVP_PKEY_encrypt(3)>,
95 L<EVP_PKEY_sign(3)>,
96 L<EVP_PKEY_verify(3)>,
97 L<EVP_PKEY_verify_recover(3)>,
98 L<EVP_PKEY_derive(3)>
99
100 =head1 HISTORY
101
102 These functions were added in OpenSSL 1.0.0.
103
104 =head1 COPYRIGHT
105
106 Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
107
108 Licensed under the Apache License 2.0 (the "License").  You may not use
109 this file except in compliance with the License.  You can obtain a copy
110 in the file LICENSE in the source distribution or at
111 L<https://www.openssl.org/source/license.html>.
112
113 =cut