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