b5dd4f930505d70984d0c0ce3e143aaa66d7f427
[strongswan.git] / src / libtls / tls_crypto.h
1 /*
2 * Copyright (C) 2020 Tobias Brunner
3 * Copyright (C) 2020 Pascal Knecht
4 * Copyright (C) 2020 Méline Sieber
5 * HSR Hochschule fuer Technik Rapperswil
6 *
7 * Copyright (C) 2010 Martin Willi
8 * Copyright (C) 2010 revosec AG
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * for more details.
19 */
20
21 /**
22 * @defgroup tls_crypto tls_crypto
23 * @{ @ingroup libtls
24 */
25
26 #ifndef TLS_CRYPTO_H_
27 #define TLS_CRYPTO_H_
28
29 typedef struct tls_crypto_t tls_crypto_t;
30 typedef enum tls_cipher_suite_t tls_cipher_suite_t;
31 typedef enum tls_hash_algorithm_t tls_hash_algorithm_t;
32 typedef enum tls_signature_scheme_t tls_signature_scheme_t;
33 typedef enum tls_client_certificate_type_t tls_client_certificate_type_t;
34 typedef enum tls_ecc_curve_type_t tls_ecc_curve_type_t;
35 typedef enum tls_named_group_t tls_named_group_t;
36 typedef enum tls_ansi_point_format_t tls_ansi_point_format_t;
37 typedef enum tls_ec_point_format_t tls_ec_point_format_t;
38
39 #include "tls.h"
40 #include "tls_prf.h"
41 #include "tls_protection.h"
42
43 #include <library.h>
44
45 #include <credentials/keys/private_key.h>
46
47 /**
48 * TLS cipher suites
49 */
50 enum tls_cipher_suite_t {
51 TLS_NULL_WITH_NULL_NULL = 0x0000,
52 TLS_RSA_WITH_NULL_MD5 = 0x0001,
53 TLS_RSA_WITH_NULL_SHA = 0x0002,
54 TLS_RSA_EXPORT_WITH_RC4_40_MD5 = 0x0003,
55 TLS_RSA_WITH_RC4_128_MD5 = 0x0004,
56 TLS_RSA_WITH_RC4_128_SHA = 0x0005,
57 TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 = 0x0006,
58 TLS_RSA_WITH_IDEA_CBC_SHA = 0x0007,
59 TLS_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x0008,
60 TLS_RSA_WITH_DES_CBC_SHA = 0x0009,
61 TLS_RSA_WITH_3DES_EDE_CBC_SHA = 0x000A,
62 TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA = 0x000B,
63 TLS_DH_DSS_WITH_DES_CBC_SHA = 0x000C,
64 TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA = 0x000D,
65 TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x000E,
66 TLS_DH_RSA_WITH_DES_CBC_SHA = 0x000F,
67 TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA = 0x0010,
68 TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA = 0x0011,
69 TLS_DHE_DSS_WITH_DES_CBC_SHA = 0x0012,
70 TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA = 0x0013,
71 TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x0014,
72 TLS_DHE_RSA_WITH_DES_CBC_SHA = 0x0015,
73 TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA = 0x0016,
74 TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 = 0x0017,
75 TLS_DH_anon_WITH_RC4_128_MD5 = 0x0018,
76 TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA = 0x0019,
77 TLS_DH_anon_WITH_DES_CBC_SHA = 0x001A,
78 TLS_DH_anon_WITH_3DES_EDE_CBC_SHA = 0x001B,
79
80 TLS_KRB5_WITH_DES_CBC_SHA = 0x001E,
81 TLS_KRB5_WITH_3DES_EDE_CBC_SHA = 0x001F,
82 TLS_KRB5_WITH_RC4_128_SHA = 0x0020,
83 TLS_KRB5_WITH_IDEA_CBC_SHA = 0x0021,
84 TLS_KRB5_WITH_DES_CBC_MD5 = 0x0022,
85 TLS_KRB5_WITH_3DES_EDE_CBC_MD5 = 0x0023,
86 TLS_KRB5_WITH_RC4_128_MD5 = 0x0024,
87 TLS_KRB5_WITH_IDEA_CBC_MD5 = 0x0025,
88 TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA = 0x0026,
89 TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA = 0x0027,
90 TLS_KRB5_EXPORT_WITH_RC4_40_SHA = 0x0028,
91 TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5 = 0x0029,
92 TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5 = 0x002A,
93 TLS_KRB5_EXPORT_WITH_RC4_40_MD5 = 0x002B,
94 TLS_PSK_WITH_NULL_SHA = 0x002C,
95 TLS_DHE_PSK_WITH_NULL_SHA = 0x002D,
96 TLS_RSA_PSK_WITH_NULL_SHA = 0x002E,
97 TLS_RSA_WITH_AES_128_CBC_SHA = 0x002F,
98 TLS_DH_DSS_WITH_AES_128_CBC_SHA = 0x0030,
99 TLS_DH_RSA_WITH_AES_128_CBC_SHA = 0x0031,
100 TLS_DHE_DSS_WITH_AES_128_CBC_SHA = 0x0032,
101 TLS_DHE_RSA_WITH_AES_128_CBC_SHA = 0x0033,
102 TLS_DH_anon_WITH_AES_128_CBC_SHA = 0x0034,
103 TLS_RSA_WITH_AES_256_CBC_SHA = 0x0035,
104 TLS_DH_DSS_WITH_AES_256_CBC_SHA = 0x0036,
105 TLS_DH_RSA_WITH_AES_256_CBC_SHA = 0x0037,
106 TLS_DHE_DSS_WITH_AES_256_CBC_SHA = 0x0038,
107 TLS_DHE_RSA_WITH_AES_256_CBC_SHA = 0x0039,
108 TLS_DH_anon_WITH_AES_256_CBC_SHA = 0x003A,
109 TLS_RSA_WITH_NULL_SHA256 = 0x003B,
110 TLS_RSA_WITH_AES_128_CBC_SHA256 = 0x003C,
111 TLS_RSA_WITH_AES_256_CBC_SHA256 = 0x003D,
112 TLS_DH_DSS_WITH_AES_128_CBC_SHA256 = 0x003E,
113 TLS_DH_RSA_WITH_AES_128_CBC_SHA256 = 0x003F,
114 TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 = 0x0040,
115 TLS_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x0041,
116 TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA = 0x0042,
117 TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x0043,
118 TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA = 0x0044,
119 TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x0045,
120 TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA = 0x0046,
121
122 TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 = 0x0067,
123 TLS_DH_DSS_WITH_AES_256_CBC_SHA256 = 0x0068,
124 TLS_DH_RSA_WITH_AES_256_CBC_SHA256 = 0x0069,
125 TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 = 0x006A,
126 TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 = 0x006B,
127 TLS_DH_anon_WITH_AES_128_CBC_SHA256 = 0x006C,
128 TLS_DH_anon_WITH_AES_256_CBC_SHA256 = 0x006D,
129
130 TLS_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x0084,
131 TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA = 0x0085,
132 TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x0086,
133 TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA = 0x0087,
134 TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x0088,
135 TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA = 0x0089,
136 TLS_PSK_WITH_RC4_128_SHA = 0x008A,
137 TLS_PSK_WITH_3DES_EDE_CBC_SHA = 0x008B,
138 TLS_PSK_WITH_AES_128_CBC_SHA = 0x008C,
139 TLS_PSK_WITH_AES_256_CBC_SHA = 0x008D,
140 TLS_DHE_PSK_WITH_RC4_128_SHA = 0x008E,
141 TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA = 0x008F,
142 TLS_DHE_PSK_WITH_AES_128_CBC_SHA = 0x0090,
143 TLS_DHE_PSK_WITH_AES_256_CBC_SHA = 0x0091,
144 TLS_RSA_PSK_WITH_RC4_128_SHA = 0x0092,
145 TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA = 0x0093,
146 TLS_RSA_PSK_WITH_AES_128_CBC_SHA = 0x0094,
147 TLS_RSA_PSK_WITH_AES_256_CBC_SHA = 0x0095,
148 TLS_RSA_WITH_SEED_CBC_SHA = 0x0096,
149 TLS_DH_DSS_WITH_SEED_CBC_SHA = 0x0097,
150 TLS_DH_RSA_WITH_SEED_CBC_SHA = 0x0098,
151 TLS_DHE_DSS_WITH_SEED_CBC_SHA = 0x0099,
152 TLS_DHE_RSA_WITH_SEED_CBC_SHA = 0x009A,
153 TLS_DH_anon_WITH_SEED_CBC_SHA = 0x009B,
154 TLS_RSA_WITH_AES_128_GCM_SHA256 = 0x009C,
155 TLS_RSA_WITH_AES_256_GCM_SHA384 = 0x009D,
156 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 = 0x009E,
157 TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 = 0x009F,
158 TLS_DH_RSA_WITH_AES_128_GCM_SHA256 = 0x00A0,
159 TLS_DH_RSA_WITH_AES_256_GCM_SHA384 = 0x00A1,
160 TLS_DHE_DSS_WITH_AES_128_GCM_SHA256 = 0x00A2,
161 TLS_DHE_DSS_WITH_AES_256_GCM_SHA384 = 0x00A3,
162 TLS_DH_DSS_WITH_AES_128_GCM_SHA256 = 0x00A4,
163 TLS_DH_DSS_WITH_AES_256_GCM_SHA384 = 0x00A5,
164 TLS_DH_anon_WITH_AES_128_GCM_SHA256 = 0x00A6,
165 TLS_DH_anon_WITH_AES_256_GCM_SHA384 = 0x00A7,
166 TLS_PSK_WITH_AES_128_GCM_SHA256 = 0x00A8,
167 TLS_PSK_WITH_AES_256_GCM_SHA384 = 0x00A9,
168 TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 = 0x00AA,
169 TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 = 0x00AB,
170 TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 = 0x00AC,
171 TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 = 0x00AD,
172 TLS_PSK_WITH_AES_128_CBC_SHA256 = 0x00AE,
173 TLS_PSK_WITH_AES_256_CBC_SHA384 = 0x00AF,
174 TLS_PSK_WITH_NULL_SHA256 = 0x00B0,
175 TLS_PSK_WITH_NULL_SHA384 = 0x00B1,
176 TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 = 0x00B2,
177 TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 = 0x00B3,
178 TLS_DHE_PSK_WITH_NULL_SHA256 = 0x00B4,
179 TLS_DHE_PSK_WITH_NULL_SHA384 = 0x00B5,
180 TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 = 0x00B6,
181 TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 = 0x00B7,
182 TLS_RSA_PSK_WITH_NULL_SHA256 = 0x00B8,
183 TLS_RSA_PSK_WITH_NULL_SHA384 = 0x00B9,
184 TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BA,
185 TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BB,
186 TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BC,
187 TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BD,
188 TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BE,
189 TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BF,
190 TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C0,
191 TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C1,
192 TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C2,
193 TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C3,
194 TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C4,
195 TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C5,
196
197 TLS_EMPTY_RENEGOTIATION_INFO_SCSV = 0x00FF,
198
199 TLS_AES_128_GCM_SHA256 = 0x1301,
200 TLS_AES_256_GCM_SHA384 = 0x1302,
201 TLS_CHACHA20_POLY1305_SHA256 = 0x1303,
202 TLS_AES_128_CCM_SHA256 = 0x1304,
203 TLS_AES_128_CCM_8_SHA256 = 0x1305,
204
205 TLS_ECDH_ECDSA_WITH_NULL_SHA = 0xC001,
206 TLS_ECDH_ECDSA_WITH_RC4_128_SHA = 0xC002,
207 TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA = 0xC003,
208 TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA = 0xC004,
209 TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA = 0xC005,
210 TLS_ECDHE_ECDSA_WITH_NULL_SHA = 0xC006,
211 TLS_ECDHE_ECDSA_WITH_RC4_128_SHA = 0xC007,
212 TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA = 0xC008,
213 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 0xC009,
214 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 0xC00A,
215 TLS_ECDH_RSA_WITH_NULL_SHA = 0xC00B,
216 TLS_ECDH_RSA_WITH_RC4_128_SHA = 0xC00C,
217 TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA = 0xC00D,
218 TLS_ECDH_RSA_WITH_AES_128_CBC_SHA = 0xC00E,
219 TLS_ECDH_RSA_WITH_AES_256_CBC_SHA = 0xC00F,
220 TLS_ECDHE_RSA_WITH_NULL_SHA = 0xC010,
221 TLS_ECDHE_RSA_WITH_RC4_128_SHA = 0xC011,
222 TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA = 0xC012,
223 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = 0xC013,
224 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0xC014,
225 TLS_ECDH_anon_WITH_NULL_SHA = 0xC015,
226 TLS_ECDH_anon_WITH_RC4_128_SHA = 0xC016,
227 TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA = 0xC017,
228 TLS_ECDH_anon_WITH_AES_128_CBC_SHA = 0xC018,
229 TLS_ECDH_anon_WITH_AES_256_CBC_SHA = 0xC019,
230 TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA = 0xC01A,
231 TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA = 0xC01B,
232 TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA = 0xC01C,
233 TLS_SRP_SHA_WITH_AES_128_CBC_SHA = 0xC01D,
234 TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA = 0xC01E,
235 TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA = 0xC01F,
236 TLS_SRP_SHA_WITH_AES_256_CBC_SHA = 0xC020,
237 TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA = 0xC021,
238 TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA = 0xC022,
239 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 = 0xC023,
240 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 = 0xC024,
241 TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 = 0xC025,
242 TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 = 0xC026,
243 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 = 0xC027,
244 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 = 0xC028,
245 TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 = 0xC029,
246 TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 = 0xC02A,
247 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0xC02B,
248 TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 0xC02C,
249 TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 = 0xC02D,
250 TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 = 0xC02E,
251 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0xC02F,
252 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0xC030,
253 TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 = 0xC031,
254 TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 = 0xC032,
255 TLS_ECDHE_PSK_WITH_RC4_128_SHA = 0xC033,
256 TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA = 0xC034,
257 TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA = 0xC035,
258 TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA = 0xC036,
259 TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 = 0xC037,
260 TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 = 0xC038,
261 TLS_ECDHE_PSK_WITH_NULL_SHA = 0xC039,
262 TLS_ECDHE_PSK_WITH_NULL_SHA256 = 0xC03A,
263 TLS_ECDHE_PSK_WITH_NULL_SHA384 = 0xC03B
264 };
265
266 /**
267 * Enum names for tls_cipher_suite_t
268 */
269 extern enum_name_t *tls_cipher_suite_names;
270
271 /**
272 * TLS HashAlgorithm identifiers
273 */
274 enum tls_hash_algorithm_t {
275 TLS_HASH_NONE = 0,
276 TLS_HASH_MD5 = 1,
277 TLS_HASH_SHA1 = 2,
278 TLS_HASH_SHA224 = 3,
279 TLS_HASH_SHA256 = 4,
280 TLS_HASH_SHA384 = 5,
281 TLS_HASH_SHA512 = 6,
282 };
283
284 /**
285 * Enum names for tls_hash_algorithm_t
286 */
287 extern enum_name_t *tls_hash_algorithm_names;
288
289 /**
290 * TLS SignatureScheme identifiers
291 */
292 enum tls_signature_scheme_t {
293 /* legacy schemes compatible with TLS 1.2 (first byte is the hash algorithm,
294 * second the key type) */
295 TLS_SIG_RSA_PKCS1_SHA1 = 0x0201,
296 TLS_SIG_ECDSA_SHA1 = 0x0203,
297 TLS_SIG_RSA_PKCS1_SHA256 = 0x0401,
298 TLS_SIG_ECDSA_SHA256 = 0x0403,
299 TLS_SIG_RSA_PKCS1_SHA384 = 0x0501,
300 TLS_SIG_ECDSA_SHA384 = 0x0503,
301 TLS_SIG_RSA_PKCS1_SHA512 = 0x0601,
302 TLS_SIG_ECDSA_SHA512 = 0x0603,
303 /* RSASSA-PSS for public keys with OID rsaEncryption */
304 TLS_SIG_RSA_PSS_RSAE_SHA256 = 0x0804,
305 TLS_SIG_RSA_PSS_RSAE_SHA384 = 0x0805,
306 TLS_SIG_RSA_PSS_RSAE_SHA512 = 0x0806,
307 /* EdDSA */
308 TLS_SIG_ED25519 = 0x0807,
309 TLS_SIG_ED448 = 0x0808,
310 /* RSASSA-PSS for public keys with OID RSASSA-PSS */
311 TLS_SIG_RSA_PSS_PSS_SHA256 = 0x0809,
312 TLS_SIG_RSA_PSS_PSS_SHA384 = 0x080a,
313 TLS_SIG_RSA_PSS_PSS_SHA512 = 0x080b,
314 };
315
316 /**
317 * Enum names for tls_signature_scheme_t
318 */
319 extern enum_name_t *tls_signature_scheme_names;
320
321 /**
322 * TLS ClientCertificateType
323 */
324 enum tls_client_certificate_type_t {
325 TLS_RSA_SIGN = 1,
326 TLS_DSA_SIGN = 2,
327 TLS_RSA_FIXED_DH = 3,
328 TLS_DSS_FIXED_DH = 4,
329 TLS_RSA_EPHEMERAL_DH = 5,
330 TLS_DSS_EPHEMERAL_DH = 6,
331 TLS_FORTEZZA_DMS = 20,
332 TLS_ECDSA_SIGN = 64,
333 TLS_RSA_FIXED_ECDH = 65,
334 TLS_ECDSA_FIXED_ECDH = 66,
335 };
336
337 /**
338 * Enum names for tls_client_certificate_type_t
339 */
340 extern enum_name_t *tls_client_certificate_type_names;
341
342 /**
343 * TLS EccCurveType
344 */
345 enum tls_ecc_curve_type_t {
346 TLS_ECC_EXPLICIT_PRIME = 1,
347 TLS_ECC_EXPLICIT_CHAR2 = 2,
348 TLS_ECC_NAMED_CURVE = 3,
349 };
350
351 /**
352 * Enum names for tls_ecc_curve_type_t
353 */
354 extern enum_name_t *tls_ecc_curve_type_names;
355
356 /**
357 * TLS Named Curve identifiers
358 */
359 enum tls_named_group_t {
360 TLS_SECT163K1 = 1,
361 TLS_SECT163R1 = 2,
362 TLS_SECT163R2 = 3,
363 TLS_SECT193R1 = 4,
364 TLS_SECT193R2 = 5,
365 TLS_SECT233K1 = 6,
366 TLS_SECT233R1 = 7,
367 TLS_SECT239K1 = 8,
368 TLS_SECT283K1 = 9,
369 TLS_SECT283R1 = 10,
370 TLS_SECT409K1 = 11,
371 TLS_SECT409R1 = 12,
372 TLS_SECT571K1 = 13,
373 TLS_SECT571R1 = 14,
374 TLS_SECP160K1 = 15,
375 TLS_SECP160R1 = 16,
376 TLS_SECP160R2 = 17,
377 TLS_SECP192K1 = 18,
378 TLS_SECP192R1 = 19,
379 TLS_SECP224K1 = 20,
380 TLS_SECP224R1 = 21,
381 TLS_SECP256K1 = 22,
382 TLS_SECP256R1 = 23,
383 TLS_SECP384R1 = 24,
384 TLS_SECP521R1 = 25,
385
386 /* TLS 1.3: new ecdhe, dhe groups */
387 TLS_CURVE25519 = 29,
388 TLS_CURVE448 = 30,
389 TLS_FFDHE2048 = 256,
390 TLS_FFDHE3072 = 257,
391 TLS_FFDHE4096 = 258,
392 TLS_FFDHE6144 = 259,
393 TLS_FFDHE8192 = 260,
394 };
395
396 /**
397 * Enum names for tls_named_group_t
398 */
399 extern enum_name_t *tls_named_group_names;
400
401 /**
402 * EC Point format, ANSI X9.62.
403 */
404 enum tls_ansi_point_format_t {
405 TLS_ANSI_COMPRESSED = 2,
406 TLS_ANSI_COMPRESSED_Y = 3,
407 TLS_ANSI_UNCOMPRESSED = 4,
408 TLS_ANSI_HYBRID = 6,
409 TLS_ANSI_HYBRID_Y = 7,
410 };
411
412 /**
413 * Enum names for tls_ansi_point_format_t.
414 */
415 extern enum_name_t *tls_ansi_point_format_names;
416
417 /**
418 * EC Point format, TLS specific identifiers.
419 */
420 enum tls_ec_point_format_t {
421 TLS_EC_POINT_UNCOMPRESSED = 0,
422 TLS_EC_POINT_ANSIX962_COMPRESSED_PRIME = 1,
423 TLS_EC_POINT_ANSIX962_COMPRESSED_CHAR2 = 2,
424 };
425
426 /**
427 * Enum names for tls_ec_point_format_t.
428 */
429 extern enum_name_t *tls_ec_point_format_names;
430
431 /**
432 * TLS crypto helper functions.
433 */
434 struct tls_crypto_t {
435
436 /**
437 * Get a list of supported TLS cipher suites.
438 *
439 * @param suites list of suites, points to internal data
440 * @return number of suites returned
441 */
442 int (*get_cipher_suites)(tls_crypto_t *this, tls_cipher_suite_t **suites);
443
444 /**
445 * Select and store a cipher suite from a given list of candidates.
446 *
447 * @param suites list of candidates to select from
448 * @param count number of suites
449 * @param key key type used, or KEY_ANY
450 * @return selected suite, 0 if none acceptable
451 */
452 tls_cipher_suite_t (*select_cipher_suite)(tls_crypto_t *this,
453 tls_cipher_suite_t *suites, int count,
454 key_type_t key);
455
456 /**
457 * Get the Diffie-Hellman group to use, if any.
458 *
459 * @return Diffie Hellman group, ord MODP_NONE
460 */
461 diffie_hellman_group_t (*get_dh_group)(tls_crypto_t *this);
462
463 /**
464 * Write the list of supported signature schemes, either for certificates
465 * or for CertificateVerify messages, to writer.
466 *
467 * @param writer writer to write supported signature schemes
468 * @param cert TRUE to return signature schemes supported in certs
469 */
470 void (*get_signature_algorithms)(tls_crypto_t *this, bio_writer_t *writer,
471 bool cert);
472
473 /**
474 * Create an enumerator over supported ECDH groups.
475 *
476 * Enumerates over (diffie_hellman_group_t, tls_named_group_t)
477 *
478 * @return enumerator
479 */
480 enumerator_t* (*create_ec_enumerator)(tls_crypto_t *this);
481
482 /**
483 * Set the protection layer of the TLS stack to control it.
484 *
485 * @param protection protection layer to work on
486 */
487 void (*set_protection)(tls_crypto_t *this, tls_protection_t *protection);
488
489 /**
490 * Store exchanged handshake data, used for cryptographic operations.
491 *
492 * @param type handshake sub type
493 * @param data data to append to handshake buffer
494 */
495 void (*append_handshake)(tls_crypto_t *this,
496 tls_handshake_type_t type, chunk_t data);
497
498 /**
499 * Hash the stored handshake data and store it. It is optionally returned
500 * so it could be sent in a cookie extension.
501 *
502 * @param hash optionally returned hash (allocated)
503 */
504 bool (*hash_handshake)(tls_crypto_t *this, chunk_t *hash);
505
506 /**
507 * Sign a blob of data, append signature to writer.
508 *
509 * @param key private key to use for signature
510 * @param writer TLS writer to write signature to
511 * @param data data to sign
512 * @param hashsig list of TLS1.2 hash/sig algorithms to select from
513 * @return TRUE if signature create successfully
514 */
515 bool (*sign)(tls_crypto_t *this, private_key_t *key,
516 bio_writer_t *writer, chunk_t data, chunk_t hashsig);
517
518 /**
519 * Verify a blob of data, read signature from a reader.
520 *
521 * @param key public key to verify signature with
522 * @param reader TLS reader to read signature from
523 * @param data data to verify signature
524 * @return TRUE if signature valid
525 */
526 bool (*verify)(tls_crypto_t *this, public_key_t *key,
527 bio_reader_t *reader, chunk_t data);
528
529 /**
530 * Create a signature of the handshake data using a given private key.
531 *
532 * @param key private key to use for signature
533 * @param writer TLS writer to write signature to
534 * @param hashsig list of TLS1.2 hash/sig algorithms to select from
535 * @return TRUE if signature create successfully
536 */
537 bool (*sign_handshake)(tls_crypto_t *this, private_key_t *key,
538 bio_writer_t *writer, chunk_t hashsig);
539
540 /**
541 * Verify the signature over handshake data using a given public key.
542 *
543 * @param key public key to verify signature with
544 * @param reader TLS reader to read signature from
545 * @return TRUE if signature valid
546 */
547 bool (*verify_handshake)(tls_crypto_t *this, public_key_t *key,
548 bio_reader_t *reader);
549
550 /**
551 * Calculate the data of a legacy TLS finished message.
552 *
553 * @param label ASCII label to use for calculation
554 * @param out buffer to write finished data to
555 * @return TRUE if calculation successful
556 */
557 bool (*calculate_finished_legacy)(tls_crypto_t *this, char *label,
558 char out[12]);
559
560 /**
561 * Calculate the data of a TLS finished message.
562 *
563 * @param out buffer to write finished data to
564 * @return TRUE if calculation successful
565 */
566 bool (*calculate_finished)(tls_crypto_t *this, bool is_server,
567 chunk_t *out);
568
569 /**
570 * Derive the master secret, MAC and encryption keys.
571 *
572 * @param premaster premaster secret
573 * @param session session identifier to cache master secret
574 * @param id identity the session is bound to
575 * @param client_random random data from client hello
576 * @param server_random random data from server hello
577 * @return TRUE if secrets derived successfully
578 */
579 bool (*derive_secrets)(tls_crypto_t *this, chunk_t premaster,
580 chunk_t session, identification_t *id,
581 chunk_t client_random, chunk_t server_random);
582
583 /**
584 * Derive the handshake keys.
585 *
586 * @param shared_secret input key material
587 * @return TRUE if secret derived successfully
588 */
589 bool (*derive_handshake_keys)(tls_crypto_t *this, chunk_t shared_secret);
590
591 /**
592 * Derive the application keys.
593 *
594 * @return TRUE if secret derived successfully
595 */
596 bool (*derive_app_keys)(tls_crypto_t *this);
597
598 /**
599 * Update the application keys.
600 *
601 * @param inbound whether to update the in- or outbound keys
602 * @return TRUE if secret derived successfully
603 */
604 bool (*update_app_keys)(tls_crypto_t *this, bool inbound);
605
606 /**
607 * Try to resume a TLS session, derive key material.
608 *
609 * @param session session identifier
610 * @param id identity the session is bound to
611 * @param client_random random data from client hello
612 * @param server_random random data from server hello
613 * @return selected suite
614 */
615 tls_cipher_suite_t (*resume_session)(tls_crypto_t *this, chunk_t session,
616 identification_t *id,
617 chunk_t client_random,
618 chunk_t server_random);
619
620 /**
621 * Check if we have a session to resume as a client.
622 *
623 * @param id server identity to get a session for
624 * @return allocated session identifier, or chunk_empty
625 */
626 chunk_t (*get_session)(tls_crypto_t *this, identification_t *id);
627
628 /**
629 * Change the cipher used at protection layer.
630 *
631 * @param inbound TRUE to change inbound cipher, FALSE for outbound
632 */
633 void (*change_cipher)(tls_crypto_t *this, bool inbound);
634
635 /**
636 * Get the MSK to use in EAP-TLS.
637 *
638 * @return MSK, points to internal data
639 */
640 chunk_t (*get_eap_msk)(tls_crypto_t *this);
641
642 /**
643 * Destroy a tls_crypto_t.
644 */
645 void (*destroy)(tls_crypto_t *this);
646 };
647
648 /**
649 * Create a tls_crypto instance.
650 *
651 * @param tls TLS stack
652 * @param cache TLS session cache
653 * @return TLS crypto helper
654 */
655 tls_crypto_t *tls_crypto_create(tls_t *tls, tls_cache_t *cache);
656
657 /**
658 * Get a list of all supported TLS cipher suites.
659 *
660 * @param null include supported NULL encryption suites
661 * @param version TLS version
662 * @param suites pointer to allocated suites array, to free(), or NULL
663 * @return number of suites supported
664 */
665 int tls_crypto_get_supported_suites(bool null, tls_version_t version,
666 tls_cipher_suite_t **suites);
667
668 #endif /** TLS_CRYPTO_H_ @}*/