5 EVP_KDF_SS - The Single Step / One Step EVP_KDF implementation
9 The EVP_KDF_SS algorithm implements the Single Step key derivation function (SSKDF).
10 SSKDF derives a key using input such as a shared secret key (that was generated
11 during the execution of a key establishment scheme) and fixedinfo.
12 SSKDF is also informally referred to as 'Concat KDF'.
14 =head2 Auxiliary function
16 The implementation uses a selectable auxiliary function H, which can be one of:
20 =item B<H(x) = hash(x, digest=md)>
22 =item B<H(x) = HMAC_hash(x, key=salt, digest=md)>
24 =item B<H(x) = KMACxxx(x, key=salt, custom="KDF", outlen=mac_size)>
28 Both the HMAC and KMAC implementations set the key using the 'salt' value.
29 The hash and HMAC also require the digest to be set.
31 =head2 Numeric identity
33 B<EVP_KDF_SS> is the numeric identity for this implementation; it
34 can be used with the EVP_KDF_CTX_new_id() function.
36 =head2 Supported controls
38 The supported controls are:
42 =item B<EVP_KDF_CTRL_SET_MD>
44 =item B<EVP_KDF_CTRL_SET_MAC>
46 =item B<EVP_MAC_CTRL_SET_MAC_SIZE>
48 =item B<EVP_KDF_CTRL_SET_SALT>
50 These controls work as described in L<EVP_KDF_CTX(3)/CONTROLS>.
52 =item B<EVP_KDF_CTRL_SET_KEY>
54 This control expects two arguments: C<unsigned char *secret>, C<size_t secretlen>
56 The shared secret used for key derivation. This control sets the secret.
58 EVP_KDF_ctrl_str() takes two type strings for this control:
64 The value string is used as is.
68 The value string is expected to be a hexadecimal number, which will be
69 decoded before being passed on as the control value.
73 =item B<EVP_KDF_CTRL_SET_SSKDF_INFO>
75 This control expects two arguments: C<unsigned char *info>, C<size_t infolen>
77 An optional value for fixedinfo, also known as otherinfo. This control sets the fixedinfo.
79 EVP_KDF_ctrl_str() takes two type strings for this control:
85 The value string is used as is.
89 The value string is expected to be a hexadecimal number, which will be
90 decoded before being passed on as the control value.
98 A context for SSKDF can be obtained by calling:
100 EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_KDF_SS);
102 The output length of an SSKDF is specified via the C<keylen>
103 parameter to the L<EVP_KDF_derive(3)> function.
107 This example derives 10 bytes using H(x) = SHA-256, with the secret key "secret"
108 and fixedinfo value "label":
111 unsigned char out[10];
113 kctx = EVP_KDF_CTX_new_id(EVP_KDF_SS);
115 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) {
116 error("EVP_KDF_CTRL_SET_MD");
118 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", (size_t)6) <= 0) {
119 error("EVP_KDF_CTRL_SET_KEY");
121 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SSKDF_INFO, "label", (size_t)5) <= 0) {
122 error("EVP_KDF_CTRL_SET_SSKDF_INFO");
124 if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) {
125 error("EVP_KDF_derive");
128 EVP_KDF_CTX_free(kctx);
130 This example derives 10 bytes using H(x) = HMAC(SHA-256), with the secret key "secret",
131 fixedinfo value "label" and salt "salt":
134 unsigned char out[10];
136 kctx = EVP_KDF_CTX_new_id(EVP_KDF_SS);
138 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAC, EVP_get_macbyname("HMAC")) <= 0) {
139 error("EVP_KDF_CTRL_SET_MAC");
141 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) {
142 error("EVP_KDF_CTRL_SET_MD");
144 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", (size_t)6) <= 0) {
145 error("EVP_KDF_CTRL_SET_KEY");
147 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SSKDF_INFO, "label", (size_t)5) <= 0) {
148 error("EVP_KDF_CTRL_SET_SSKDF_INFO");
150 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "salt", (size_t)4) <= 0) {
151 error("EVP_KDF_CTRL_SET_SALT");
153 if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) {
154 error("EVP_KDF_derive");
157 EVP_KDF_CTX_free(kctx);
159 This example derives 10 bytes using H(x) = KMAC128(x,salt,outlen), with the secret key "secret"
160 fixedinfo value "label", salt of "salt" and KMAC outlen of 20:
163 unsigned char out[10];
165 kctx = EVP_KDF_CTX_new_id(EVP_KDF_SS);
167 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAC, EVP_get_macbyname("KMAC128")) <= 0) {
168 error("EVP_KDF_CTRL_SET_MAC");
170 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) {
171 error("EVP_KDF_CTRL_SET_MD");
173 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", (size_t)6) <= 0) {
174 error("EVP_KDF_CTRL_SET_KEY");
176 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SSKDF_INFO, "label", (size_t)5) <= 0) {
177 error("EVP_KDF_CTRL_SET_SSKDF_INFO");
179 /* If not specified the salt will be set to a default value */
180 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "salt", (size_t)4) <= 0) {
181 error("EVP_KDF_CTRL_SET_SALT");
183 /* If not specified the default size will be the size of the derived key */
184 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAC_SIZE, (size_t)20) <= 0) {
185 error("EVP_KDF_CTRL_SET_MAC_SIZE");
187 if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) {
188 error("EVP_KDF_derive");
191 EVP_KDF_CTX_free(kctx);
201 L<EVP_KDF_CTX_new_id(3)>,
202 L<EVP_KDF_CTX_free(3)>,
205 L<EVP_KDF_derive(3)>,
206 L<EVP_KDF_CTX(3)/CONTROLS>
210 This functionality was added to OpenSSL 3.0.
214 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. Copyright
215 (c) 2019, Oracle and/or its affiliates. All rights reserved.
217 Licensed under the Apache License 2.0 (the "License"). You may not use
218 this file except in compliance with the License. You can obtain a copy
219 in the file LICENSE in the source distribution or at
220 L<https://www.openssl.org/source/license.html>.