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