OSDN Git Service

20b33483087cd399fc245757627367c6f3020e23
[ffftp/ffftp.git] / contrib / openssl / include / 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 # ifdef OPENSSL_SYS_VMS\r
66 #  include <resource.h>\r
67 #  include <sys/timeb.h>\r
68 # endif\r
69 # ifdef OPENSSL_SYS_WIN32\r
70 /* Needed for struct timeval */\r
71 #  include <winsock.h>\r
72 # elif defined(OPENSSL_SYS_NETWARE) && !defined(_WINSOCK2API_)\r
73 #  include <sys/timeval.h>\r
74 # else\r
75 #  if defined(OPENSSL_SYS_VXWORKS)\r
76 #   include <sys/times.h>\r
77 #  else\r
78 #   include <sys/time.h>\r
79 #  endif\r
80 # endif\r
81 \r
82 #ifdef  __cplusplus\r
83 extern "C" {\r
84 #endif\r
85 \r
86 # define DTLS1_VERSION                   0xFEFF\r
87 # define DTLS1_2_VERSION                 0xFEFD\r
88 # define DTLS_MAX_VERSION                DTLS1_2_VERSION\r
89 # define DTLS1_VERSION_MAJOR             0xFE\r
90 \r
91 # define DTLS1_BAD_VER                   0x0100\r
92 \r
93 /* Special value for method supporting multiple versions */\r
94 # define DTLS_ANY_VERSION                0x1FFFF\r
95 \r
96 # if 0\r
97 /* this alert description is not specified anywhere... */\r
98 #  define DTLS1_AD_MISSING_HANDSHAKE_MESSAGE    110\r
99 # endif\r
100 \r
101 /* lengths of messages */\r
102 # define DTLS1_COOKIE_LENGTH                     256\r
103 \r
104 # define DTLS1_RT_HEADER_LENGTH                  13\r
105 \r
106 # define DTLS1_HM_HEADER_LENGTH                  12\r
107 \r
108 # define DTLS1_HM_BAD_FRAGMENT                   -2\r
109 # define DTLS1_HM_FRAGMENT_RETRY                 -3\r
110 \r
111 # define DTLS1_CCS_HEADER_LENGTH                  1\r
112 \r
113 # ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE\r
114 #  define DTLS1_AL_HEADER_LENGTH                   7\r
115 # else\r
116 #  define DTLS1_AL_HEADER_LENGTH                   2\r
117 # endif\r
118 \r
119 # ifndef OPENSSL_NO_SSL_INTERN\r
120 \r
121 #  ifndef OPENSSL_NO_SCTP\r
122 #   define DTLS1_SCTP_AUTH_LABEL   "EXPORTER_DTLS_OVER_SCTP"\r
123 #  endif\r
124 \r
125 /* Max MTU overhead we know about so far is 40 for IPv6 + 8 for UDP */\r
126 #  define DTLS1_MAX_MTU_OVERHEAD                   48\r
127 \r
128 typedef struct dtls1_bitmap_st {\r
129     unsigned long map;          /* track 32 packets on 32-bit systems and 64\r
130                                  * - on 64-bit systems */\r
131     unsigned char max_seq_num[8]; /* max record number seen so far, 64-bit\r
132                                    * value in big-endian encoding */\r
133 } DTLS1_BITMAP;\r
134 \r
135 struct dtls1_retransmit_state {\r
136     EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */\r
137     EVP_MD_CTX *write_hash;     /* used for mac generation */\r
138 #  ifndef OPENSSL_NO_COMP\r
139     COMP_CTX *compress;         /* compression */\r
140 #  else\r
141     char *compress;\r
142 #  endif\r
143     SSL_SESSION *session;\r
144     unsigned short epoch;\r
145 };\r
146 \r
147 struct hm_header_st {\r
148     unsigned char type;\r
149     unsigned long msg_len;\r
150     unsigned short seq;\r
151     unsigned long frag_off;\r
152     unsigned long frag_len;\r
153     unsigned int is_ccs;\r
154     struct dtls1_retransmit_state saved_retransmit_state;\r
155 };\r
156 \r
157 struct ccs_header_st {\r
158     unsigned char type;\r
159     unsigned short seq;\r
160 };\r
161 \r
162 struct dtls1_timeout_st {\r
163     /* Number of read timeouts so far */\r
164     unsigned int read_timeouts;\r
165     /* Number of write timeouts so far */\r
166     unsigned int write_timeouts;\r
167     /* Number of alerts received so far */\r
168     unsigned int num_alerts;\r
169 };\r
170 \r
171 typedef struct record_pqueue_st {\r
172     unsigned short epoch;\r
173     pqueue q;\r
174 } record_pqueue;\r
175 \r
176 typedef struct hm_fragment_st {\r
177     struct hm_header_st msg_header;\r
178     unsigned char *fragment;\r
179     unsigned char *reassembly;\r
180 } hm_fragment;\r
181 \r
182 typedef struct dtls1_state_st {\r
183     unsigned int send_cookie;\r
184     unsigned char cookie[DTLS1_COOKIE_LENGTH];\r
185     unsigned char rcvd_cookie[DTLS1_COOKIE_LENGTH];\r
186     unsigned int cookie_len;\r
187     /*\r
188      * The current data and handshake epoch.  This is initially\r
189      * undefined, and starts at zero once the initial handshake is\r
190      * completed\r
191      */\r
192     unsigned short r_epoch;\r
193     unsigned short w_epoch;\r
194     /* records being received in the current epoch */\r
195     DTLS1_BITMAP bitmap;\r
196     /* renegotiation starts a new set of sequence numbers */\r
197     DTLS1_BITMAP next_bitmap;\r
198     /* handshake message numbers */\r
199     unsigned short handshake_write_seq;\r
200     unsigned short next_handshake_write_seq;\r
201     unsigned short handshake_read_seq;\r
202     /* save last sequence number for retransmissions */\r
203     unsigned char last_write_sequence[8];\r
204     /* Received handshake records (processed and unprocessed) */\r
205     record_pqueue unprocessed_rcds;\r
206     record_pqueue processed_rcds;\r
207     /* Buffered handshake messages */\r
208     pqueue buffered_messages;\r
209     /* Buffered (sent) handshake records */\r
210     pqueue sent_messages;\r
211     /*\r
212      * Buffered application records. Only for records between CCS and\r
213      * Finished to prevent either protocol violation or unnecessary message\r
214      * loss.\r
215      */\r
216     record_pqueue buffered_app_data;\r
217     /* Is set when listening for new connections with dtls1_listen() */\r
218     unsigned int listen;\r
219     unsigned int link_mtu;      /* max on-the-wire DTLS packet size */\r
220     unsigned int mtu;           /* max DTLS packet size */\r
221     struct hm_header_st w_msg_hdr;\r
222     struct hm_header_st r_msg_hdr;\r
223     struct dtls1_timeout_st timeout;\r
224     /*\r
225      * Indicates when the last handshake msg or heartbeat sent will timeout\r
226      */\r
227     struct timeval next_timeout;\r
228     /* Timeout duration */\r
229     unsigned short timeout_duration;\r
230     /*\r
231      * storage for Alert/Handshake protocol data received but not yet\r
232      * processed by ssl3_read_bytes:\r
233      */\r
234     unsigned char alert_fragment[DTLS1_AL_HEADER_LENGTH];\r
235     unsigned int alert_fragment_len;\r
236     unsigned char handshake_fragment[DTLS1_HM_HEADER_LENGTH];\r
237     unsigned int handshake_fragment_len;\r
238     unsigned int retransmitting;\r
239     /*\r
240      * Set when the handshake is ready to process peer's ChangeCipherSpec message.\r
241      * Cleared after the message has been processed.\r
242      */\r
243     unsigned int change_cipher_spec_ok;\r
244 #  ifndef OPENSSL_NO_SCTP\r
245     /* used when SSL_ST_XX_FLUSH is entered */\r
246     int next_state;\r
247     int shutdown_received;\r
248 #  endif\r
249 } DTLS1_STATE;\r
250 \r
251 typedef struct dtls1_record_data_st {\r
252     unsigned char *packet;\r
253     unsigned int packet_length;\r
254     SSL3_BUFFER rbuf;\r
255     SSL3_RECORD rrec;\r
256 #  ifndef OPENSSL_NO_SCTP\r
257     struct bio_dgram_sctp_rcvinfo recordinfo;\r
258 #  endif\r
259 } DTLS1_RECORD_DATA;\r
260 \r
261 # endif\r
262 \r
263 /* Timeout multipliers (timeout slice is defined in apps/timeouts.h */\r
264 # define DTLS1_TMO_READ_COUNT                      2\r
265 # define DTLS1_TMO_WRITE_COUNT                     2\r
266 \r
267 # define DTLS1_TMO_ALERT_COUNT                     12\r
268 \r
269 #ifdef  __cplusplus\r
270 }\r
271 #endif\r
272 #endif\r