126 static int satsub64be(
const unsigned char *v1,
const unsigned char *v2)
129 if (
sizeof(
long) == 8)
do
130 {
const union {
long one;
char little; } is_endian = {1};
133 if (is_endian.little)
break;
137 if (((
size_t)v1|(
size_t)v2)&0x7)
break;
141 if (l>128)
return 128;
142 else if (l<-128)
return -128;
146 ret = (int)v1[7]-(
int)v2[7];
151 { brw += (int)v1[i]-(
int)v2[i];
158 { brw += (int)v1[i]-(
int)v2[i];
165 if (sat&0xff)
return brw | 0x80;
166 else return brw + (ret&0xFF);
169 static int have_handshake_fragment(
SSL *s,
int type,
unsigned char *buf,
174 unsigned int *is_next_epoch);
177 unsigned short *priority,
unsigned long *offset);
180 unsigned char *priority);
181 static int dtls1_process_record(
SSL *s);
185 dtls1_copy_record(
SSL *s,
pitem *item)
218 if (rdata == NULL || item == NULL)
234 #ifndef OPENSSL_NO_SCTP
275 dtls1_copy_record(s, item);
289 #define dtls1_get_unprocessed_record(s) \
290 dtls1_retrieve_buffered_record((s), \
291 &((s)->d1->unprocessed_rcds))
294 #define dtls1_get_processed_record(s) \
295 dtls1_retrieve_buffered_record((s), \
296 &((s)->d1->processed_rcds))
299 dtls1_process_buffered_records(
SSL *s)
314 if ( ! dtls1_process_record(s))
333 dtls1_get_buffered_record(
SSL *s)
346 if (item && item->
priority == priority)
376 dtls1_process_record(
SSL *s)
383 unsigned int mac_size;
385 int decryption_failed_or_bad_record_mac = 0;
386 unsigned char *mac = NULL;
424 decryption_failed_or_bad_record_mac = 1;
428 printf(
"dec %d\n",rr->
length);
429 {
unsigned int z;
for (z=0; z<rr->
length; z++) printf(
"%02X%c",rr->
data[z],((z+1)%16)?
' ':
'\n'); }
434 if ( (sess == NULL) ||
454 decryption_failed_or_bad_record_mac = 1;
458 if (rr->
length >= mac_size)
466 if (i < 0 || mac == NULL || memcmp(md, mac, mac_size) != 0)
468 decryption_failed_or_bad_record_mac = 1;
472 if (decryption_failed_or_bad_record_mac)
515 dtls1_record_bitmap_update(s, &(s->
d1->
bitmap));
536 int ssl_major,ssl_minor;
539 unsigned char *
p = NULL;
540 unsigned short version;
542 unsigned int is_next_epoch;
548 dtls1_process_buffered_records(s);
562 if (n <= 0)
return(n);
579 version=(ssl_major<<8)|ssl_minor;
601 if ((version & 0xff00) != (s->
version & 0xff00))
627 if (n <= 0)
return(n);
643 bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch);
651 #ifndef OPENSSL_NO_SCTP
664 !dtls1_record_replay_check(s, bitmap))
670 #ifndef OPENSSL_NO_SCTP
675 if (rr->
length == 0)
goto again;
693 if (!dtls1_process_record(s))
736 void (*
cb)(
const SSL *ssl,
int type2,
int val)=NULL;
752 if ( (ret = have_handshake_fragment(s, type, buf, len, peek)))
757 #ifndef OPENSSL_NO_SCTP
771 if (i < 0)
return(i);
798 #ifndef OPENSSL_NO_SCTP
807 dtls1_copy_record(s, item);
859 if (type == rr->
type)
871 if (len <= 0)
return(len);
873 if ((
unsigned int)len > rr->
length)
876 n = (
unsigned int)len;
878 memcpy(buf,&(rr->
data[rr->
off]),n);
890 #ifndef OPENSSL_NO_SCTP
925 unsigned int k, dest_maxlen = 0;
926 unsigned char *dest = NULL;
927 unsigned int *dest_len = NULL;
941 #ifndef OPENSSL_NO_HEARTBEATS
981 if ( rr->
length < dest_maxlen)
983 #ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE
997 for ( k = 0; k < dest_maxlen; k++)
1002 *dest_len = dest_maxlen;
1042 if (i < 0)
return(i);
1090 j = (alert_level << 8) | alert_descr;
1094 if (alert_level == 1)
1099 #ifndef OPENSSL_NO_SCTP
1120 if (alert_descr == DTLS1_AD_MISSING_HANDSHAKE_MESSAGE)
1123 unsigned int frag_off;
1138 DTLS1_AD_MISSING_HANDSHAKE_MESSAGE);
1143 else if (alert_level == 2)
1186 if ( (rr->
length != ccs_hdr_len) ||
1220 #ifndef OPENSSL_NO_SCTP
1275 if (i < 0)
return(i);
1304 #ifndef OPENSSL_NO_TLS
1368 #ifndef OPENSSL_NO_SCTP
1380 if (i < 0)
return(i);
1402 have_handshake_fragment(
SSL *s,
int type,
unsigned char *buf,
1410 unsigned char *dst = buf;
1446 int do_dtls1_write(
SSL *s,
int type,
const unsigned char *buf,
unsigned int len,
int create_empty_fragment)
1448 unsigned char *
p,*pseq;
1449 int i,mac_size,clear=0;
1473 if (len == 0 && !create_empty_fragment)
1480 if ( (sess == NULL) ||
1510 prefix_len = s->
method->do_ssl_write(s, type, buf, 0, 1);
1511 if (prefix_len <= 0)
1525 p = wb->
buf + prefix_len;
1552 wr->
input=(
unsigned char *)buf;
1630 if (create_empty_fragment)
1669 if (shift >=
sizeof(bitmap->
map)*8)
1671 else if (bitmap->
map & (1UL<<shift))
1689 if (shift <
sizeof(bitmap->
map)*8)
1690 bitmap->
map <<= shift, bitmap->
map |= 1UL;
1697 if (shift <
sizeof(bitmap->
map)*8)
1698 bitmap->
map |= 1UL<<shift;
1708 unsigned char *
ptr = &buf[0];
1712 memset(buf, 0x00,
sizeof(buf));
1716 #ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE
1717 if (s->
s3->
send_alert[1] == DTLS1_AD_MISSING_HANDSHAKE_MESSAGE)
1743 #ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE
1744 || s->
s3->
send_alert[1] == DTLS1_AD_MISSING_HANDSHAKE_MESSAGE
1769 dtls1_get_bitmap(
SSL *s,
SSL3_RECORD *rr,
unsigned int *is_next_epoch)
1792 dtls1_record_needs_buffering(
SSL *s,
SSL3_RECORD *rr,
unsigned short *priority,
1793 unsigned long *offset)
1811 unsigned short seq_num;
1818 seq_num = msg_hdr.seq;
1819 *offset = msg_hdr.frag_off;
1824 seq_num = ccs_hdr.seq;
1831 if ( seq_num < s->d1->handshake_read_seq)
1843 *priority = seq_num;
1875 memset(seq, 0x00, seq_bytes);