$search
00001 /* 00002 * TLSv1 Record Protocol 00003 * Copyright (c) 2006-2007, Jouni Malinen <j@w1.fi> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation. 00008 * 00009 * Alternatively, this software may be distributed under the terms of BSD 00010 * license. 00011 * 00012 * See README and COPYING for more details. 00013 */ 00014 00015 #ifndef TLSV1_RECORD_H 00016 #define TLSV1_RECORD_H 00017 00018 #include "crypto/crypto.h" 00019 00020 #define TLS_MAX_WRITE_MAC_SECRET_LEN 20 00021 #define TLS_MAX_WRITE_KEY_LEN 32 00022 #define TLS_MAX_IV_LEN 16 00023 #define TLS_MAX_KEY_BLOCK_LEN (2 * (TLS_MAX_WRITE_MAC_SECRET_LEN + \ 00024 TLS_MAX_WRITE_KEY_LEN + TLS_MAX_IV_LEN)) 00025 00026 #define TLS_SEQ_NUM_LEN 8 00027 #define TLS_RECORD_HEADER_LEN 5 00028 00029 /* ContentType */ 00030 enum { 00031 TLS_CONTENT_TYPE_CHANGE_CIPHER_SPEC = 20, 00032 TLS_CONTENT_TYPE_ALERT = 21, 00033 TLS_CONTENT_TYPE_HANDSHAKE = 22, 00034 TLS_CONTENT_TYPE_APPLICATION_DATA = 23 00035 }; 00036 00037 struct tlsv1_record_layer { 00038 u8 write_mac_secret[TLS_MAX_WRITE_MAC_SECRET_LEN]; 00039 u8 read_mac_secret[TLS_MAX_WRITE_MAC_SECRET_LEN]; 00040 u8 write_key[TLS_MAX_WRITE_KEY_LEN]; 00041 u8 read_key[TLS_MAX_WRITE_KEY_LEN]; 00042 u8 write_iv[TLS_MAX_IV_LEN]; 00043 u8 read_iv[TLS_MAX_IV_LEN]; 00044 00045 size_t hash_size; 00046 size_t key_material_len; 00047 size_t iv_size; /* also block_size */ 00048 00049 enum crypto_hash_alg hash_alg; 00050 enum crypto_cipher_alg cipher_alg; 00051 00052 u8 write_seq_num[TLS_SEQ_NUM_LEN]; 00053 u8 read_seq_num[TLS_SEQ_NUM_LEN]; 00054 00055 u16 cipher_suite; 00056 u16 write_cipher_suite; 00057 u16 read_cipher_suite; 00058 00059 struct crypto_cipher *write_cbc; 00060 struct crypto_cipher *read_cbc; 00061 }; 00062 00063 00064 int tlsv1_record_set_cipher_suite(struct tlsv1_record_layer *rl, 00065 u16 cipher_suite); 00066 int tlsv1_record_change_write_cipher(struct tlsv1_record_layer *rl); 00067 int tlsv1_record_change_read_cipher(struct tlsv1_record_layer *rl); 00068 int tlsv1_record_send(struct tlsv1_record_layer *rl, u8 content_type, u8 *buf, 00069 size_t buf_size, size_t payload_len, size_t *out_len); 00070 int tlsv1_record_receive(struct tlsv1_record_layer *rl, 00071 const u8 *in_data, size_t in_len, 00072 u8 *out_data, size_t *out_len, u8 *alert); 00073 00074 #endif /* TLSV1_RECORD_H */