2 * TLSv1 Record Protocol
3 * Copyright (c) 2006-2011, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
10 #define TLSV1_RECORD_H
12 #include "crypto/crypto.h"
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))
20 #define TLS_SEQ_NUM_LEN 8
21 #define TLS_RECORD_HEADER_LEN 5
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
31 struct tlsv1_record_layer {
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];
42 size_t key_material_len;
43 size_t iv_size; /* also block_size */
45 enum crypto_hash_alg hash_alg;
46 enum crypto_cipher_alg cipher_alg;
48 u8 write_seq_num[TLS_SEQ_NUM_LEN];
49 u8 read_seq_num[TLS_SEQ_NUM_LEN];
52 u16 write_cipher_suite;
53 u16 read_cipher_suite;
55 struct crypto_cipher *write_cbc;
56 struct crypto_cipher *read_cbc;
60 int tlsv1_record_set_cipher_suite(struct tlsv1_record_layer *rl,
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,
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);
71 #endif /* TLSV1_RECORD_H */