[KDF] Add KBKDF implementation for counter-mode HMAC
[openssl.git] / doc / man7 / EVP_KDF-KB.pod
1 =pod
2
3 =head1 NAME
4
5 EVP_KDF-KB - The Key-Based EVP_KDF implementation
6
7 =head1 DESCRIPTION
8
9 The EVP_KDF-KB algorithm implements the Key-Based key derivation function
10 (KBKDF).  KBKDF derives a key from repeated application of a keyed MAC to an
11 input secret (and other optional values).
12
13 =head2 Identity
14
15 "KBKDF" is the name for this implementation; it can be used with the
16 EVP_KDF_fetch() function.
17
18 =head2 Supported parameters
19
20 The supported parameters are:
21
22 =over 4
23
24 =item B<OSSL_KDF_PARAM_PROPERTIES> ("properties") <UTF8 string>
25
26 =item B<OSSL_KDF_PARAM_DIGEST> ("digest") <UTF8 string>
27
28 =item B<OSSL_KDF_PARAM_DIGEST> ("mac") <UTF8 string>
29
30 =item B<OSSL_KDF_PARAM_KEY> ("key") <octet string>
31
32 =item B<OSSL_KDF_PARAM_SALT> ("salt") <octet string>
33
34 =item B<OSSL_KDF_PARAM_INFO> ("info") <octet string>
35
36 =back
37
38 The parameters key, salt, and info correspond to KI, Label, and Context
39 (respectively) in SP800-108.  As in that document, salt and info are optional
40 and may be omitted.  Currently, only HMAC is supported for mac.
41
42 =head1 NOTES
43
44 A context for KBKDF can be obtained by calling:
45
46  EVP_KDF *kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
47  EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
48
49 The output length of an KBKDF is specified via the C<keylen>
50 parameter to the L<EVP_KDF_derive(3)> function.
51
52 Note that currently OpenSSL only implements Counter mode with HMAC.  Other
53 variants may be supported in the future.
54
55 =head1 EXAMPLES
56
57 This example derives 10 bytes using COUNTER-HMAC-SHA256, with KI "secret",
58 Label "label", and Context "context".
59
60  EVP_KDF *kdf;
61  EVP_KDF_CTX *kctx;
62  unsigned char out[10];
63  OSSL_PARAM params[6], *p = params;
64
65  kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
66  kctx = EVP_KDF_CTX_new(kdf);
67  EVP_KDF_free(kdf);
68
69  *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
70                                          "SHA256", 0);
71  *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC,
72                                          "HMAC", 0);
73  *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
74                                           "secret", strlen("secret"))
75  *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
76                                           "context", strlen("context"));
77  *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
78                                           "label", strlen("label"));
79  *p = OSSL_PARAM_construct_end();
80  if (EVP_KDF_CTX_set_params(kctx, params) <= 0)
81      error("EVP_KDF_CTX_set_params");
82  else if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0)
83      error("EVP_KDF_derive");
84
85  EVP_KDF_CTX_free(kctx);
86
87 =head1 CONFORMING TO
88
89 NIST SP800-108, IETF RFC 8009.
90
91 =head1 SEE ALSO
92
93 L<EVP_KDF(3)>,
94 L<EVP_KDF_CTX_new_id(3)>,
95 L<EVP_KDF_CTX_free(3)>,
96 L<EVP_KDF_ctrl(3)>,
97 L<EVP_KDF_size(3)>,
98 L<EVP_KDF_derive(3)>,
99 L<EVP_KDF(3)/PARAMETERS>
100
101 =head1 HISTORY
102
103 This functionality was added to OpenSSL 3.0.
104
105 =head1 COPYRIGHT
106
107 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
108 Copyright 2019 Red Hat, Inc.
109
110 Licensed under the Apache License 2.0 (the "License").  You may not use
111 this file except in compliance with the License.  You can obtain a copy
112 in the file LICENSE in the source distribution or at
113 L<https://www.openssl.org/source/license.html>.
114
115 =cut