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