3 * DTLS implementation written by Nagendra Modadugu
\r
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
\r
6 /* ====================================================================
\r
7 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
\r
9 * Redistribution and use in source and binary forms, with or without
\r
10 * modification, are permitted provided that the following conditions
\r
13 * 1. Redistributions of source code must retain the above copyright
\r
14 * notice, this list of conditions and the following disclaimer.
\r
16 * 2. Redistributions in binary form must reproduce the above copyright
\r
17 * notice, this list of conditions and the following disclaimer in
\r
18 * the documentation and/or other materials provided with the
\r
21 * 3. All advertising materials mentioning features or use of this
\r
22 * software must display the following acknowledgment:
\r
23 * "This product includes software developed by the OpenSSL Project
\r
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
\r
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
\r
27 * endorse or promote products derived from this software without
\r
28 * prior written permission. For written permission, please contact
\r
29 * openssl-core@OpenSSL.org.
\r
31 * 5. Products derived from this software may not be called "OpenSSL"
\r
32 * nor may "OpenSSL" appear in their names without prior written
\r
33 * permission of the OpenSSL Project.
\r
35 * 6. Redistributions of any form whatsoever must retain the following
\r
37 * "This product includes software developed by the OpenSSL Project
\r
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
\r
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
\r
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
\r
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
\r
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
\r
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
\r
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
\r
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
\r
52 * ====================================================================
\r
54 * This product includes cryptographic software written by Eric Young
\r
55 * (eay@cryptsoft.com). This product includes software written by Tim
\r
56 * Hudson (tjh@cryptsoft.com).
\r
60 #ifndef HEADER_DTLS1_H
\r
61 #define HEADER_DTLS1_H
\r
63 #include <openssl/buffer.h>
\r
64 #include <openssl/pqueue.h>
\r
70 #define DTLS1_VERSION 0x0100
\r
71 #define DTLS1_VERSION_MAJOR 0x01
\r
72 #define DTLS1_VERSION_MINOR 0x00
\r
74 #define DTLS1_AD_MISSING_HANDSHAKE_MESSAGE 110
\r
76 /* lengths of messages */
\r
77 #define DTLS1_COOKIE_LENGTH 32
\r
79 #define DTLS1_RT_HEADER_LENGTH 13
\r
81 #define DTLS1_HM_HEADER_LENGTH 12
\r
83 #define DTLS1_HM_BAD_FRAGMENT -2
\r
84 #define DTLS1_HM_FRAGMENT_RETRY -3
\r
86 #define DTLS1_CCS_HEADER_LENGTH 3
\r
88 #define DTLS1_AL_HEADER_LENGTH 7
\r
91 typedef struct dtls1_bitmap_st
\r
94 unsigned long length; /* sizeof the bitmap in bits */
\r
95 PQ_64BIT max_seq_num; /* max record number seen so far */
\r
100 unsigned char type;
\r
101 unsigned long msg_len;
\r
102 unsigned short seq;
\r
103 unsigned long frag_off;
\r
104 unsigned long frag_len;
\r
105 unsigned int is_ccs;
\r
108 struct ccs_header_st
\r
110 unsigned char type;
\r
111 unsigned short seq;
\r
114 struct dtls1_timeout_st
\r
116 /* Number of read timeouts so far */
\r
117 unsigned int read_timeouts;
\r
119 /* Number of write timeouts so far */
\r
120 unsigned int write_timeouts;
\r
122 /* Number of alerts received so far */
\r
123 unsigned int num_alerts;
\r
126 typedef struct record_pqueue_st
\r
128 unsigned short epoch;
\r
132 typedef struct hm_fragment_st
\r
134 struct hm_header_st msg_header;
\r
135 unsigned char *fragment;
\r
138 typedef struct dtls1_state_st
\r
140 unsigned int send_cookie;
\r
141 unsigned char cookie[DTLS1_COOKIE_LENGTH];
\r
142 unsigned char rcvd_cookie[DTLS1_COOKIE_LENGTH];
\r
143 unsigned int cookie_len;
\r
146 * The current data and handshake epoch. This is initially
\r
147 * undefined, and starts at zero once the initial handshake is
\r
150 unsigned short r_epoch;
\r
151 unsigned short w_epoch;
\r
153 /* records being received in the current epoch */
\r
154 DTLS1_BITMAP bitmap;
\r
156 /* renegotiation starts a new set of sequence numbers */
\r
157 DTLS1_BITMAP next_bitmap;
\r
159 /* handshake message numbers */
\r
160 unsigned short handshake_write_seq;
\r
161 unsigned short next_handshake_write_seq;
\r
163 unsigned short handshake_read_seq;
\r
165 /* Received handshake records (processed and unprocessed) */
\r
166 record_pqueue unprocessed_rcds;
\r
167 record_pqueue processed_rcds;
\r
169 /* Buffered handshake messages */
\r
170 pqueue buffered_messages;
\r
172 /* Buffered (sent) handshake records */
\r
173 pqueue sent_messages;
\r
175 unsigned int mtu; /* max wire packet size */
\r
177 struct hm_header_st w_msg_hdr;
\r
178 struct hm_header_st r_msg_hdr;
\r
180 struct dtls1_timeout_st timeout;
\r
182 /* storage for Alert/Handshake protocol data received but not
\r
183 * yet processed by ssl3_read_bytes: */
\r
184 unsigned char alert_fragment[DTLS1_AL_HEADER_LENGTH];
\r
185 unsigned int alert_fragment_len;
\r
186 unsigned char handshake_fragment[DTLS1_HM_HEADER_LENGTH];
\r
187 unsigned int handshake_fragment_len;
\r
189 unsigned int retransmitting;
\r
193 typedef struct dtls1_record_data_st
\r
195 unsigned char *packet;
\r
196 unsigned int packet_length;
\r
199 } DTLS1_RECORD_DATA;
\r
202 /* Timeout multipliers (timeout slice is defined in apps/timeouts.h */
\r
203 #define DTLS1_TMO_READ_COUNT 2
\r
204 #define DTLS1_TMO_WRITE_COUNT 2
\r
206 #define DTLS1_TMO_ALERT_COUNT 12
\r