1EVP_KDF_SSHKDF(7) OpenSSL EVP_KDF_SSHKDF(7)
2
3
4
6 EVP_KDF_SSHKDF - The SSHKDF EVP_KDF implementation
7
9 Support for computing the SSHKDF KDF through the EVP_KDF API.
10
11 The EVP_KDF_SSHKDF algorithm implements the SSHKDF key derivation
12 function. It is defined in RFC 4253, section 7.2 and is used by SSH to
13 derive IVs, encryption keys and integrity keys. Five inputs are
14 required to perform key derivation: The hashing function (for example
15 SHA256), the Initial Key, the Exchange Hash, the Session ID, and the
16 derivation key type.
17
18 Numeric identity
19 EVP_KDF_SSHKDF is the numeric identity for this implementation; it can
20 be used with the EVP_KDF_CTX_new_id() function.
21
22 Supported controls
23 The supported controls are:
24
25 EVP_KDF_CTRL_SET_MD
26 EVP_KDF_CTRL_SET_KEY
27 These controls work as described in "CONTROLS" in EVP_KDF_CTX(3).
28
29 EVP_KDF_CTRL_SET_SSHKDF_XCGHASH
30 EVP_KDF_CTRL_SET_SSHKDF_SESSION_ID
31 These controls expect two arguments: "unsigned char *buffer",
32 "size_t length"
33
34 They set the respective values to the first length bytes of the
35 buffer buffer. If a value is already set, the contents are
36 replaced.
37
38 EVP_KDF_ctrl_str() takes two type strings for these controls:
39
40 "xcghash"
41 "session_id"
42 The value string is used as is.
43
44 "hexxcghash"
45 "hexsession_id"
46 The value string is expected to be a hexadecimal number, which
47 will be decoded before being passed on as the control value.
48
49 EVP_KDF_CTRL_SET_SSHKDF_TYPE
50 This control expects one argument: "int mode"
51
52 Sets the type for the SSHHKDF operation. There are six supported
53 types:
54
55 EVP_KDF_SSHKDF_TYPE_ININITAL_IV_CLI_TO_SRV
56 The Initial IV from client to server. A single char of value
57 65 (ASCII char 'A').
58
59 EVP_KDF_SSHKDF_TYPE_ININITAL_IV_SRV_TO_CLI
60 The Initial IV from server to client A single char of value 66
61 (ASCII char 'B').
62
63 EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_CLI_TO_SRV
64 The Encryption Key from client to server A single char of value
65 67 (ASCII char 'C').
66
67 EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_SRV_TO_CLI
68 The Encryption Key from server to client A single char of value
69 68 (ASCII char 'D').
70
71 EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_CLI_TO_SRV
72 The Integrity Key from client to server A single char of value
73 69 (ASCII char 'E').
74
75 EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_SRV_TO_CLI
76 The Integrity Key from client to server A single char of value
77 70 (ASCII char 'F').
78
79 EVP_KDF_ctrl_str() type string: "type"
80
81 The value is a string of length one character. The only valid
82 values are the numerical values of the ASCII caracters: "A" (65) to
83 "F" (70).
84
86 A context for SSHKDF can be obtained by calling:
87
88 EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_KDF_SSHKDF);
89
90 The output length of the SSHKDF derivation is specified via the
91 "keylen" parameter to the EVP_KDF_derive(3) function. Since the SSHKDF
92 output length is variable, calling EVP_KDF_size() to obtain the
93 requisite length is not meaningful. The caller must allocate a buffer
94 of the desired length, and pass that buffer to the EVP_KDF_derive(3)
95 function along with the desired length.
96
98 This example derives an 8 byte IV using SHA-256 with a 1K "key" and
99 appropriate "xcghash" and "session_id" values:
100
101 EVP_KDF_CTX *kctx;
102 unsigned char key[1024] = "01234...";
103 unsigned char xcghash[32] = "012345...";
104 unsigned char session_id[32] = "012345...";
105 unsigned char out[8];
106 size_t outlen = sizeof(out);
107 kctx = EVP_KDF_CTX_new_id(EVP_KDF_SSHKDF);
108
109 if (EVP_KDF_CTX_set_md(kctx, EVP_sha256()) <= 0)
110 /* Error */
111 if (EVP_KDF_CTX_set1_key(kctx, key, 1024) <= 0)
112 /* Error */
113 if (EVP_KDF_CTX_set1_sshkdf_xcghash(kctx, xcghash, 32) <= 0)
114 /* Error */
115 if (EVP_KDF_CTX_set1_sshkdf_session_id(kctx, session_id, 32) <= 0)
116 /* Error */
117 if (EVP_KDF_CTX_set_sshkdf_type(kctx,
118 EVP_KDF_SSHKDF_TYPE_ININITAL_IV_CLI_TO_SRV) <= 0)
119 /* Error */
120 if (EVP_KDF_derive(kctx, out, &outlen) <= 0)
121 /* Error */
122
124 RFC 4253
125
127 EVP_KDF_CTX, 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
132 Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
133
134 Licensed under the OpenSSL license (the "License"). You may not use
135 this file except in compliance with the License. You can obtain a copy
136 in the file LICENSE in the source distribution or at
137 <https://www.openssl.org/source/license.html>.
138
139
140
1411.1.1c 2019-06-03 EVP_KDF_SSHKDF(7)