]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man7/EVP_KDF-SSHKDF.pod
Update KDF documentation (section 7)
[thirdparty/openssl.git] / doc / man7 / EVP_KDF-SSHKDF.pod
CommitLineData
8d76481b
SS
1=pod
2
3=head1 NAME
4
ccd7115a 5EVP_KDF-SSHKDF - The SSHKDF EVP_KDF implementation
8d76481b
SS
6
7=head1 DESCRIPTION
8
9Support for computing the B<SSHKDF> KDF through the B<EVP_KDF> API.
10
ccd7115a 11The EVP_KDF-SSHKDF algorithm implements the SSHKDF key derivation function.
8d76481b
SS
12It is defined in RFC 4253, section 7.2 and is used by SSH to derive IVs,
13encryption keys and integrity keys.
14Five inputs are required to perform key derivation: The hashing function
15(for example SHA256), the Initial Key, the Exchange Hash, the Session ID,
16and the derivation key type.
17
ccd7115a 18=head2 Identity
8d76481b 19
ccd7115a
P
20"SSHKDF" is the name for this implementation; it
21can be used with the EVP_KDF_fetch() function.
8d76481b 22
ccd7115a 23=head2 Supported parameters
8d76481b 24
ccd7115a 25The supported parameters are:
8d76481b
SS
26
27=over 4
28
ccd7115a 29=item B<OSSL_KDF_PARAM_PROPERTIES> ("properties") <UTF8 string>
8d76481b 30
ccd7115a 31=item B<OSSL_KDF_PARAM_DIGEST> ("digest") <UTF8 string>
8d76481b 32
ccd7115a 33=item B<OSSL_KDF_PARAM_KEY> ("key") <octet string>
8d76481b 34
ccd7115a 35These parameters work as described in L<EVP_KDF(3)/PARAMETERS>.
8d76481b 36
ccd7115a 37=item B<OSSL_KDF_PARAM_SSHKDF_XCGHASH> ("xcghash") <octet string>
8d76481b 38
ccd7115a 39=item B<OSSL_KDF_PARAM_SSHKDF_SESSION_ID> ("session_id") <octet string>
8d76481b 40
ccd7115a
P
41These parameters set the respective values for the KDF.
42If a value is already set, the contents are replaced.
8d76481b 43
ccd7115a 44=item B<OSSL_KDF_PARAM_SSHKDF_TYPE> ("type") <int>
8d76481b 45
ccd7115a
P
46This parameter sets the type for the SSHHKDF operation.
47There are six supported types:
8d76481b
SS
48
49=over 4
50
c2969ff6 51=item EVP_KDF_SSHKDF_TYPE_INITIAL_IV_CLI_TO_SRV
8d76481b
SS
52
53The Initial IV from client to server.
54A single char of value 65 (ASCII char 'A').
55
c2969ff6 56=item EVP_KDF_SSHKDF_TYPE_INITIAL_IV_SRV_TO_CLI
8d76481b
SS
57
58The Initial IV from server to client
59A single char of value 66 (ASCII char 'B').
60
61=item EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_CLI_TO_SRV
62
63The Encryption Key from client to server
64A single char of value 67 (ASCII char 'C').
65
66=item EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_SRV_TO_CLI
67
68The Encryption Key from server to client
69A single char of value 68 (ASCII char 'D').
70
71=item EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_CLI_TO_SRV
72
73The Integrity Key from client to server
74A single char of value 69 (ASCII char 'E').
75
76=item EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_SRV_TO_CLI
77
78The Integrity Key from client to server
79A single char of value 70 (ASCII char 'F').
80
81=back
82
8d76481b
SS
83=back
84
85=head1 NOTES
86
87A context for SSHKDF can be obtained by calling:
88
ccd7115a
P
89 EVP_KDF *kdf = EVP_KDF_fetch(NULL, "SSHKDF", NULL);
90 EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
8d76481b
SS
91
92The output length of the SSHKDF derivation is specified via the C<keylen>
ccd7115a
P
93parameter to the L<EVP_KDF-derive(3)> function.
94Since the SSHKDF output length is variable, calling L<EVP_KDF-size()>
8d76481b
SS
95to obtain the requisite length is not meaningful. The caller must
96allocate a buffer of the desired length, and pass that buffer to the
ccd7115a 97L<EVP_KDF-derive(3)> function along with the desired length.
8d76481b 98
cda77422 99=head1 EXAMPLES
8d76481b
SS
100
101This example derives an 8 byte IV using SHA-256 with a 1K "key" and appropriate
102"xcghash" and "session_id" values:
103
ccd7115a 104 EVP_KDF *kdf;
8d76481b
SS
105 EVP_KDF_CTX *kctx;
106 unsigned char key[1024] = "01234...";
107 unsigned char xcghash[32] = "012345...";
108 unsigned char session_id[32] = "012345...";
109 unsigned char out[8];
110 size_t outlen = sizeof(out);
ccd7115a
P
111 OSSL_PARAM params[6], *p = params;
112
113 kdf = EVP_KDF_fetch(NULL, "SSHKDF", NULL);
114 kctx = EVP_KDF_CTX_new(kdf);
115 EVP_KDF_free(kdf);
116
117 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
118 SN_sha256, strlen(SN_sha256));
119 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
120 key, (size_t)1024);
121 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SSHKDF_XCGHASH,
122 xcghash, (size_t)32);
123 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
124 session_id, (size_t)32);
125 *p++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_SSHKDF_TYPE,
126 EVP_KDF_SSHKDF_TYPE_INITIAL_IV_CLI_TO_SRV);
127 *p = OSSL_PARAM_construct_end();
128 if (EVP_KDF_set_params(kctx, params) <= 0)
8d76481b 129 /* Error */
ccd7115a 130
8d76481b
SS
131 if (EVP_KDF_derive(kctx, out, &outlen) <= 0)
132 /* Error */
133
134
135=head1 CONFORMING TO
136
137RFC 4253
138
139=head1 SEE ALSO
140
ccd7115a
P
141L<EVP_KDF>,
142L<EVP_KDF-CTX_new_id(3)>,
143L<EVP_KDF-CTX_free(3)>,
144L<EVP_KDF-ctrl(3)>,
145L<EVP_KDF-size(3)>,
146L<EVP_KDF-derive(3)>,
147L<EVP_KDF(3)/PARAMETERS>
8d76481b
SS
148
149=head1 COPYRIGHT
150
151Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
152
153Licensed under the OpenSSL license (the "License"). You may not use
154this file except in compliance with the License. You can obtain a copy
155in the file LICENSE in the source distribution or at
156L<https://www.openssl.org/source/license.html>.
157
158=cut
159