summaryrefslogtreecommitdiff
path: root/src/lib/libssl
diff options
context:
space:
mode:
authorjsing <>2026-07-16 14:37:21 +0000
committerjsing <>2026-07-16 14:37:21 +0000
commit8ae67bc076214ca24ed2b1e80df490ba9ec3126b (patch)
tree4a5fd950855fdfb0377df3f06c436d2e1b6d7fe6 /src/lib/libssl
parentcf7a40bb11f97c00986c060585e3bc517ff3b9fb (diff)
downloadopenbsd-8ae67bc076214ca24ed2b1e80df490ba9ec3126b.tar.gz
openbsd-8ae67bc076214ca24ed2b1e80df490ba9ec3126b.tar.bz2
openbsd-8ae67bc076214ca24ed2b1e80df490ba9ec3126b.zip
Clean up sequence number and message header handling.
dtls1_set_message_header() is only called in one place - inline the write handshake sequence number handling. Rename dtls1_set_message_header_int() to dtls1_set_message_header(). The dtls12_write_ccs() code does not use handshake sequence numbers (since they're not handshake messages) - stop pretending that it does. ok kenjiro@ tb@
Diffstat (limited to 'src/lib/libssl')
-rw-r--r--src/lib/libssl/d1_both.c33
-rw-r--r--src/lib/libssl/dtls_local.h6
2 files changed, 13 insertions, 26 deletions
diff --git a/src/lib/libssl/d1_both.c b/src/lib/libssl/d1_both.c
index d3742cbd12..57390112c9 100644
--- a/src/lib/libssl/d1_both.c
+++ b/src/lib/libssl/d1_both.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_both.c,v 1.97 2026/06/06 15:28:14 jsing Exp $ */ 1/* $OpenBSD: d1_both.c,v 1.98 2026/07/16 14:37:21 jsing Exp $ */
2/* 2/*
3 * DTLS implementation written by Nagendra Modadugu 3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -941,7 +941,7 @@ dtls1_retransmit_message(SSL *s, hm_fragment *frag)
941 frag->msg_header.msg_len + header_length); 941 frag->msg_header.msg_len + header_length);
942 s->init_num = frag->msg_header.msg_len + header_length; 942 s->init_num = frag->msg_header.msg_len + header_length;
943 943
944 dtls1_set_message_header_int(s, frag->msg_header.type, 944 dtls1_set_message_header(s, frag->msg_header.type,
945 frag->msg_header.msg_len, frag->msg_header.seq, 0, 945 frag->msg_header.msg_len, frag->msg_header.seq, 0,
946 frag->msg_header.frag_len); 946 frag->msg_header.frag_len);
947 947
@@ -1057,21 +1057,6 @@ dtls1_clear_record_buffer(SSL *s)
1057 1057
1058void 1058void
1059dtls1_set_message_header(SSL *s, unsigned char mt, unsigned long len, 1059dtls1_set_message_header(SSL *s, unsigned char mt, unsigned long len,
1060 unsigned long frag_off, unsigned long frag_len)
1061{
1062 /* Don't change sequence numbers while listening */
1063 if (frag_off == 0 && !s->d1->listen) {
1064 s->d1->handshake_write_seq = s->d1->next_handshake_write_seq;
1065 s->d1->next_handshake_write_seq++;
1066 }
1067
1068 dtls1_set_message_header_int(s, mt, len, s->d1->handshake_write_seq,
1069 frag_off, frag_len);
1070}
1071
1072/* don't actually do the writing, wait till the MTU has been retrieved */
1073void
1074dtls1_set_message_header_int(SSL *s, unsigned char mt, unsigned long len,
1075 unsigned short seq_num, unsigned long frag_off, unsigned long frag_len) 1060 unsigned short seq_num, unsigned long frag_off, unsigned long frag_len)
1076{ 1061{
1077 struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr; 1062 struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr;
@@ -1166,10 +1151,7 @@ dtls1_get_message_header(CBS *header, struct hm_header_st *msg_hdr)
1166int 1151int
1167dtls12_ccs_built(SSL *s) 1152dtls12_ccs_built(SSL *s)
1168{ 1153{
1169 s->d1->handshake_write_seq = s->d1->next_handshake_write_seq; 1154 dtls1_set_message_header(s, SSL3_MT_CCS, 0, 0, 0, 0);
1170
1171 dtls1_set_message_header_int(s, SSL3_MT_CCS, 0,
1172 s->d1->handshake_write_seq, 0, 0);
1173 1155
1174 if (!dtls1_buffer_message(s, 1)) 1156 if (!dtls1_buffer_message(s, 1))
1175 return 0; 1157 return 0;
@@ -1195,7 +1177,14 @@ dtls12_handshake_msg_built(SSL *s)
1195 1177
1196 len = s->init_num - DTLS1_HM_HEADER_LENGTH; 1178 len = s->init_num - DTLS1_HM_HEADER_LENGTH;
1197 1179
1198 dtls1_set_message_header(s, msg_type, len, 0, len); 1180 /* Do not change sequence numbers while listening. */
1181 if (!s->d1->listen) {
1182 s->d1->handshake_write_seq = s->d1->next_handshake_write_seq;
1183 s->d1->next_handshake_write_seq++;
1184 }
1185
1186 dtls1_set_message_header(s, msg_type, len, s->d1->handshake_write_seq,
1187 0, len);
1199 1188
1200 if (!dtls1_buffer_message(s, 0)) 1189 if (!dtls1_buffer_message(s, 0))
1201 return 0; 1190 return 0;
diff --git a/src/lib/libssl/dtls_local.h b/src/lib/libssl/dtls_local.h
index 9939928b38..c1ac35055a 100644
--- a/src/lib/libssl/dtls_local.h
+++ b/src/lib/libssl/dtls_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: dtls_local.h,v 1.8 2026/06/06 15:24:26 jsing Exp $ */ 1/* $OpenBSD: dtls_local.h,v 1.9 2026/07/16 14:37:21 jsing Exp $ */
2/* 2/*
3 * DTLS implementation written by Nagendra Modadugu 3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -186,9 +186,7 @@ struct dtls1_state_st {
186 186
187int dtls1_do_write(SSL *s, int type); 187int dtls1_do_write(SSL *s, int type);
188int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek); 188int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
189void dtls1_set_message_header(SSL *s, unsigned char mt, unsigned long len, 189void dtls1_set_message_header(SSL *s, unsigned char mt,
190 unsigned long frag_off, unsigned long frag_len);
191void dtls1_set_message_header_int(SSL *s, unsigned char mt,
192 unsigned long len, unsigned short seq_num, unsigned long frag_off, 190 unsigned long len, unsigned short seq_num, unsigned long frag_off,
193 unsigned long frag_len); 191 unsigned long frag_len);
194 192