2 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/macros.h>
11 #include <openssl/objects.h>
12 #include "quic_local.h"
13 #include "internal/quic_vlint.h"
14 #include "internal/quic_wire.h"
16 OSSL_SAFE_MATH_UNSIGNED(uint64_t, uint64_t)
19 * QUIC Wire Format Encoding
20 * =========================
23 int ossl_quic_wire_encode_padding(WPACKET
*pkt
, size_t num_bytes
)
26 * PADDING is frame type zero, which as a variable-length integer is
27 * represented as a single zero byte. As an optimisation, just use memset.
29 return WPACKET_memset(pkt
, 0, num_bytes
);
32 static int encode_frame_hdr(WPACKET
*pkt
, uint64_t frame_type
)
34 return WPACKET_quic_write_vlint(pkt
, frame_type
);
37 int ossl_quic_wire_encode_frame_ping(WPACKET
*pkt
)
39 return encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_PING
);
42 int ossl_quic_wire_encode_frame_ack(WPACKET
*pkt
,
43 uint32_t ack_delay_exponent
,
44 const OSSL_QUIC_FRAME_ACK
*ack
)
46 uint64_t frame_type
= ack
->ecn_present
? OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN
47 : OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN
;
49 uint64_t largest_ackd
, first_ack_range
, ack_delay_enc
;
50 size_t i
, num_ack_ranges
= ack
->num_ack_ranges
;
53 if (num_ack_ranges
== 0)
56 delay
= ossl_time_divide(ossl_time_divide(ack
->delay_time
, OSSL_TIME_US
),
57 1UL << ack_delay_exponent
);
58 ack_delay_enc
= ossl_time2ticks(delay
);
60 largest_ackd
= ack
->ack_ranges
[0].end
;
61 first_ack_range
= ack
->ack_ranges
[0].end
- ack
->ack_ranges
[0].start
;
63 if (!encode_frame_hdr(pkt
, frame_type
)
64 || !WPACKET_quic_write_vlint(pkt
, largest_ackd
)
65 || !WPACKET_quic_write_vlint(pkt
, ack_delay_enc
)
66 || !WPACKET_quic_write_vlint(pkt
, num_ack_ranges
- 1)
67 || !WPACKET_quic_write_vlint(pkt
, first_ack_range
))
70 for (i
= 1; i
< num_ack_ranges
; ++i
) {
71 uint64_t gap
, range_len
;
73 gap
= ack
->ack_ranges
[i
- 1].start
- ack
->ack_ranges
[i
].end
- 2;
74 range_len
= ack
->ack_ranges
[i
].end
- ack
->ack_ranges
[i
].start
;
76 if (!WPACKET_quic_write_vlint(pkt
, gap
)
77 || !WPACKET_quic_write_vlint(pkt
, range_len
))
82 if (!WPACKET_quic_write_vlint(pkt
, ack
->ect0
)
83 || !WPACKET_quic_write_vlint(pkt
, ack
->ect1
)
84 || !WPACKET_quic_write_vlint(pkt
, ack
->ecnce
))
90 int ossl_quic_wire_encode_frame_reset_stream(WPACKET
*pkt
,
91 const OSSL_QUIC_FRAME_RESET_STREAM
*f
)
93 if (!encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_RESET_STREAM
)
94 || !WPACKET_quic_write_vlint(pkt
, f
->stream_id
)
95 || !WPACKET_quic_write_vlint(pkt
, f
->app_error_code
)
96 || !WPACKET_quic_write_vlint(pkt
, f
->final_size
))
102 int ossl_quic_wire_encode_frame_stop_sending(WPACKET
*pkt
,
103 const OSSL_QUIC_FRAME_STOP_SENDING
*f
)
105 if (!encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_STOP_SENDING
)
106 || !WPACKET_quic_write_vlint(pkt
, f
->stream_id
)
107 || !WPACKET_quic_write_vlint(pkt
, f
->app_error_code
))
113 int ossl_quic_wire_encode_frame_crypto_hdr(WPACKET
*pkt
,
114 const OSSL_QUIC_FRAME_CRYPTO
*f
)
116 if (!encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_CRYPTO
)
117 || !WPACKET_quic_write_vlint(pkt
, f
->offset
)
118 || !WPACKET_quic_write_vlint(pkt
, f
->len
))
124 void *ossl_quic_wire_encode_frame_crypto(WPACKET
*pkt
,
125 const OSSL_QUIC_FRAME_CRYPTO
*f
)
127 unsigned char *p
= NULL
;
129 if (!ossl_quic_wire_encode_frame_crypto_hdr(pkt
, f
)
130 || !WPACKET_allocate_bytes(pkt
, f
->len
, &p
))
134 memcpy(p
, f
->data
, f
->len
);
139 int ossl_quic_wire_encode_frame_new_token(WPACKET
*pkt
,
140 const unsigned char *token
,
143 if (!encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN
)
144 || !WPACKET_quic_write_vlint(pkt
, token_len
)
145 || !WPACKET_memcpy(pkt
, token
, token_len
))
151 int ossl_quic_wire_encode_frame_stream_hdr(WPACKET
*pkt
,
152 const OSSL_QUIC_FRAME_STREAM
*f
)
154 uint64_t frame_type
= OSSL_QUIC_FRAME_TYPE_STREAM
;
157 frame_type
|= OSSL_QUIC_FRAME_FLAG_STREAM_OFF
;
158 if (f
->has_explicit_len
)
159 frame_type
|= OSSL_QUIC_FRAME_FLAG_STREAM_LEN
;
161 frame_type
|= OSSL_QUIC_FRAME_FLAG_STREAM_FIN
;
163 if (!encode_frame_hdr(pkt
, frame_type
)
164 || !WPACKET_quic_write_vlint(pkt
, f
->stream_id
))
167 if (f
->offset
!= 0 && !WPACKET_quic_write_vlint(pkt
, f
->offset
))
170 if (f
->has_explicit_len
&& !WPACKET_quic_write_vlint(pkt
, f
->len
))
176 void *ossl_quic_wire_encode_frame_stream(WPACKET
*pkt
,
177 const OSSL_QUIC_FRAME_STREAM
*f
)
180 unsigned char *p
= NULL
;
182 if (!ossl_quic_wire_encode_frame_stream_hdr(pkt
, f
))
185 if (!WPACKET_allocate_bytes(pkt
, f
->len
, &p
))
189 memcpy(p
, f
->data
, f
->len
);
194 int ossl_quic_wire_encode_frame_max_data(WPACKET
*pkt
,
197 if (!encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_MAX_DATA
)
198 || !WPACKET_quic_write_vlint(pkt
, max_data
))
204 int ossl_quic_wire_encode_frame_max_stream_data(WPACKET
*pkt
,
208 if (!encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA
)
209 || !WPACKET_quic_write_vlint(pkt
, stream_id
)
210 || !WPACKET_quic_write_vlint(pkt
, max_data
))
216 int ossl_quic_wire_encode_frame_max_streams(WPACKET
*pkt
,
218 uint64_t max_streams
)
220 if (!encode_frame_hdr(pkt
, is_uni
? OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI
221 : OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI
)
222 || !WPACKET_quic_write_vlint(pkt
, max_streams
))
228 int ossl_quic_wire_encode_frame_data_blocked(WPACKET
*pkt
,
231 if (!encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED
)
232 || !WPACKET_quic_write_vlint(pkt
, max_data
))
239 int ossl_quic_wire_encode_frame_stream_data_blocked(WPACKET
*pkt
,
241 uint64_t max_stream_data
)
243 if (!encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED
)
244 || !WPACKET_quic_write_vlint(pkt
, stream_id
)
245 || !WPACKET_quic_write_vlint(pkt
, max_stream_data
))
251 int ossl_quic_wire_encode_frame_streams_blocked(WPACKET
*pkt
,
253 uint64_t max_streams
)
255 if (!encode_frame_hdr(pkt
, is_uni
? OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI
256 : OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI
)
257 || !WPACKET_quic_write_vlint(pkt
, max_streams
))
263 int ossl_quic_wire_encode_frame_new_conn_id(WPACKET
*pkt
,
264 const OSSL_QUIC_FRAME_NEW_CONN_ID
*f
)
266 if (f
->conn_id
.id_len
> OSSL_QUIC_MAX_CONN_ID_LEN
)
269 if (!encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID
)
270 || !WPACKET_quic_write_vlint(pkt
, f
->seq_num
)
271 || !WPACKET_quic_write_vlint(pkt
, f
->retire_prior_to
)
272 || !WPACKET_put_bytes_u8(pkt
, f
->conn_id
.id_len
)
273 || !WPACKET_memcpy(pkt
, f
->conn_id
.id
, f
->conn_id
.id_len
)
274 || !WPACKET_memcpy(pkt
, f
->stateless_reset_token
,
275 sizeof(f
->stateless_reset_token
)))
281 int ossl_quic_wire_encode_frame_retire_conn_id(WPACKET
*pkt
,
284 if (!encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID
)
285 || !WPACKET_quic_write_vlint(pkt
, seq_num
))
291 int ossl_quic_wire_encode_frame_path_challenge(WPACKET
*pkt
,
294 if (!encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE
)
295 || !WPACKET_put_bytes_u64(pkt
, data
))
301 int ossl_quic_wire_encode_frame_path_response(WPACKET
*pkt
,
304 if (!encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE
)
305 || !WPACKET_put_bytes_u64(pkt
, data
))
311 int ossl_quic_wire_encode_frame_conn_close(WPACKET
*pkt
,
312 const OSSL_QUIC_FRAME_CONN_CLOSE
*f
)
314 if (!encode_frame_hdr(pkt
, f
->is_app
? OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP
315 : OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_TRANSPORT
)
316 || !WPACKET_quic_write_vlint(pkt
, f
->error_code
))
319 if (!f
->is_app
&& !WPACKET_quic_write_vlint(pkt
, f
->frame_type
))
322 if (!WPACKET_quic_write_vlint(pkt
, f
->reason_len
)
323 || !WPACKET_memcpy(pkt
, f
->reason
, f
->reason_len
))
329 int ossl_quic_wire_encode_frame_handshake_done(WPACKET
*pkt
)
331 return encode_frame_hdr(pkt
, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE
);
334 unsigned char *ossl_quic_wire_encode_transport_param_bytes(WPACKET
*pkt
,
336 const unsigned char *value
,
339 unsigned char *b
= NULL
;
341 if (!WPACKET_quic_write_vlint(pkt
, id
)
342 || !WPACKET_quic_write_vlint(pkt
, value_len
)
343 || !WPACKET_allocate_bytes(pkt
, value_len
, (unsigned char **)&b
))
347 memcpy(b
, value
, value_len
);
352 int ossl_quic_wire_encode_transport_param_int(WPACKET
*pkt
,
356 if (!WPACKET_quic_write_vlint(pkt
, id
)
357 || !WPACKET_quic_write_vlint(pkt
, ossl_quic_vlint_encode_len(value
))
358 || !WPACKET_quic_write_vlint(pkt
, value
))
365 * QUIC Wire Format Decoding
366 * =========================
368 int ossl_quic_wire_peek_frame_header(PACKET
*pkt
, uint64_t *type
)
370 return PACKET_peek_quic_vlint(pkt
, type
);
373 int ossl_quic_wire_skip_frame_header(PACKET
*pkt
, uint64_t *type
)
375 return PACKET_get_quic_vlint(pkt
, type
);
378 static int expect_frame_header_mask(PACKET
*pkt
,
379 uint64_t expected_frame_type
,
381 uint64_t *actual_frame_type
)
383 uint64_t actual_frame_type_
;
385 if (!ossl_quic_wire_skip_frame_header(pkt
, &actual_frame_type_
)
386 || (actual_frame_type_
& ~mask_bits
) != expected_frame_type
)
389 if (actual_frame_type
!= NULL
)
390 *actual_frame_type
= actual_frame_type_
;
395 static int expect_frame_header(PACKET
*pkt
, uint64_t expected_frame_type
)
397 uint64_t actual_frame_type
;
399 if (!ossl_quic_wire_skip_frame_header(pkt
, &actual_frame_type
)
400 || actual_frame_type
!= expected_frame_type
)
406 int ossl_quic_wire_peek_frame_ack_num_ranges(const PACKET
*orig_pkt
,
407 uint64_t *total_ranges
)
409 PACKET pkt
= *orig_pkt
;
410 uint64_t ack_range_count
;
412 if (!expect_frame_header_mask(&pkt
, OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN
,
414 || !PACKET_skip_quic_vlint(&pkt
)
415 || !PACKET_skip_quic_vlint(&pkt
)
416 || !PACKET_get_quic_vlint(&pkt
, &ack_range_count
))
419 /* (cannot overflow because QUIC vlints can only encode up to 2**62-1) */
420 *total_ranges
= ack_range_count
+ 1;
424 int ossl_quic_wire_decode_frame_ack(PACKET
*pkt
,
425 uint32_t ack_delay_exponent
,
426 OSSL_QUIC_FRAME_ACK
*ack
,
427 uint64_t *total_ranges
) {
428 uint64_t frame_type
, largest_ackd
, ack_delay_raw
;
429 uint64_t ack_range_count
, first_ack_range
, start
, end
, i
;
431 /* This call matches both ACK_WITHOUT_ECN and ACK_WITH_ECN. */
432 if (!expect_frame_header_mask(pkt
, OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN
,
434 || !PACKET_get_quic_vlint(pkt
, &largest_ackd
)
435 || !PACKET_get_quic_vlint(pkt
, &ack_delay_raw
)
436 || !PACKET_get_quic_vlint(pkt
, &ack_range_count
)
437 || !PACKET_get_quic_vlint(pkt
, &first_ack_range
))
440 if (first_ack_range
> largest_ackd
)
443 start
= largest_ackd
- first_ack_range
;
448 = ossl_time_multiply(ossl_ticks2time(OSSL_TIME_US
),
449 safe_mul_uint64_t(ack_delay_raw
,
450 1UL << ack_delay_exponent
,
453 ack
->delay_time
= ossl_time_infinite();
455 if (ack
->num_ack_ranges
> 0) {
456 ack
->ack_ranges
[0].end
= largest_ackd
;
457 ack
->ack_ranges
[0].start
= start
;
461 for (i
= 0; i
< ack_range_count
; ++i
) {
464 if (!PACKET_get_quic_vlint(pkt
, &gap
)
465 || !PACKET_get_quic_vlint(pkt
, &len
))
468 end
= start
- gap
- 2;
469 if (start
< gap
+ 2 || len
> end
)
472 if (ack
!= NULL
&& i
+ 1 < ack
->num_ack_ranges
) {
473 ack
->ack_ranges
[i
+ 1].start
= start
= end
- len
;
474 ack
->ack_ranges
[i
+ 1].end
= end
;
478 if (ack
!= NULL
&& ack_range_count
+ 1 < ack
->num_ack_ranges
)
479 ack
->num_ack_ranges
= ack_range_count
+ 1;
481 if (total_ranges
!= NULL
)
482 *total_ranges
= ack_range_count
+ 1;
484 if (frame_type
== OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN
) {
485 uint64_t ect0
, ect1
, ecnce
;
487 if (!PACKET_get_quic_vlint(pkt
, &ect0
)
488 || !PACKET_get_quic_vlint(pkt
, &ect1
)
489 || !PACKET_get_quic_vlint(pkt
, &ecnce
))
496 ack
->ecn_present
= 1;
498 } else if (ack
!= NULL
) {
499 ack
->ecn_present
= 0;
505 int ossl_quic_wire_decode_frame_reset_stream(PACKET
*pkt
,
506 OSSL_QUIC_FRAME_RESET_STREAM
*f
)
508 if (!expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_RESET_STREAM
)
509 || !PACKET_get_quic_vlint(pkt
, &f
->stream_id
)
510 || !PACKET_get_quic_vlint(pkt
, &f
->app_error_code
)
511 || !PACKET_get_quic_vlint(pkt
, &f
->final_size
))
517 int ossl_quic_wire_decode_frame_stop_sending(PACKET
*pkt
,
518 OSSL_QUIC_FRAME_STOP_SENDING
*f
)
520 if (!expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_STOP_SENDING
)
521 || !PACKET_get_quic_vlint(pkt
, &f
->stream_id
)
522 || !PACKET_get_quic_vlint(pkt
, &f
->app_error_code
))
528 int ossl_quic_wire_decode_frame_crypto(PACKET
*pkt
,
529 OSSL_QUIC_FRAME_CRYPTO
*f
)
531 if (!expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_CRYPTO
)
532 || !PACKET_get_quic_vlint(pkt
, &f
->offset
)
533 || !PACKET_get_quic_vlint(pkt
, &f
->len
))
536 if (PACKET_remaining(pkt
) < f
->len
)
539 f
->data
= PACKET_data(pkt
);
541 if (!PACKET_forward(pkt
, f
->len
))
547 int ossl_quic_wire_decode_frame_new_token(PACKET
*pkt
,
548 const unsigned char **token
,
553 if (!expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN
)
554 || !PACKET_get_quic_vlint(pkt
, &token_len_
))
557 if (token_len_
> SIZE_MAX
)
560 *token
= PACKET_data(pkt
);
561 *token_len
= token_len_
;
563 if (!PACKET_forward(pkt
, token_len_
))
569 int ossl_quic_wire_decode_frame_stream(PACKET
*pkt
,
570 OSSL_QUIC_FRAME_STREAM
*f
)
574 /* This call matches all STREAM values (low 3 bits are masked). */
575 if (!expect_frame_header_mask(pkt
, OSSL_QUIC_FRAME_TYPE_STREAM
,
576 OSSL_QUIC_FRAME_FLAG_STREAM_MASK
,
578 || !PACKET_get_quic_vlint(pkt
, &f
->stream_id
))
581 if ((frame_type
& OSSL_QUIC_FRAME_FLAG_STREAM_OFF
) != 0) {
582 if (!PACKET_get_quic_vlint(pkt
, &f
->offset
))
588 f
->has_explicit_len
= ((frame_type
& OSSL_QUIC_FRAME_FLAG_STREAM_LEN
) != 0);
589 f
->is_fin
= ((frame_type
& OSSL_QUIC_FRAME_FLAG_STREAM_FIN
) != 0);
591 if (f
->has_explicit_len
) {
592 if (!PACKET_get_quic_vlint(pkt
, &f
->len
))
595 f
->len
= PACKET_remaining(pkt
);
598 f
->data
= PACKET_data(pkt
);
600 if (!PACKET_forward(pkt
, f
->len
))
606 int ossl_quic_wire_decode_frame_max_data(PACKET
*pkt
,
609 if (!expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_MAX_DATA
)
610 || !PACKET_get_quic_vlint(pkt
, max_data
))
616 int ossl_quic_wire_decode_frame_max_stream_data(PACKET
*pkt
,
618 uint64_t *max_stream_data
)
620 if (!expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA
)
621 || !PACKET_get_quic_vlint(pkt
, stream_id
)
622 || !PACKET_get_quic_vlint(pkt
, max_stream_data
))
628 int ossl_quic_wire_decode_frame_max_streams(PACKET
*pkt
,
629 uint64_t *max_streams
)
631 /* This call matches both MAX_STREAMS_BIDI and MAX_STREAMS_UNI. */
632 if (!expect_frame_header_mask(pkt
, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI
,
634 || !PACKET_get_quic_vlint(pkt
, max_streams
))
640 int ossl_quic_wire_decode_frame_data_blocked(PACKET
*pkt
,
643 if (!expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED
)
644 || !PACKET_get_quic_vlint(pkt
, max_data
))
650 int ossl_quic_wire_decode_frame_stream_data_blocked(PACKET
*pkt
,
652 uint64_t *max_stream_data
)
654 if (!expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED
)
655 || !PACKET_get_quic_vlint(pkt
, stream_id
)
656 || !PACKET_get_quic_vlint(pkt
, max_stream_data
))
662 int ossl_quic_wire_decode_frame_streams_blocked(PACKET
*pkt
,
663 uint64_t *max_streams
)
665 /* This call matches both STREAMS_BLOCKED_BIDI and STREAMS_BLOCKED_UNI. */
666 if (!expect_frame_header_mask(pkt
, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI
,
668 || !PACKET_get_quic_vlint(pkt
, max_streams
))
674 int ossl_quic_wire_decode_frame_new_conn_id(PACKET
*pkt
,
675 OSSL_QUIC_FRAME_NEW_CONN_ID
*f
)
679 if (!expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID
)
680 || !PACKET_get_quic_vlint(pkt
, &f
->seq_num
)
681 || !PACKET_get_quic_vlint(pkt
, &f
->retire_prior_to
)
682 || !PACKET_get_1(pkt
, &len
)
683 || len
> OSSL_QUIC_MAX_CONN_ID_LEN
)
686 f
->conn_id
.id_len
= (unsigned char)len
;
687 if (!PACKET_copy_bytes(pkt
, f
->conn_id
.id
, len
))
690 /* Clear unused bytes to allow consistent memcmp. */
691 if (len
< OSSL_QUIC_MAX_CONN_ID_LEN
)
692 memset(f
->conn_id
.id
+ len
, 0, OSSL_QUIC_MAX_CONN_ID_LEN
- len
);
694 if (!PACKET_copy_bytes(pkt
, f
->stateless_reset_token
,
695 sizeof(f
->stateless_reset_token
)))
701 int ossl_quic_wire_decode_frame_retire_conn_id(PACKET
*pkt
,
704 if (!expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID
)
705 || !PACKET_get_quic_vlint(pkt
, seq_num
))
711 int ossl_quic_wire_decode_frame_path_challenge(PACKET
*pkt
,
714 if (!expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE
)
715 || !PACKET_get_net_8(pkt
, data
))
721 int ossl_quic_wire_decode_frame_path_response(PACKET
*pkt
,
724 if (!expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE
)
725 || !PACKET_get_net_8(pkt
, data
))
731 int ossl_quic_wire_decode_frame_conn_close(PACKET
*pkt
,
732 OSSL_QUIC_FRAME_CONN_CLOSE
*f
)
734 uint64_t frame_type
, reason_len
;
736 /* This call matches both CONN_CLOSE_TRANSPORT and CONN_CLOSE_APP. */
737 if (!expect_frame_header_mask(pkt
, OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_TRANSPORT
,
739 || !PACKET_get_quic_vlint(pkt
, &f
->error_code
))
742 f
->is_app
= ((frame_type
& 1) != 0);
745 if (!PACKET_get_quic_vlint(pkt
, &f
->frame_type
))
751 if (!PACKET_get_quic_vlint(pkt
, &reason_len
)
752 || reason_len
> SIZE_MAX
)
755 if (!PACKET_get_bytes(pkt
, (const unsigned char **)&f
->reason
, reason_len
))
758 f
->reason_len
= reason_len
;
762 size_t ossl_quic_wire_decode_padding(PACKET
*pkt
)
764 const unsigned char *start
= PACKET_data(pkt
), *end
= PACKET_end(pkt
),
767 while (p
< end
&& *p
== 0)
770 if (!PACKET_forward(pkt
, p
- start
))
776 int ossl_quic_wire_decode_frame_ping(PACKET
*pkt
)
778 return expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_PING
);
781 int ossl_quic_wire_decode_frame_handshake_done(PACKET
*pkt
)
783 return expect_frame_header(pkt
, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE
);
786 int ossl_quic_wire_peek_transport_param(PACKET
*pkt
, uint64_t *id
)
788 return PACKET_peek_quic_vlint(pkt
, id
);
791 const unsigned char *ossl_quic_wire_decode_transport_param_bytes(PACKET
*pkt
,
796 const unsigned char *b
= NULL
;
798 if (!PACKET_get_quic_vlint(pkt
, id
)
799 || !PACKET_get_quic_vlint(pkt
, &len_
))
803 || !PACKET_get_bytes(pkt
, (const unsigned char **)&b
, (size_t)len_
))
810 int ossl_quic_wire_decode_transport_param_int(PACKET
*pkt
,
816 sub
.curr
= ossl_quic_wire_decode_transport_param_bytes(pkt
,
818 if (sub
.curr
== NULL
)
821 if (!PACKET_get_quic_vlint(&sub
, value
))