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

NAME

6       EVP_PKEY_encapsulate_init, EVP_PKEY_encapsulate - Key encapsulation
7       using a public key algorithm
8

SYNOPSIS

10        #include <openssl/evp.h>
11
12        int EVP_PKEY_encapsulate_init(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
13        int EVP_PKEY_encapsulate(EVP_PKEY_CTX *ctx,
14                                 unsigned char *out, size_t *outlen,
15                                 unsigned char *genkey, size_t *genkeylen);
16

DESCRIPTION

18       The EVP_PKEY_encapsulate_init() function initializes a public key
19       algorithm context ctx for an encapsulation operation and then sets the
20       params on the context in the same way as calling
21       EVP_PKEY_CTX_set_params(3).
22
23       The EVP_PKEY_encapsulate() function performs a public key encapsulation
24       operation using ctx with the name name.  If out is NULL then the
25       maximum size of the output buffer is written to the *outlen parameter
26       and the maximum size of the generated key buffer is written to
27       *genkeylen. If out is not NULL and the call is successful then the
28       internally generated key is written to genkey and its size is written
29       to *genkeylen. The encapsulated version of the generated key is written
30       to out and its size is written to *outlen.
31

NOTES

33       After the call to EVP_PKEY_encapsulate_init() algorithm specific
34       parameters for the operation may be set or modified using
35       EVP_PKEY_CTX_set_params(3).
36

RETURN VALUES

38       EVP_PKEY_encapsulate_init() and EVP_PKEY_encapsulate() return 1 for
39       success and 0 or a negative value for failure. In particular a return
40       value of -2 indicates the operation is not supported by the public key
41       algorithm.
42

EXAMPLES

44       Encapsulate an RSASVE key (for RSA keys).
45
46        #include <openssl/evp.h>
47
48        /*
49         * NB: assumes rsa_pub_key is an public key of another party.
50         */
51
52        EVP_PKEY_CTX *ctx = NULL;
53        size_t secretlen = 0, outlen = 0;
54        unsigned char *out = NULL, *secret = NULL;
55
56        ctx = EVP_PKEY_CTX_new_from_pkey(libctx, rsa_pub_key, NULL);
57        if (ctx = NULL)
58            /* Error */
59        if (EVP_PKEY_encapsulate_init(ctx, NULL) <= 0)
60            /* Error */
61
62        /* Set the mode - only 'RSASVE' is currently supported */
63         if (EVP_PKEY_CTX_set_kem_op(ctx, "RSASVE") <= 0)
64            /* Error */
65        /* Determine buffer length */
66        if (EVP_PKEY_encapsulate(ctx, NULL, &outlen, NULL, &secretlen) <= 0)
67            /* Error */
68
69        out = OPENSSL_malloc(outlen);
70        secret = OPENSSL_malloc(secretlen);
71        if (out == NULL || secret == NULL)
72            /* malloc failure */
73
74        /*
75         * The generated 'secret' can be used as key material.
76         * The encapsulated 'out' can be sent to another party who can
77         * decapsulate it using their private key to retrieve the 'secret'.
78         */
79        if (EVP_PKEY_encapsulate(ctx, out, &outlen, secret, &secretlen) <= 0)
80            /* Error */
81

SEE ALSO

83       EVP_PKEY_CTX_new(3), EVP_PKEY_decapsulate(3), EVP_KEM-RSA(7),
84

HISTORY

86       These functions were added in OpenSSL 3.0.
87
89       Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
90
91       Licensed under the Apache License 2.0 (the "License").  You may not use
92       this file except in compliance with the License.  You can obtain a copy
93       in the file LICENSE in the source distribution or at
94       <https://www.openssl.org/source/license.html>.
95
96
97
983.0.9                             2023-07-27       EVP_PKEY_ENCAPSULATE(3ossl)
Impressum