PR: 2028
[openssl.git] / ssl / dtls1.h
index b377cc5f6b2d29d8c92c57344229842904d48c53..926af1c4c5737c4241a156ef6cb1db6df301781e 100644 (file)
 
 #include <openssl/buffer.h>
 #include <openssl/pqueue.h>
+#ifdef OPENSSL_SYS_WIN32
+/* Needed for struct timeval */
+#include <winsock.h>
+#elif defined(OPENSSL_SYS_NETWARE) && !defined(_WINSOCK2API_)
+#include <sys/timeval.h>
+#else
+#include <sys/time.h>
+#endif
 
 #ifdef  __cplusplus
 extern "C" {
 #endif
 
-#define DTLS1_VERSION                  0x0100
-#define DTLS1_VERSION_MAJOR            0x01
-#define DTLS1_VERSION_MINOR            0x00
+#define DTLS1_VERSION                  0xFEFF
+#define DTLS1_BAD_VER                  0x0100
 
+#if 0
+/* this alert description is not specified anywhere... */
 #define DTLS1_AD_MISSING_HANDSHAKE_MESSAGE    110
+#endif
 
 /* lengths of messages */
-#define DTLS1_COOKIE_LENGTH                     32
+#define DTLS1_COOKIE_LENGTH                     256
 
 #define DTLS1_RT_HEADER_LENGTH                  13
 
@@ -83,18 +93,37 @@ extern "C" {
 #define DTLS1_HM_BAD_FRAGMENT                   -2
 #define DTLS1_HM_FRAGMENT_RETRY                 -3
 
-#define DTLS1_CCS_HEADER_LENGTH                  3
+#define DTLS1_CCS_HEADER_LENGTH                  1
 
+#ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE
 #define DTLS1_AL_HEADER_LENGTH                   7
+#else
+#define DTLS1_AL_HEADER_LENGTH                   2
+#endif
 
 
 typedef struct dtls1_bitmap_st
        {
-       PQ_64BIT map;
-       unsigned long length;     /* sizeof the bitmap in bits */
-       PQ_64BIT max_seq_num;  /* max record number seen so far */
+       unsigned long map;              /* track 32 packets on 32-bit systems
+                                          and 64 - on 64-bit systems */
+       unsigned char max_seq_num[8];   /* max record number seen so far,
+                                          64-bit value in big-endian
+                                          encoding */
        } DTLS1_BITMAP;
 
+struct dtls1_retransmit_state
+       {
+       EVP_CIPHER_CTX *enc_write_ctx;  /* cryptographic state */
+       EVP_MD_CTX *write_hash;                 /* used for mac generation */
+#ifndef OPENSSL_NO_COMP
+       COMP_CTX *compress;                             /* compression */
+#else
+       char *compress; 
+#endif
+       SSL_SESSION *session;
+       unsigned short epoch;
+       };
+
 struct hm_header_st
        {
        unsigned char type;
@@ -103,6 +132,7 @@ struct hm_header_st
        unsigned long frag_off;
        unsigned long frag_len;
        unsigned int is_ccs;
+       struct dtls1_retransmit_state saved_retransmit_state;
        };
 
 struct ccs_header_st
@@ -162,6 +192,9 @@ typedef struct dtls1_state_st
 
        unsigned short handshake_read_seq;
 
+       /* save last sequence number for retransmissions */
+       unsigned char last_write_sequence[8];
+
        /* Received handshake records (processed and unprocessed) */
        record_pqueue unprocessed_rcds;
        record_pqueue processed_rcds;
@@ -172,13 +205,26 @@ typedef struct dtls1_state_st
        /* Buffered (sent) handshake records */
        pqueue sent_messages;
 
-       unsigned int mtu; /* max wire packet size */
+       /* Buffered application records.
+        * Only for records between CCS and Finished
+        * to prevent either protocol violation or
+        * unnecessary message loss.
+        */
+       record_pqueue buffered_app_data;
+
+       unsigned int mtu; /* max DTLS packet size */
 
        struct hm_header_st w_msg_hdr;
        struct hm_header_st r_msg_hdr;
 
        struct dtls1_timeout_st timeout;
-       
+
+       /* Indicates when the last handshake msg sent will timeout */
+       struct timeval next_timeout;
+
+       /* Timeout duration */
+       unsigned short timeout_duration;
+
        /* storage for Alert/Handshake protocol data received but not
         * yet processed by ssl3_read_bytes: */
        unsigned char alert_fragment[DTLS1_AL_HEADER_LENGTH];
@@ -187,6 +233,7 @@ typedef struct dtls1_state_st
        unsigned int handshake_fragment_len;
 
        unsigned int retransmitting;
+       unsigned int change_cipher_spec_ok;
 
        } DTLS1_STATE;