dtls1.h

Go to the documentation of this file.
00001 /* ssl/dtls1.h */
00002 /*
00003  * DTLS implementation written by Nagendra Modadugu
00004  * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
00005  */
00006 /* ====================================================================
00007  * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  *
00016  * 2. Redistributions in binary form must reproduce the above copyright
00017  *    notice, this list of conditions and the following disclaimer in
00018  *    the documentation and/or other materials provided with the
00019  *    distribution.
00020  *
00021  * 3. All advertising materials mentioning features or use of this
00022  *    software must display the following acknowledgment:
00023  *    "This product includes software developed by the OpenSSL Project
00024  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
00025  *
00026  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
00027  *    endorse or promote products derived from this software without
00028  *    prior written permission. For written permission, please contact
00029  *    openssl-core@OpenSSL.org.
00030  *
00031  * 5. Products derived from this software may not be called "OpenSSL"
00032  *    nor may "OpenSSL" appear in their names without prior written
00033  *    permission of the OpenSSL Project.
00034  *
00035  * 6. Redistributions of any form whatsoever must retain the following
00036  *    acknowledgment:
00037  *    "This product includes software developed by the OpenSSL Project
00038  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
00039  *
00040  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
00041  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00042  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00043  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
00044  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00045  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00046  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00047  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00048  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00049  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00050  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00051  * OF THE POSSIBILITY OF SUCH DAMAGE.
00052  * ====================================================================
00053  *
00054  * This product includes cryptographic software written by Eric Young
00055  * (eay@cryptsoft.com).  This product includes software written by Tim
00056  * Hudson (tjh@cryptsoft.com).
00057  *
00058  */
00059 
00060 #ifndef HEADER_DTLS1_H
00061 #define HEADER_DTLS1_H
00062 
00063 #include <openssl/buffer.h>
00064 #include <openssl/pqueue.h>
00065 
00066 #ifdef  __cplusplus
00067 extern "C" {
00068 #endif
00069 
00070 #define DTLS1_VERSION         0x0100
00071 #define DTLS1_VERSION_MAJOR      0x01
00072 #define DTLS1_VERSION_MINOR      0x00
00073 
00074 #define DTLS1_AD_MISSING_HANDSHAKE_MESSAGE    110
00075 
00076 /* lengths of messages */
00077 #define DTLS1_COOKIE_LENGTH                     32
00078 
00079 #define DTLS1_RT_HEADER_LENGTH                  13
00080 
00081 #define DTLS1_HM_HEADER_LENGTH                  12
00082 
00083 #define DTLS1_HM_BAD_FRAGMENT                   -2
00084 #define DTLS1_HM_FRAGMENT_RETRY                 -3
00085 
00086 #define DTLS1_CCS_HEADER_LENGTH                  3
00087 
00088 #define DTLS1_AL_HEADER_LENGTH                   7
00089 
00090 
00091 typedef struct dtls1_bitmap_st
00092    {
00093    PQ_64BIT map;
00094    unsigned long length;     /* sizeof the bitmap in bits */
00095    PQ_64BIT max_seq_num;  /* max record number seen so far */
00096    } DTLS1_BITMAP;
00097 
00098 struct hm_header_st
00099    {
00100    unsigned char type;
00101    unsigned long msg_len;
00102    unsigned short seq;
00103    unsigned long frag_off;
00104    unsigned long frag_len;
00105    unsigned int is_ccs;
00106    };
00107 
00108 struct ccs_header_st
00109    {
00110    unsigned char type;
00111    unsigned short seq;
00112    };
00113 
00114 struct dtls1_timeout_st
00115    {
00116    /* Number of read timeouts so far */
00117    unsigned int read_timeouts;
00118 
00119    /* Number of write timeouts so far */
00120    unsigned int write_timeouts;
00121 
00122    /* Number of alerts received so far */
00123    unsigned int num_alerts;
00124    };
00125 
00126 typedef struct record_pqueue_st
00127    {
00128    unsigned short epoch;
00129    pqueue q;
00130    } record_pqueue;
00131 
00132 typedef struct hm_fragment_st
00133    {
00134    struct hm_header_st msg_header;
00135    unsigned char *fragment;
00136    } hm_fragment;
00137 
00138 typedef struct dtls1_state_st
00139    {
00140    unsigned int send_cookie;
00141    unsigned char cookie[DTLS1_COOKIE_LENGTH];
00142    unsigned char rcvd_cookie[DTLS1_COOKIE_LENGTH];
00143    unsigned int cookie_len;
00144 
00145    /*
00146     * The current data and handshake epoch.  This is initially
00147     * undefined, and starts at zero once the initial handshake is
00148     * completed
00149     */
00150    unsigned short r_epoch;
00151    unsigned short w_epoch;
00152 
00153    /* records being received in the current epoch */
00154    DTLS1_BITMAP bitmap;
00155 
00156    /* renegotiation starts a new set of sequence numbers */
00157    DTLS1_BITMAP next_bitmap;
00158 
00159    /* handshake message numbers */
00160    unsigned short handshake_write_seq;
00161    unsigned short next_handshake_write_seq;
00162 
00163    unsigned short handshake_read_seq;
00164 
00165    /* Received handshake records (processed and unprocessed) */
00166    record_pqueue unprocessed_rcds;
00167    record_pqueue processed_rcds;
00168 
00169    /* Buffered handshake messages */
00170    pqueue buffered_messages;
00171 
00172    /* Buffered (sent) handshake records */
00173    pqueue sent_messages;
00174 
00175    unsigned int mtu; /* max wire packet size */
00176 
00177    struct hm_header_st w_msg_hdr;
00178    struct hm_header_st r_msg_hdr;
00179 
00180    struct dtls1_timeout_st timeout;
00181 
00182    /* storage for Alert/Handshake protocol data received but not
00183     * yet processed by ssl3_read_bytes: */
00184    unsigned char alert_fragment[DTLS1_AL_HEADER_LENGTH];
00185    unsigned int alert_fragment_len;
00186    unsigned char handshake_fragment[DTLS1_HM_HEADER_LENGTH];
00187    unsigned int handshake_fragment_len;
00188 
00189    unsigned int retransmitting;
00190 
00191    } DTLS1_STATE;
00192 
00193 typedef struct dtls1_record_data_st
00194    {
00195    unsigned char *packet;
00196    unsigned int   packet_length;
00197    SSL3_BUFFER    rbuf;
00198    SSL3_RECORD    rrec;
00199    } DTLS1_RECORD_DATA;
00200 
00201 
00202 /* Timeout multipliers (timeout slice is defined in apps/timeouts.h */
00203 #define DTLS1_TMO_READ_COUNT                      2
00204 #define DTLS1_TMO_WRITE_COUNT                     2
00205 
00206 #define DTLS1_TMO_ALERT_COUNT                     12
00207 
00208 #ifdef  __cplusplus
00209 }
00210 #endif
00211 #endif
00212 

Generated on Thu Aug 20 22:33:05 2009 for OpenXDAS by  doxygen 1.5.6