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