1EVP_KDF_KB(7)                       OpenSSL                      EVP_KDF_KB(7)
2
3
4

NAME

6       EVP_KDF_KB - The Key-Based EVP_KDF implementation
7

DESCRIPTION

9       The EVP_KDF_KB algorithm implements the Key-Based key derivation
10       function (KBKDF).  KBKDF derives a key from repeated application of a
11       keyed MAC to an input secret (and other optional values).
12
13   Numeric identity
14       EVP_KDF_KB is the numeric identity for this implementation; it can be
15       used with the EVP_KDF_CTX_new_id() function.
16
17   Supported controls
18       The supported controls are:
19
20       EVP_KDF_CTRL_SET_KB_MODE
21           This control expects one argument: "int mode"
22
23           Sets the mode for the KBKDF operation. There are two supported
24           modes:
25
26           EVP_KDF_KB_MODE_COUNTER
27               The counter mode of KBKDF should be used. This is the default.
28
29           EVP_KDF_KB_MODE_FEEDBACK
30               The feedback mode of KBKDF should be used.
31
32       EVP_KDF_CTRL_SET_KB_MAC_TYPE
33           This control expects one argument: "int mac_type"
34
35           Sets the mac type for the KBKDF operation. There are two supported
36           mac types:
37
38           EVP_KDF_KB_MAC_TYPE_HMAC
39               The HMAC with the digest set by EVP_KDF_CTRL_SET_MD should be
40               used as the mac.
41
42           EVP_KDF_KB_MAC_TYPE_CMAC
43               The CMAC with the cipher set by EVP_KDF_CTRL_SET_CIPHER should
44               be used as the mac.
45
46       EVP_KDF_CTRL_SET_MD
47       EVP_KDF_CTRL_SET_CIPHER
48       EVP_KDF_CTRL_SET_KEY
49       EVP_KDF_CTRL_SET_SALT
50           These controls work as described in "CONTROLS" in EVP_KDF_CTX(3).
51
52       EVP_KDF_CTRL_SET_KB_INFO
53           This control expects two arguments: "unsigned char *info", "size_t
54           infolen"
55
56       EVP_KDF_CTRL_SET_KB_SEED
57           This control expects two arguments: "unsigned char *seed", "size_t
58           seedlen"
59
60           It is used only in the feedback mode and the length must be the
61           same as the block length of the cipher in CMAC or the size of the
62           digest in HMAC.
63
64       The controls EVP_KDF_CTRL_SET_KEY, EVP_KDF_CTRL_SET_SALT,
65       EVP_KDF_CTRL_SET_KB_INFO, and EVP_KDF_CTRL_SET_KB_SEED correspond to
66       KI, Label, Context, and IV (respectively) in SP800-108.  As in that
67       document, salt, info, and seed are optional and may be omitted.
68
69       Depending on whether mac is CMAC or HMAC, either digest or cipher is
70       required (respectively) and the other is unused.
71

NOTES

73       A context for KBKDF can be obtained by calling:
74
75        EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_KDF_KB);
76
77       The output length of an KBKDF is specified via the "keylen" parameter
78       to the EVP_KDF_derive(3) function.
79
80       Note that currently OpenSSL only implements counter and feedback modes.
81       Other variants may be supported in the future.
82

EXAMPLES

84       This example derives 10 bytes using COUNTER-HMAC-SHA256, with KI
85       "secret", Label "label", and Context "context".
86
87        EVP_KDF_CTX *kctx;
88        unsigned char out[10];
89
90        kctx = EVP_KDF_CTX_new_id(EVP_KDF_KB);
91
92        EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256());
93        EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KB_MAC_TYPE, EVP_KDF_KB_MAC_TYPE_HMAC);
94        EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", strlen("secret"));
95        EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "label", strlen("label"));
96        EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KB_INFO, "context", strlen("context"));
97        if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0)
98            error("EVP_KDF_derive");
99
100        EVP_KDF_CTX_free(kctx);
101
102       This example derives 10 bytes using FEEDBACK-CMAC-AES256, with KI
103       "secret", Label "label", Context "context", and IV "sixteen bytes iv".
104
105        EVP_KDF_CTX *kctx;
106        unsigned char out[10];
107        unsigned char *iv = "sixteen bytes iv";
108
109        kctx = EVP_KDF_CTX_new_id(EVP_KDF_KB);
110
111        EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_CIPHER, EVP_aes_256_cbc());
112        EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KB_MAC_TYPE, EVP_KDF_KB_MAC_TYPE_CMAC);
113        EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KB_MODE, EVP_KDF_KB_MODE_FEEDBACK);
114        EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", strlen("secret"));
115        EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "label", strlen("label"));
116        EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KB_INFO, "context", strlen("context"));
117        EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KB_SEED, iv, strlen(iv));
118        if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0)
119            error("EVP_KDF_derive");
120
121        EVP_KDF_CTX_free(kctx);
122

CONFORMING TO

124       NIST SP800-108, IETF RFC 6803, IETF RFC 8009.
125

SEE ALSO

127       EVP_KDF_CTX(3), EVP_KDF_CTX_new_id(3), EVP_KDF_CTX_free(3),
128       EVP_KDF_ctrl(3), EVP_KDF_size(3), EVP_KDF_derive(3), "CONTROLS" in
129       EVP_KDF_CTX(3)
130

HISTORY

132       This functionality was added to OpenSSL 3.0.
133
135       Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
136       Copyright 2019 Red Hat, Inc.
137
138       Licensed under the Apache License 2.0 (the "License").  You may not use
139       this file except in compliance with the License.  You can obtain a copy
140       in the file LICENSE in the source distribution or at
141       <https://www.openssl.org/source/license.html>.
142
143
144
1451.1.1l                            2021-09-15                     EVP_KDF_KB(7)
Impressum