5 EVP_KDF_SSHKDF - The SSHKDF EVP_KDF implementation
9 Support for computing the B<SSHKDF> KDF through the B<EVP_KDF> API.
11 The EVP_KDF_SSHKDF algorithm implements the SSHKDF key derivation function.
12 It is defined in RFC 4253, section 7.2 and is used by SSH to derive IVs,
13 encryption keys and integrity keys.
14 Five inputs are required to perform key derivation: The hashing function
15 (for example SHA256), the Initial Key, the Exchange Hash, the Session ID,
16 and the derivation key type.
18 =head2 Numeric identity
20 B<EVP_KDF_SSHKDF> is the numeric identity for this implementation; it
21 can be used with the EVP_KDF_CTX_new_id() function.
23 =head2 Supported controls
25 The supported controls are:
29 =item B<EVP_KDF_CTRL_SET_MD>
31 =item B<EVP_KDF_CTRL_SET_KEY>
33 These controls work as described in L<EVP_KDF_CTX(3)/CONTROLS>.
35 =item B<EVP_KDF_CTRL_SET_SSHKDF_XCGHASH>
37 =item B<EVP_KDF_CTRL_SET_SSHKDF_SESSION_ID>
39 These controls expect two arguments: C<unsigned char *buffer>, C<size_t length>
41 They set the respective values to the first B<length> bytes of the buffer
42 B<buffer>. If a value is already set, the contents are replaced.
44 EVP_KDF_ctrl_str() takes two type strings for these controls:
52 The value string is used as is.
58 The value string is expected to be a hexadecimal number, which will be
59 decoded before being passed on as the control value.
63 =item B<EVP_KDF_CTRL_SET_SSHKDF_TYPE>
65 This control expects one argument: C<int mode>
67 Sets the type for the SSHHKDF operation. There are six supported types:
71 =item EVP_KDF_SSHKDF_TYPE_ININITAL_IV_CLI_TO_SRV
73 The Initial IV from client to server.
74 A single char of value 65 (ASCII char 'A').
76 =item EVP_KDF_SSHKDF_TYPE_ININITAL_IV_SRV_TO_CLI
78 The Initial IV from server to client
79 A single char of value 66 (ASCII char 'B').
81 =item EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_CLI_TO_SRV
83 The Encryption Key from client to server
84 A single char of value 67 (ASCII char 'C').
86 =item EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_SRV_TO_CLI
88 The Encryption Key from server to client
89 A single char of value 68 (ASCII char 'D').
91 =item EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_CLI_TO_SRV
93 The Integrity Key from client to server
94 A single char of value 69 (ASCII char 'E').
96 =item EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_SRV_TO_CLI
98 The Integrity Key from client to server
99 A single char of value 70 (ASCII char 'F').
103 EVP_KDF_ctrl_str() type string: "type"
105 The value is a string of length one character. The only valid values
106 are the numerical values of the ASCII caracters: "A" (65) to "F" (70).
112 A context for SSHKDF can be obtained by calling:
114 EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_KDF_SSHKDF);
116 The output length of the SSHKDF derivation is specified via the C<keylen>
117 parameter to the L<EVP_KDF_derive(3)> function.
118 Since the SSHKDF output length is variable, calling L<EVP_KDF_size()>
119 to obtain the requisite length is not meaningful. The caller must
120 allocate a buffer of the desired length, and pass that buffer to the
121 L<EVP_KDF_derive(3)> function along with the desired length.
125 This example derives an 8 byte IV using SHA-256 with a 1K "key" and appropriate
126 "xcghash" and "session_id" values:
129 unsigned char key[1024] = "01234...";
130 unsigned char xcghash[32] = "012345...";
131 unsigned char session_id[32] = "012345...";
132 unsigned char out[8];
133 size_t outlen = sizeof(out);
134 kctx = EVP_KDF_CTX_new_id(EVP_KDF_SSHKDF);
136 if (EVP_KDF_CTX_set_md(kctx, EVP_sha256()) <= 0)
138 if (EVP_KDF_CTX_set1_key(kctx, key, 1024) <= 0)
140 if (EVP_KDF_CTX_set1_sshkdf_xcghash(kctx, xcghash, 32) <= 0)
142 if (EVP_KDF_CTX_set1_sshkdf_session_id(kctx, session_id, 32) <= 0)
144 if (EVP_KDF_CTX_set_sshkdf_type(kctx,
145 EVP_KDF_SSHKDF_TYPE_ININITAL_IV_CLI_TO_SRV) <= 0)
147 if (EVP_KDF_derive(kctx, out, &outlen) <= 0)
158 L<EVP_KDF_CTX_new_id(3)>,
159 L<EVP_KDF_CTX_free(3)>,
162 L<EVP_KDF_derive(3)>,
163 L<EVP_KDF_CTX(3)/CONTROLS>
167 Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
169 Licensed under the OpenSSL license (the "License"). You may not use
170 this file except in compliance with the License. You can obtain a copy
171 in the file LICENSE in the source distribution or at
172 L<https://www.openssl.org/source/license.html>.