18dbcf02cSchristos /* 2*62a52023Schristos * TLSv1 Record Protocol 342669be3Schristos * Copyright (c) 2006-2011, Jouni Malinen <j@w1.fi> 48dbcf02cSchristos * 5*62a52023Schristos * This software may be distributed under the terms of the BSD license. 6*62a52023Schristos * See README for more details. 78dbcf02cSchristos */ 88dbcf02cSchristos 98dbcf02cSchristos #ifndef TLSV1_RECORD_H 108dbcf02cSchristos #define TLSV1_RECORD_H 118dbcf02cSchristos 128dbcf02cSchristos #include "crypto/crypto.h" 138dbcf02cSchristos 14*62a52023Schristos #define TLS_MAX_WRITE_MAC_SECRET_LEN 32 158dbcf02cSchristos #define TLS_MAX_WRITE_KEY_LEN 32 168dbcf02cSchristos #define TLS_MAX_IV_LEN 16 178dbcf02cSchristos #define TLS_MAX_KEY_BLOCK_LEN (2 * (TLS_MAX_WRITE_MAC_SECRET_LEN + \ 188dbcf02cSchristos TLS_MAX_WRITE_KEY_LEN + TLS_MAX_IV_LEN)) 198dbcf02cSchristos 208dbcf02cSchristos #define TLS_SEQ_NUM_LEN 8 218dbcf02cSchristos #define TLS_RECORD_HEADER_LEN 5 228dbcf02cSchristos 238dbcf02cSchristos /* ContentType */ 248dbcf02cSchristos enum { 258dbcf02cSchristos TLS_CONTENT_TYPE_CHANGE_CIPHER_SPEC = 20, 268dbcf02cSchristos TLS_CONTENT_TYPE_ALERT = 21, 278dbcf02cSchristos TLS_CONTENT_TYPE_HANDSHAKE = 22, 288dbcf02cSchristos TLS_CONTENT_TYPE_APPLICATION_DATA = 23 298dbcf02cSchristos }; 308dbcf02cSchristos 318dbcf02cSchristos struct tlsv1_record_layer { 3242669be3Schristos u16 tls_version; 3342669be3Schristos 348dbcf02cSchristos u8 write_mac_secret[TLS_MAX_WRITE_MAC_SECRET_LEN]; 358dbcf02cSchristos u8 read_mac_secret[TLS_MAX_WRITE_MAC_SECRET_LEN]; 368dbcf02cSchristos u8 write_key[TLS_MAX_WRITE_KEY_LEN]; 378dbcf02cSchristos u8 read_key[TLS_MAX_WRITE_KEY_LEN]; 388dbcf02cSchristos u8 write_iv[TLS_MAX_IV_LEN]; 398dbcf02cSchristos u8 read_iv[TLS_MAX_IV_LEN]; 408dbcf02cSchristos 418dbcf02cSchristos size_t hash_size; 428dbcf02cSchristos size_t key_material_len; 438dbcf02cSchristos size_t iv_size; /* also block_size */ 448dbcf02cSchristos 458dbcf02cSchristos enum crypto_hash_alg hash_alg; 468dbcf02cSchristos enum crypto_cipher_alg cipher_alg; 478dbcf02cSchristos 488dbcf02cSchristos u8 write_seq_num[TLS_SEQ_NUM_LEN]; 498dbcf02cSchristos u8 read_seq_num[TLS_SEQ_NUM_LEN]; 508dbcf02cSchristos 518dbcf02cSchristos u16 cipher_suite; 528dbcf02cSchristos u16 write_cipher_suite; 538dbcf02cSchristos u16 read_cipher_suite; 548dbcf02cSchristos 558dbcf02cSchristos struct crypto_cipher *write_cbc; 568dbcf02cSchristos struct crypto_cipher *read_cbc; 578dbcf02cSchristos }; 588dbcf02cSchristos 598dbcf02cSchristos 608dbcf02cSchristos int tlsv1_record_set_cipher_suite(struct tlsv1_record_layer *rl, 618dbcf02cSchristos u16 cipher_suite); 628dbcf02cSchristos int tlsv1_record_change_write_cipher(struct tlsv1_record_layer *rl); 638dbcf02cSchristos int tlsv1_record_change_read_cipher(struct tlsv1_record_layer *rl); 648dbcf02cSchristos int tlsv1_record_send(struct tlsv1_record_layer *rl, u8 content_type, u8 *buf, 6542669be3Schristos size_t buf_size, const u8 *payload, size_t payload_len, 6642669be3Schristos size_t *out_len); 678dbcf02cSchristos int tlsv1_record_receive(struct tlsv1_record_layer *rl, 688dbcf02cSchristos const u8 *in_data, size_t in_len, 698dbcf02cSchristos u8 *out_data, size_t *out_len, u8 *alert); 708dbcf02cSchristos 718dbcf02cSchristos #endif /* TLSV1_RECORD_H */ 72