sl@0: /* ssl/dtls1.h */ sl@0: /* sl@0: * DTLS implementation written by Nagendra Modadugu sl@0: * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. sl@0: */ sl@0: /* ==================================================================== sl@0: * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * sl@0: * 1. Redistributions of source code must retain the above copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in sl@0: * the documentation and/or other materials provided with the sl@0: * distribution. sl@0: * sl@0: * 3. All advertising materials mentioning features or use of this sl@0: * software must display the following acknowledgment: sl@0: * "This product includes software developed by the OpenSSL Project sl@0: * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" sl@0: * sl@0: * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to sl@0: * endorse or promote products derived from this software without sl@0: * prior written permission. For written permission, please contact sl@0: * openssl-core@OpenSSL.org. sl@0: * sl@0: * 5. Products derived from this software may not be called "OpenSSL" sl@0: * nor may "OpenSSL" appear in their names without prior written sl@0: * permission of the OpenSSL Project. sl@0: * sl@0: * 6. Redistributions of any form whatsoever must retain the following sl@0: * acknowledgment: sl@0: * "This product includes software developed by the OpenSSL Project sl@0: * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY sl@0: * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE sl@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR sl@0: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR sl@0: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, sl@0: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT sl@0: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; sl@0: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, sl@0: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) sl@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED sl@0: * OF THE POSSIBILITY OF SUCH DAMAGE. sl@0: * ==================================================================== sl@0: * sl@0: * This product includes cryptographic software written by Eric Young sl@0: * (eay@cryptsoft.com). This product includes software written by Tim sl@0: * Hudson (tjh@cryptsoft.com). sl@0: * sl@0: */ sl@0: sl@0: #ifndef HEADER_DTLS1_H sl@0: #define HEADER_DTLS1_H sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #ifdef __cplusplus sl@0: extern "C" { sl@0: #endif sl@0: sl@0: #define DTLS1_VERSION 0xFEFF sl@0: #define DTLS1_BAD_VER 0x0100 sl@0: sl@0: #define DTLS1_AD_MISSING_HANDSHAKE_MESSAGE 110 sl@0: sl@0: /* lengths of messages */ sl@0: #define DTLS1_COOKIE_LENGTH 32 sl@0: sl@0: #define DTLS1_RT_HEADER_LENGTH 13 sl@0: sl@0: #define DTLS1_HM_HEADER_LENGTH 12 sl@0: sl@0: #define DTLS1_HM_BAD_FRAGMENT -2 sl@0: #define DTLS1_HM_FRAGMENT_RETRY -3 sl@0: sl@0: #define DTLS1_CCS_HEADER_LENGTH 1 sl@0: sl@0: #define DTLS1_AL_HEADER_LENGTH 7 sl@0: sl@0: sl@0: typedef struct dtls1_bitmap_st sl@0: { sl@0: PQ_64BIT map; sl@0: unsigned long length; /* sizeof the bitmap in bits */ sl@0: PQ_64BIT max_seq_num; /* max record number seen so far */ sl@0: } DTLS1_BITMAP; sl@0: sl@0: struct hm_header_st sl@0: { sl@0: unsigned char type; sl@0: unsigned long msg_len; sl@0: unsigned short seq; sl@0: unsigned long frag_off; sl@0: unsigned long frag_len; sl@0: unsigned int is_ccs; sl@0: }; sl@0: sl@0: struct ccs_header_st sl@0: { sl@0: unsigned char type; sl@0: unsigned short seq; sl@0: }; sl@0: sl@0: struct dtls1_timeout_st sl@0: { sl@0: /* Number of read timeouts so far */ sl@0: unsigned int read_timeouts; sl@0: sl@0: /* Number of write timeouts so far */ sl@0: unsigned int write_timeouts; sl@0: sl@0: /* Number of alerts received so far */ sl@0: unsigned int num_alerts; sl@0: }; sl@0: sl@0: typedef struct record_pqueue_st sl@0: { sl@0: unsigned short epoch; sl@0: pqueue q; sl@0: } record_pqueue; sl@0: sl@0: typedef struct hm_fragment_st sl@0: { sl@0: struct hm_header_st msg_header; sl@0: unsigned char *fragment; sl@0: } hm_fragment; sl@0: sl@0: typedef struct dtls1_state_st sl@0: { sl@0: unsigned int send_cookie; sl@0: unsigned char cookie[DTLS1_COOKIE_LENGTH]; sl@0: unsigned char rcvd_cookie[DTLS1_COOKIE_LENGTH]; sl@0: unsigned int cookie_len; sl@0: sl@0: /* sl@0: * The current data and handshake epoch. This is initially sl@0: * undefined, and starts at zero once the initial handshake is sl@0: * completed sl@0: */ sl@0: unsigned short r_epoch; sl@0: unsigned short w_epoch; sl@0: sl@0: /* records being received in the current epoch */ sl@0: DTLS1_BITMAP bitmap; sl@0: sl@0: /* renegotiation starts a new set of sequence numbers */ sl@0: DTLS1_BITMAP next_bitmap; sl@0: sl@0: /* handshake message numbers */ sl@0: unsigned short handshake_write_seq; sl@0: unsigned short next_handshake_write_seq; sl@0: sl@0: unsigned short handshake_read_seq; sl@0: sl@0: /* Received handshake records (processed and unprocessed) */ sl@0: record_pqueue unprocessed_rcds; sl@0: record_pqueue processed_rcds; sl@0: sl@0: /* Buffered handshake messages */ sl@0: pqueue buffered_messages; sl@0: sl@0: /* Buffered (sent) handshake records */ sl@0: pqueue sent_messages; sl@0: sl@0: unsigned int mtu; /* max wire packet size */ sl@0: sl@0: struct hm_header_st w_msg_hdr; sl@0: struct hm_header_st r_msg_hdr; sl@0: sl@0: struct dtls1_timeout_st timeout; sl@0: sl@0: /* storage for Alert/Handshake protocol data received but not sl@0: * yet processed by ssl3_read_bytes: */ sl@0: unsigned char alert_fragment[DTLS1_AL_HEADER_LENGTH]; sl@0: unsigned int alert_fragment_len; sl@0: unsigned char handshake_fragment[DTLS1_HM_HEADER_LENGTH]; sl@0: unsigned int handshake_fragment_len; sl@0: sl@0: unsigned int retransmitting; sl@0: sl@0: } DTLS1_STATE; sl@0: sl@0: typedef struct dtls1_record_data_st sl@0: { sl@0: unsigned char *packet; sl@0: unsigned int packet_length; sl@0: SSL3_BUFFER rbuf; sl@0: SSL3_RECORD rrec; sl@0: } DTLS1_RECORD_DATA; sl@0: sl@0: sl@0: /* Timeout multipliers (timeout slice is defined in apps/timeouts.h */ sl@0: #define DTLS1_TMO_READ_COUNT 2 sl@0: #define DTLS1_TMO_WRITE_COUNT 2 sl@0: sl@0: #define DTLS1_TMO_ALERT_COUNT 12 sl@0: sl@0: #ifdef __cplusplus sl@0: } sl@0: #endif sl@0: #endif sl@0: