9c9734e7c34cc25fd62735a2a57d384f14bfd740
[openssl.git] / doc / man7 / EVP_KDF_SSHKDF.pod
1 =pod
2
3 =head1 NAME
4
5 EVP_KDF_SSHKDF - The SSHKDF EVP_KDF implementation
6
7 =head1 DESCRIPTION
8
9 Support for computing the B<SSHKDF> KDF through the B<EVP_KDF> API.
10
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.
17
18 =head2 Numeric identity
19
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.
22
23 =head2 Supported controls
24
25 The supported controls are:
26
27 =over 4
28
29 =item B<EVP_KDF_CTRL_SET_MD>
30
31 =item B<EVP_KDF_CTRL_SET_KEY>
32
33 These controls work as described in L<EVP_KDF_CTX(3)/CONTROLS>.
34
35 =item B<EVP_KDF_CTRL_SET_SSHKDF_XCGHASH>
36
37 =item B<EVP_KDF_CTRL_SET_SSHKDF_SESSION_ID>
38
39 These controls expect two arguments: C<unsigned char *buffer>, C<size_t length>
40
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.
43
44 EVP_KDF_ctrl_str() takes two type strings for these controls:
45
46 =over 4
47
48 =item "xcghash"
49
50 =item "session_id"
51
52 The value string is used as is.
53
54 =item "hexxcghash"
55
56 =item "hexsession_id"
57
58 The value string is expected to be a hexadecimal number, which will be
59 decoded before being passed on as the control value.
60
61 =back
62
63 =item B<EVP_KDF_CTRL_SET_SSHKDF_TYPE>
64
65 This control expects one argument: C<int mode>
66
67 Sets the type for the SSHHKDF operation. There are six supported types:
68
69 =over 4
70
71 =item EVP_KDF_SSHKDF_TYPE_ININITAL_IV_CLI_TO_SRV
72
73 The Initial IV from client to server.
74 A single char of value 65 (ASCII char 'A').
75
76 =item EVP_KDF_SSHKDF_TYPE_ININITAL_IV_SRV_TO_CLI
77
78 The Initial IV from server to client
79 A single char of value 66 (ASCII char 'B').
80
81 =item EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_CLI_TO_SRV
82
83 The Encryption Key from client to server
84 A single char of value 67 (ASCII char 'C').
85
86 =item EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_SRV_TO_CLI
87
88 The Encryption Key from server to client
89 A single char of value 68 (ASCII char 'D').
90
91 =item EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_CLI_TO_SRV
92
93 The Integrity Key from client to server
94 A single char of value 69 (ASCII char 'E').
95
96 =item EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_SRV_TO_CLI
97
98 The Integrity Key from client to server
99 A single char of value 70 (ASCII char 'F').
100
101 =back
102
103 EVP_KDF_ctrl_str() type string: "type"
104
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).
107
108 =back
109
110 =head1 NOTES
111
112 A context for SSHKDF can be obtained by calling:
113
114  EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_KDF_SSHKDF);
115
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.
122
123 =head1 EXAMPLE
124
125 This example derives an 8 byte IV using SHA-256 with a 1K "key" and appropriate
126 "xcghash" and "session_id" values:
127
128  EVP_KDF_CTX *kctx;
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);
135
136  if (EVP_KDF_CTX_set_md(kctx, EVP_sha256()) <= 0)
137      /* Error */
138  if (EVP_KDF_CTX_set1_key(kctx, key, 1024) <= 0)
139      /* Error */
140  if (EVP_KDF_CTX_set1_sshkdf_xcghash(kctx, xcghash, 32) <= 0)
141      /* Error */
142  if (EVP_KDF_CTX_set1_sshkdf_session_id(kctx, session_id, 32) <= 0)
143      /* Error */
144  if (EVP_KDF_CTX_set_sshkdf_type(kctx,
145                     EVP_KDF_SSHKDF_TYPE_ININITAL_IV_CLI_TO_SRV) <= 0)
146      /* Error */
147  if (EVP_KDF_derive(kctx, out, &outlen) <= 0)
148      /* Error */
149
150
151 =head1 CONFORMING TO
152
153 RFC 4253
154
155 =head1 SEE ALSO
156
157 L<EVP_KDF_CTX>,
158 L<EVP_KDF_CTX_new_id(3)>,
159 L<EVP_KDF_CTX_free(3)>,
160 L<EVP_KDF_ctrl(3)>,
161 L<EVP_KDF_size(3)>,
162 L<EVP_KDF_derive(3)>,
163 L<EVP_KDF_CTX(3)/CONTROLS>
164
165 =head1 COPYRIGHT
166
167 Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
168
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>.
173
174 =cut
175