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