* tar xzf utvpn-src-unix-v101-7101-public-2010.06.27.tar.gz
[lab.git] / utvpn / utvpn-unix-v101-7101-public / src / Mayaqua / openssl / dtls1.h
1 /* ssl/dtls1.h */\r
2 /* \r
3  * DTLS implementation written by Nagendra Modadugu\r
4  * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.  \r
5  */\r
6 /* ====================================================================\r
7  * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.\r
8  *\r
9  * Redistribution and use in source and binary forms, with or without\r
10  * modification, are permitted provided that the following conditions\r
11  * are met:\r
12  *\r
13  * 1. Redistributions of source code must retain the above copyright\r
14  *    notice, this list of conditions and the following disclaimer. \r
15  *\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
19  *    distribution.\r
20  *\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
25  *\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
30  *\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
34  *\r
35  * 6. Redistributions of any form whatsoever must retain the following\r
36  *    acknowledgment:\r
37  *    "This product includes software developed by the OpenSSL Project\r
38  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
39  *\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
53  *\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
57  *\r
58  */\r
59 \r
60 #ifndef HEADER_DTLS1_H \r
61 #define HEADER_DTLS1_H \r
62 \r
63 #include <openssl/buffer.h>\r
64 #include <openssl/pqueue.h>\r
65 \r
66 #ifdef  __cplusplus\r
67 extern "C" {\r
68 #endif\r
69 \r
70 #define DTLS1_VERSION                   0x0100\r
71 #define DTLS1_VERSION_MAJOR             0x01\r
72 #define DTLS1_VERSION_MINOR             0x00\r
73 \r
74 #define DTLS1_AD_MISSING_HANDSHAKE_MESSAGE    110\r
75 \r
76 /* lengths of messages */\r
77 #define DTLS1_COOKIE_LENGTH                     32\r
78 \r
79 #define DTLS1_RT_HEADER_LENGTH                  13\r
80 \r
81 #define DTLS1_HM_HEADER_LENGTH                  12\r
82 \r
83 #define DTLS1_HM_BAD_FRAGMENT                   -2\r
84 #define DTLS1_HM_FRAGMENT_RETRY                 -3\r
85 \r
86 #define DTLS1_CCS_HEADER_LENGTH                  3\r
87 \r
88 #define DTLS1_AL_HEADER_LENGTH                   7\r
89 \r
90 \r
91 typedef struct dtls1_bitmap_st\r
92         {\r
93         PQ_64BIT map;\r
94         unsigned long length;     /* sizeof the bitmap in bits */\r
95         PQ_64BIT max_seq_num;  /* max record number seen so far */\r
96         } DTLS1_BITMAP;\r
97 \r
98 struct hm_header_st\r
99         {\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
106         };\r
107 \r
108 struct ccs_header_st\r
109         {\r
110         unsigned char type;\r
111         unsigned short seq;\r
112         };\r
113 \r
114 struct dtls1_timeout_st\r
115         {\r
116         /* Number of read timeouts so far */\r
117         unsigned int read_timeouts;\r
118         \r
119         /* Number of write timeouts so far */\r
120         unsigned int write_timeouts;\r
121         \r
122         /* Number of alerts received so far */\r
123         unsigned int num_alerts;\r
124         };\r
125 \r
126 typedef struct record_pqueue_st\r
127         {\r
128         unsigned short epoch;\r
129         pqueue q;\r
130         } record_pqueue;\r
131 \r
132 typedef struct hm_fragment_st\r
133         {\r
134         struct hm_header_st msg_header;\r
135         unsigned char *fragment;\r
136         } hm_fragment;\r
137 \r
138 typedef struct dtls1_state_st\r
139         {\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
144 \r
145         /* \r
146          * The current data and handshake epoch.  This is initially\r
147          * undefined, and starts at zero once the initial handshake is\r
148          * completed \r
149          */\r
150         unsigned short r_epoch;\r
151         unsigned short w_epoch;\r
152 \r
153         /* records being received in the current epoch */\r
154         DTLS1_BITMAP bitmap;\r
155 \r
156         /* renegotiation starts a new set of sequence numbers */\r
157         DTLS1_BITMAP next_bitmap;\r
158 \r
159         /* handshake message numbers */\r
160         unsigned short handshake_write_seq;\r
161         unsigned short next_handshake_write_seq;\r
162 \r
163         unsigned short handshake_read_seq;\r
164 \r
165         /* Received handshake records (processed and unprocessed) */\r
166         record_pqueue unprocessed_rcds;\r
167         record_pqueue processed_rcds;\r
168 \r
169         /* Buffered handshake messages */\r
170         pqueue buffered_messages;\r
171 \r
172         /* Buffered (sent) handshake records */\r
173         pqueue sent_messages;\r
174 \r
175         unsigned int mtu; /* max wire packet size */\r
176 \r
177         struct hm_header_st w_msg_hdr;\r
178         struct hm_header_st r_msg_hdr;\r
179 \r
180         struct dtls1_timeout_st timeout;\r
181         \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
188 \r
189         unsigned int retransmitting;\r
190 \r
191         } DTLS1_STATE;\r
192 \r
193 typedef struct dtls1_record_data_st\r
194         {\r
195         unsigned char *packet;\r
196         unsigned int   packet_length;\r
197         SSL3_BUFFER    rbuf;\r
198         SSL3_RECORD    rrec;\r
199         } DTLS1_RECORD_DATA;\r
200 \r
201 \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
205 \r
206 #define DTLS1_TMO_ALERT_COUNT                     12\r
207 \r
208 #ifdef  __cplusplus\r
209 }\r
210 #endif\r
211 #endif\r
212 \r