1EVP_KDF-SSHKDF(7ossl) OpenSSL EVP_KDF-SSHKDF(7ossl)
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 Identity
19 "SSHKDF" is the name for this implementation; it can be used with the
20 EVP_KDF_fetch() function.
21
22 Supported parameters
23 The supported parameters are:
24
25 "properties" (OSSL_KDF_PARAM_PROPERTIES) <UTF8 string>
26 "digest" (OSSL_KDF_PARAM_DIGEST) <UTF8 string>
27 "key" (OSSL_KDF_PARAM_KEY) <octet string>
28 These parameters work as described in "PARAMETERS" in EVP_KDF(3).
29
30 "xcghash" (OSSL_KDF_PARAM_SSHKDF_XCGHASH) <octet string>
31 "session_id" (OSSL_KDF_PARAM_SSHKDF_SESSION_ID) <octet string>
32 These parameters set the respective values for the KDF. If a value
33 is already set, the contents are replaced.
34
35 "type" (OSSL_KDF_PARAM_SSHKDF_TYPE) <UTF8 string>
36 This parameter sets the type for the SSHKDF operation. There are
37 six supported types:
38
39 EVP_KDF_SSHKDF_TYPE_INITIAL_IV_CLI_TO_SRV
40 The Initial IV from client to server. A single char of value
41 65 (ASCII char 'A').
42
43 EVP_KDF_SSHKDF_TYPE_INITIAL_IV_SRV_TO_CLI
44 The Initial IV from server to client A single char of value 66
45 (ASCII char 'B').
46
47 EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_CLI_TO_SRV
48 The Encryption Key from client to server A single char of value
49 67 (ASCII char 'C').
50
51 EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_SRV_TO_CLI
52 The Encryption Key from server to client A single char of value
53 68 (ASCII char 'D').
54
55 EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_CLI_TO_SRV
56 The Integrity Key from client to server A single char of value
57 69 (ASCII char 'E').
58
59 EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_SRV_TO_CLI
60 The Integrity Key from client to server A single char of value
61 70 (ASCII char 'F').
62
64 A context for SSHKDF can be obtained by calling:
65
66 EVP_KDF *kdf = EVP_KDF_fetch(NULL, "SSHKDF", NULL);
67 EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
68
69 The output length of the SSHKDF derivation is specified via the keylen
70 parameter to the EVP_KDF_derive(3) function. Since the SSHKDF output
71 length is variable, calling EVP_KDF_CTX_get_kdf_size(3) to obtain the
72 requisite length is not meaningful. The caller must allocate a buffer
73 of the desired length, and pass that buffer to the EVP_KDF_derive(3)
74 function along with the desired length.
75
77 This example derives an 8 byte IV using SHA-256 with a 1K "key" and
78 appropriate "xcghash" and "session_id" values:
79
80 EVP_KDF *kdf;
81 EVP_KDF_CTX *kctx;
82 char type = EVP_KDF_SSHKDF_TYPE_INITIAL_IV_CLI_TO_SRV;
83 unsigned char key[1024] = "01234...";
84 unsigned char xcghash[32] = "012345...";
85 unsigned char session_id[32] = "012345...";
86 unsigned char out[8];
87 size_t outlen = sizeof(out);
88 OSSL_PARAM params[6], *p = params;
89
90 kdf = EVP_KDF_fetch(NULL, "SSHKDF", NULL);
91 kctx = EVP_KDF_CTX_new(kdf);
92 EVP_KDF_free(kdf);
93
94 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
95 SN_sha256, strlen(SN_sha256));
96 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
97 key, (size_t)1024);
98 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SSHKDF_XCGHASH,
99 xcghash, (size_t)32);
100 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SSHKDF_SESSION_ID,
101 session_id, (size_t)32);
102 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_SSHKDF_TYPE,
103 &type, sizeof(type));
104 *p = OSSL_PARAM_construct_end();
105 if (EVP_KDF_derive(kctx, out, outlen, params) <= 0)
106 /* Error */
107
109 RFC 4253
110
112 EVP_KDF(3), EVP_KDF_CTX_new(3), EVP_KDF_CTX_free(3),
113 EVP_KDF_CTX_set_params(3), EVP_KDF_CTX_get_kdf_size(3),
114 EVP_KDF_derive(3), "PARAMETERS" in EVP_KDF(3)
115
117 Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
118
119 Licensed under the Apache License 2.0 (the "License"). You may not use
120 this file except in compliance with the License. You can obtain a copy
121 in the file LICENSE in the source distribution or at
122 <https://www.openssl.org/source/license.html>.
123
124
125
1263.0.5 2022-07-05 EVP_KDF-SSHKDF(7ossl)