1EVP_PKEY_DECAPSULATE(3ossl) OpenSSL EVP_PKEY_DECAPSULATE(3ossl)
2
3
4
6 EVP_PKEY_decapsulate_init, EVP_PKEY_decapsulate - Key decapsulation
7 using a private key algorithm
8
10 #include <openssl/evp.h>
11
12 int EVP_PKEY_decapsulate_init(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
13 int EVP_PKEY_decapsulate(EVP_PKEY_CTX *ctx,
14 unsigned char *secret, size_t *secretlen,
15 const unsigned char *wrapped, size_t wrappedlen);
16
18 The EVP_PKEY_decapsulate_init() function initializes a private key
19 algorithm context ctx for a decapsulation 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_decapsulate() function performs a private key
24 decapsulation operation using ctx. The data to be decapsulated is
25 specified using the wrapped and wrappedlen parameters. If secret is
26 NULL then the maximum size of the output secret buffer is written to
27 the *secretlen parameter. If secret is not NULL and the call is
28 successful then the decapsulated secret data is written to secret and
29 the amount of data written to secretlen.
30
32 After the call to EVP_PKEY_decapsulate_init() algorithm specific
33 parameters for the operation may be set or modified using
34 EVP_PKEY_CTX_set_params(3).
35
37 EVP_PKEY_decapsulate_init() and EVP_PKEY_decapsulate() return 1 for
38 success and 0 or a negative value for failure. In particular a return
39 value of -2 indicates the operation is not supported by the private key
40 algorithm.
41
43 Decapsulate data using RSA:
44
45 #include <openssl/evp.h>
46
47 /*
48 * NB: assumes rsa_priv_key is an RSA private key,
49 * and that in, inlen are already set up to contain encapsulated data.
50 */
51
52 EVP_PKEY_CTX *ctx = NULL;
53 size_t secretlen = 0;
54 unsigned char *secret = NULL;;
55
56 ctx = EVP_PKEY_CTX_new_from_pkey(libctx, rsa_priv_key, NULL);
57 if (ctx = NULL)
58 /* Error */
59 if (EVP_PKEY_decapsulate_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
66 /* Determine buffer length */
67 if (EVP_PKEY_decapsulate(ctx, NULL, &secretlen, in, inlen) <= 0)
68 /* Error */
69
70 secret = OPENSSL_malloc(secretlen);
71 if (secret == NULL)
72 /* malloc failure */
73
74 /* Decapsulated secret data is secretlen bytes long */
75 if (EVP_PKEY_decapsulaterctx, secret, &secretlen, in, inlen) <= 0)
76 /* Error */
77
79 EVP_PKEY_CTX_new(3), EVP_PKEY_encapsulate(3), EVP_KEM-RSA(7),
80
82 These functions were added in OpenSSL 3.0.
83
85 Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
86
87 Licensed under the Apache License 2.0 (the "License"). You may not use
88 this file except in compliance with the License. You can obtain a copy
89 in the file LICENSE in the source distribution or at
90 <https://www.openssl.org/source/license.html>.
91
92
93
943.1.1 2023-08-31 EVP_PKEY_DECAPSULATE(3ossl)