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);
132 This example derives 10 bytes using H(x) = HMAC(SHA-256), with the secret key "secret",
133 fixedinfo value "label" and salt "salt":
136 unsigned char out[10];
138 kctx = EVP_KDF_CTX_new_id(EVP_KDF_SS);
140 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAC, EVP_get_macbyname("HMAC")) <= 0) {
141 error("EVP_KDF_CTRL_SET_MAC");
143 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) {
144 error("EVP_KDF_CTRL_SET_MD");
146 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", (size_t)6) <= 0) {
147 error("EVP_KDF_CTRL_SET_KEY");
149 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SSKDF_INFO, "label", (size_t)5) <= 0) {
150 error("EVP_KDF_CTRL_SET_SSKDF_INFO");
152 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "salt", (size_t)4) <= 0) {
153 error("EVP_KDF_CTRL_SET_SALT");
155 if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) {
156 error("EVP_KDF_derive");
159 EVP_KDF_CTX_free(kctx);
163 This example derives 10 bytes using H(x) = KMAC128(x,salt,outlen), with the secret key "secret"
164 fixedinfo value "label", salt of "salt" and KMAC outlen of 20:
167 unsigned char out[10];
169 kctx = EVP_KDF_CTX_new_id(EVP_KDF_SS);
171 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAC, EVP_get_macbyname("KMAC128")) <= 0) {
172 error("EVP_KDF_CTRL_SET_MAC");
174 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) {
175 error("EVP_KDF_CTRL_SET_MD");
177 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", (size_t)6) <= 0) {
178 error("EVP_KDF_CTRL_SET_KEY");
180 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SSKDF_INFO, "label", (size_t)5) <= 0) {
181 error("EVP_KDF_CTRL_SET_SSKDF_INFO");
183 /* If not specified the salt will be set to a default value */
184 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "salt", (size_t)4) <= 0) {
185 error("EVP_KDF_CTRL_SET_SALT");
187 /* If not specified the default size will be the size of the derived key */
188 if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAC_SIZE, (size_t)20) <= 0) {
189 error("EVP_KDF_CTRL_SET_MAC_SIZE");
191 if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) {
192 error("EVP_KDF_derive");
195 EVP_KDF_CTX_free(kctx);
205 L<EVP_KDF_CTX_new_id(3)>,
206 L<EVP_KDF_CTX_free(3)>,
209 L<EVP_KDF_derive(3)>,
210 L<EVP_KDF_CTX(3)/CONTROLS>
214 This functionality was added to OpenSSL 3.0.
218 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. Copyright
219 (c) 2019, Oracle and/or its affiliates. All rights reserved.
221 Licensed under the Apache License 2.0 (the "License"). You may not use
222 this file except in compliance with the License. You can obtain a copy
223 in the file LICENSE in the source distribution or at
224 L<https://www.openssl.org/source/license.html>.