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  christos EVP_PKEY_decapsulate_init, EVP_PKEY_decapsulate
      6  1.2  christos - Key decapsulation using a KEM algorithm with a private key
      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_decapsulate_init(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
     13  1.1  christos  int EVP_PKEY_decapsulate(EVP_PKEY_CTX *ctx,
     14  1.2  christos                           unsigned char *unwrapped, size_t *unwrappedlen,
     15  1.1  christos                           const unsigned char *wrapped, size_t wrappedlen);
     16  1.1  christos 
     17  1.1  christos =head1 DESCRIPTION
     18  1.1  christos 
     19  1.1  christos The EVP_PKEY_decapsulate_init() function initializes a private key algorithm
     20  1.1  christos context I<ctx> for a decapsulation operation and then sets the I<params>
     21  1.1  christos on the context in the same way as calling L<EVP_PKEY_CTX_set_params(3)>.
     22  1.2  christos Note that I<ctx> usually is produced using L<EVP_PKEY_CTX_new_from_pkey(3)>,
     23  1.2  christos specifying the private key to use.
     24  1.1  christos 
     25  1.1  christos The EVP_PKEY_decapsulate() function performs a private key decapsulation
     26  1.1  christos operation using I<ctx>. The data to be decapsulated is specified using the
     27  1.1  christos I<wrapped> and I<wrappedlen> parameters.
     28  1.3  christos If I<unwrapped> is NULL then the size of the output secret buffer
     29  1.2  christos is written to I<*unwrappedlen>. If I<unwrapped> is not NULL and the
     30  1.2  christos call is successful then the decapsulated secret data is written to I<unwrapped>
     31  1.3  christos and the amount of data written to I<*unwrappedlen>.  Note that, if I<unwrappedlen>
     32  1.3  christos is not NULL in this call, the value it points to must be initialised to the length of
     33  1.3  christos I<unwrapped>, so that the call can validate it is of sufficient size to hold the
     34  1.3  christos result of the operation.
     35  1.1  christos 
     36  1.1  christos =head1 NOTES
     37  1.1  christos 
     38  1.2  christos After the call to EVP_PKEY_decapsulate_init() algorithm-specific parameters
     39  1.1  christos for the operation may be set or modified using L<EVP_PKEY_CTX_set_params(3)>.
     40  1.1  christos 
     41  1.1  christos =head1 RETURN VALUES
     42  1.1  christos 
     43  1.1  christos EVP_PKEY_decapsulate_init() and EVP_PKEY_decapsulate() return 1 for
     44  1.1  christos success and 0 or a negative value for failure. In particular a return value of -2
     45  1.1  christos indicates the operation is not supported by the private key algorithm.
     46  1.1  christos 
     47  1.1  christos =head1 EXAMPLES
     48  1.1  christos 
     49  1.1  christos Decapsulate data using RSA:
     50  1.1  christos 
     51  1.1  christos  #include <openssl/evp.h>
     52  1.1  christos 
     53  1.1  christos  /*
     54  1.1  christos   * NB: assumes rsa_priv_key is an RSA private key,
     55  1.1  christos   * and that in, inlen are already set up to contain encapsulated data.
     56  1.1  christos   */
     57  1.1  christos 
     58  1.1  christos  EVP_PKEY_CTX *ctx = NULL;
     59  1.1  christos  size_t secretlen = 0;
     60  1.1  christos  unsigned char *secret = NULL;;
     61  1.1  christos 
     62  1.1  christos  ctx = EVP_PKEY_CTX_new_from_pkey(libctx, rsa_priv_key, NULL);
     63  1.3  christos  if (ctx == NULL)
     64  1.1  christos      /* Error */
     65  1.1  christos  if (EVP_PKEY_decapsulate_init(ctx, NULL) <= 0)
     66  1.1  christos      /* Error */
     67  1.1  christos 
     68  1.1  christos  /* Set the mode - only 'RSASVE' is currently supported */
     69  1.1  christos  if (EVP_PKEY_CTX_set_kem_op(ctx, "RSASVE") <= 0)
     70  1.1  christos      /* Error */
     71  1.1  christos 
     72  1.1  christos  /* Determine buffer length */
     73  1.1  christos  if (EVP_PKEY_decapsulate(ctx, NULL, &secretlen, in, inlen) <= 0)
     74  1.1  christos      /* Error */
     75  1.1  christos 
     76  1.1  christos  secret = OPENSSL_malloc(secretlen);
     77  1.1  christos  if (secret == NULL)
     78  1.1  christos      /* malloc failure */
     79  1.1  christos 
     80  1.1  christos  /* Decapsulated secret data is secretlen bytes long */
     81  1.1  christos  if (EVP_PKEY_decapsulaterctx, secret, &secretlen, in, inlen) <= 0)
     82  1.1  christos      /* Error */
     83  1.1  christos 
     84  1.1  christos 
     85  1.1  christos =head1 SEE ALSO
     86  1.1  christos 
     87  1.2  christos L<EVP_PKEY_CTX_new_from_pkey(3)>,
     88  1.1  christos L<EVP_PKEY_encapsulate(3)>,
     89  1.1  christos L<EVP_KEM-RSA(7)>,
     90  1.1  christos 
     91  1.1  christos =head1 HISTORY
     92  1.1  christos 
     93  1.1  christos These functions were added in OpenSSL 3.0.
     94  1.1  christos 
     95  1.1  christos =head1 COPYRIGHT
     96  1.1  christos 
     97  1.2  christos Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved.
     98  1.1  christos 
     99  1.1  christos Licensed under the Apache License 2.0 (the "License").  You may not use
    100  1.1  christos this file except in compliance with the License.  You can obtain a copy
    101  1.1  christos in the file LICENSE in the source distribution or at
    102  1.1  christos L<https://www.openssl.org/source/license.html>.
    103  1.1  christos 
    104  1.1  christos =cut
    105