@@ -1957,6 +1957,13 @@ static int qc_do_build_pkt(unsigned char *pos, const unsigned char *end,
1957
1957
add_ping_frm = 1 ;
1958
1958
len += 1 ;
1959
1959
dglen += 1 ;
1960
+
1961
+ /* Ensure packet is big enough so that header protection sample
1962
+ * decryption can be performed. Note that +1 is for the PING
1963
+ * frame.
1964
+ */
1965
+ if (!padding && * pn_len + 1 < QUIC_PACKET_PN_MAXLEN )
1966
+ len += padding_len = QUIC_PACKET_PN_MAXLEN - * pn_len - 1 ;
1960
1967
}
1961
1968
1962
1969
/* Handle Initial packet padding if necessary. */
@@ -1974,29 +1981,14 @@ static int qc_do_build_pkt(unsigned char *pos, const unsigned char *end,
1974
1981
}
1975
1982
}
1976
1983
}
1977
-
1978
- /* RFC 9001 5.4.2. Header Protection Sample
1979
- *
1980
- * To ensure that sufficient data is available for sampling, packets are
1981
- * padded so that the combined lengths of the encoded packet number and
1982
- * protected payload is at least 4 bytes longer than the sample required
1983
- * for header protection. The cipher suites defined in [TLS13] -- other
1984
- * than TLS_AES_128_CCM_8_SHA256, for which a header protection scheme
1985
- * is not defined in this document -- have 16-byte expansions and 16-
1986
- * byte header protection samples. This results in needing at least 3
1987
- * bytes of frames in the unprotected payload if the packet number is
1988
- * encoded on a single byte, or 2 bytes of frames for a 2-byte packet
1989
- * number encoding.
1990
- */
1991
-
1992
- /* Add padding if packet is too small for HP sampling as specified
1993
- * above. QUIC TLS algos relies on 16 bytes sample extracted 4 bytes
1994
- * after PN offset. Thus, pn and payload must be at least 4 bytes long,
1995
- * so that the sample will be extracted as the AEAD tag.
1996
- */
1997
- if (* pn_len + len < QUIC_PACKET_PN_MAXLEN + QUIC_HP_SAMPLE_LEN ) {
1998
- padding_len = QUIC_PACKET_PN_MAXLEN + QUIC_HP_SAMPLE_LEN - (* pn_len + len );
1999
- len += padding_len ;
1984
+ else if (len_frms && len_frms < QUIC_PACKET_PN_MAXLEN ) {
1985
+ len += padding_len = QUIC_PACKET_PN_MAXLEN - len_frms ;
1986
+ }
1987
+ /* TODO qc_do_build_pkt() must rely on its <probe> argument instead of using QEL <pto_probe> field. */
1988
+ else if (LIST_ISEMPTY (& frm_list ) && !cc && !qel -> pktns -> tx .pto_probe ) {
1989
+ /* If there is no frame at all to follow, add at least a PADDING frame. */
1990
+ if (!ack_frm_len )
1991
+ len += padding_len = QUIC_PACKET_PN_MAXLEN - * pn_len ;
2000
1992
}
2001
1993
2002
1994
if (pkt -> type != QUIC_PACKET_TYPE_SHORT && !quic_enc_int (& pos , end , len ))
0 commit comments