xref: /freebsd/contrib/wpa/src/tls/tlsv1_record.h (revision fcb560670601b2a4d87bb31d7531c8dcc37ee71b)
1 /*
2  * TLSv1 Record Protocol
3  * Copyright (c) 2006-2011, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #ifndef TLSV1_RECORD_H
10 #define TLSV1_RECORD_H
11 
12 #include "crypto/crypto.h"
13 
14 #define TLS_MAX_WRITE_MAC_SECRET_LEN 32
15 #define TLS_MAX_WRITE_KEY_LEN 32
16 #define TLS_MAX_IV_LEN 16
17 #define TLS_MAX_KEY_BLOCK_LEN (2 * (TLS_MAX_WRITE_MAC_SECRET_LEN + \
18 				    TLS_MAX_WRITE_KEY_LEN + TLS_MAX_IV_LEN))
19 
20 #define TLS_SEQ_NUM_LEN 8
21 #define TLS_RECORD_HEADER_LEN 5
22 
23 /* ContentType */
24 enum {
25 	TLS_CONTENT_TYPE_CHANGE_CIPHER_SPEC = 20,
26 	TLS_CONTENT_TYPE_ALERT = 21,
27 	TLS_CONTENT_TYPE_HANDSHAKE = 22,
28 	TLS_CONTENT_TYPE_APPLICATION_DATA = 23
29 };
30 
31 struct tlsv1_record_layer {
32 	u16 tls_version;
33 
34 	u8 write_mac_secret[TLS_MAX_WRITE_MAC_SECRET_LEN];
35 	u8 read_mac_secret[TLS_MAX_WRITE_MAC_SECRET_LEN];
36 	u8 write_key[TLS_MAX_WRITE_KEY_LEN];
37 	u8 read_key[TLS_MAX_WRITE_KEY_LEN];
38 	u8 write_iv[TLS_MAX_IV_LEN];
39 	u8 read_iv[TLS_MAX_IV_LEN];
40 
41 	size_t hash_size;
42 	size_t key_material_len;
43 	size_t iv_size; /* also block_size */
44 
45 	enum crypto_hash_alg hash_alg;
46 	enum crypto_cipher_alg cipher_alg;
47 
48 	u8 write_seq_num[TLS_SEQ_NUM_LEN];
49 	u8 read_seq_num[TLS_SEQ_NUM_LEN];
50 
51 	u16 cipher_suite;
52 	u16 write_cipher_suite;
53 	u16 read_cipher_suite;
54 
55 	struct crypto_cipher *write_cbc;
56 	struct crypto_cipher *read_cbc;
57 };
58 
59 
60 int tlsv1_record_set_cipher_suite(struct tlsv1_record_layer *rl,
61 				  u16 cipher_suite);
62 int tlsv1_record_change_write_cipher(struct tlsv1_record_layer *rl);
63 int tlsv1_record_change_read_cipher(struct tlsv1_record_layer *rl);
64 int tlsv1_record_send(struct tlsv1_record_layer *rl, u8 content_type, u8 *buf,
65 		      size_t buf_size, const u8 *payload, size_t payload_len,
66 		      size_t *out_len);
67 int tlsv1_record_receive(struct tlsv1_record_layer *rl,
68 			 const u8 *in_data, size_t in_len,
69 			 u8 *out_data, size_t *out_len, u8 *alert);
70 
71 #endif /* TLSV1_RECORD_H */
72