Add SSL_CTX_set1_cert_store()
[openssl.git] / doc / man3 / EVP_PKEY_CTX_set_hkdf_md.pod
1 =pod
2
3 =head1 NAME
4
5 EVP_PKEY_CTX_set_hkdf_md, EVP_PKEY_CTX_set1_hkdf_salt,
6 EVP_PKEY_CTX_set1_hkdf_key, EVP_PKEY_CTX_add1_hkdf_info -
7 HMAC-based Extract-and-Expand key derivation algorithm
8
9 =head1 SYNOPSIS
10
11  #include <openssl/kdf.h>
12
13  int EVP_PKEY_CTX_set_hkdf_md(EVP_PKEY_CTX *pctx, const EVP_MD *md);
14
15  int EVP_PKEY_CTX_set1_hkdf_salt(EVP_PKEY_CTX *pctx, unsigned char *salt,
16                                  int saltlen);
17
18  int EVP_PKEY_CTX_set1_hkdf_key(EVP_PKEY_CTX *pctx, unsigned char *key,
19                                 int keylen);
20
21  int EVP_PKEY_CTX_add1_hkdf_info(EVP_PKEY_CTX *pctx, unsigned char *info,
22                                  int infolen);
23
24 =head1 DESCRIPTION
25
26 The EVP_PKEY_HKDF algorithm implements the HKDF key derivation function.
27 HKDF follows the "extract-then-expand" paradigm, where the KDF logically
28 consists of two modules. The first stage takes the input keying material
29 and "extracts" from it a fixed-length pseudorandom key K. The second stage
30 "expands" the key K into several additional pseudorandom keys (the output
31 of the KDF).
32
33 EVP_PKEY_set_hkdf_md() sets the message digest associated with the HKDF.
34
35 EVP_PKEY_CTX_set1_hkdf_salt() sets the salt to B<saltlen> bytes of the
36 buffer B<salt>. Any existing value is replaced.
37
38 EVP_PKEY_CTX_set_hkdf_key() sets the key to B<keylen> bytes of the buffer
39 B<key>. Any existing value is replaced.
40
41 EVP_PKEY_CTX_add1_hkdf_info() sets the info value to B<infolen> bytes of the
42 buffer B<info>. If a value is already set, it is appended to the existing
43 value.
44
45 =head1 STRING CTRLS
46
47 HKDF also supports string based control operations via
48 L<EVP_PKEY_CTX_ctrl_str(3)>.
49 The B<type> parameter "md" uses the supplied B<value> as the name of the digest
50 algorithm to use.
51 The B<type> parameters "salt", "key" and "info" use the supplied B<value>
52 parameter as a B<seed>, B<key> or B<info> value.
53 The names "hexsalt", "hexkey" and "hexinfo" are similar except they take a hex
54 string which is converted to binary.
55
56 =head1 NOTES
57
58 All these functions are implemented as macros.
59
60 A context for HKDF can be obtained by calling:
61
62  EVP_PKEY_CTX *pctx = EVP_PKEY_new_id(EVP_PKEY_HKDF, NULL);
63
64 The digest, key, salt and info values must be set before a key is derived or
65 an error occurs.
66
67 The total length of the info buffer cannot exceed 1024 bytes in length: this
68 should be more than enough for any normal use of HKDF.
69
70 The output length of the KDF is specified via the length parameter to the
71 L<EVP_PKEY_derive(3)> function.
72 Since the HKDF output length is variable, passing a B<NULL> buffer as a means
73 to obtain the requisite length is not meaningful with HKDF.
74 Instead, the caller must allocate a buffer of the desired length, and pass that
75 buffer to L<EVP_PKEY_derive(3)> along with (a pointer initialized to) the
76 desired length.
77
78 Optimised versions of HKDF can be implemented in an ENGINE.
79
80 =head1 RETURN VALUES
81
82 All these functions return 1 for success and 0 or a negative value for failure.
83 In particular a return value of -2 indicates the operation is not supported by
84 the public key algorithm.
85
86 =head1 EXAMPLE
87
88 This example derives 10 bytes using SHA-256 with the secret key "secret",
89 salt value "salt" and info value "label":
90
91  EVP_PKEY_CTX *pctx;
92  unsigned char out[10];
93  size_t outlen = sizeof(out);
94  pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
95
96  if (EVP_PKEY_derive_init(pctx) <= 0)
97     /* Error */
98  if (EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()) <= 0)
99     /* Error */
100  if (EVP_PKEY_CTX_set1_salt(pctx, "salt", 4) <= 0)
101     /* Error */
102  if (EVP_PKEY_CTX_set1_key(pctx, "secret", 6) <= 0)
103     /* Error */
104  if (EVP_PKEY_CTX_add1_hkdf_info(pctx, "label", 6) <= 0)
105     /* Error */
106  if (EVP_PKEY_derive(pctx, out, &outlen) <= 0)
107     /* Error */
108
109 =head1 CONFORMING TO
110
111 RFC 5869
112
113 =head1 SEE ALSO
114
115 L<EVP_PKEY_CTX_new(3)>,
116 L<EVP_PKEY_CTX_ctrl_str(3)>,
117 L<EVP_PKEY_derive(3)>
118
119 =head1 COPYRIGHT
120
121 Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
122
123 Licensed under the OpenSSL license (the "License").  You may not use
124 this file except in compliance with the License.  You can obtain a copy
125 in the file LICENSE in the source distribution or at
126 L<https://www.openssl.org/source/license.html>.
127
128 =cut