Skip to content

Commit 93e06fa

Browse files
authored
Merge pull request #1848 from EndPositive/fix-pn-enc-short-messages
Add padding to packets too small for PN encryption
2 parents f0eaf10 + cdacce2 commit 93e06fa

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

picoquic/sender.c

+9
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,9 @@ size_t picoquic_protect_packet(picoquic_cnx_t* cnx,
843843
size_t pn_offset = 0;
844844
size_t pn_length = 0;
845845
size_t aead_checksum_length = picoquic_aead_get_checksum_length(aead_context);
846+
size_t pn_iv_size = picoquic_pn_iv_size(pn_enc);
847+
size_t pn_sample_start;
848+
size_t pn_sample_end;
846849
uint8_t first_mask = 0x0F;
847850

848851
/* Create the packet header just before encrypting the content */
@@ -857,6 +860,12 @@ size_t picoquic_protect_packet(picoquic_cnx_t* cnx,
857860
picoquic_log_app_message(cnx, "BUFFER OVERFLOW? Packet header prediction fails, %zu instead of %zu\n", h_length, header_length);
858861
}
859862

863+
// https://datatracker.ietf.org/doc/html/rfc9001#section-5.4.2
864+
// ensure there are enough iv bytes for pn encryption
865+
pn_sample_start = pn_offset + 4;
866+
pn_sample_end = pn_sample_start + pn_iv_size;
867+
length = picoquic_pad_to_target_length(bytes, length, pn_sample_end - aead_checksum_length); // discount aead checksum length added later
868+
860869
if (ptype == picoquic_packet_1rtt_protected) {
861870
if (cnx->is_loss_bit_enabled_outgoing) {
862871
first_mask = 0x07;

0 commit comments

Comments
 (0)