]> git.ipfire.org Git - thirdparty/openssl.git/blob - include/internal/quic_types.h
Copyright year updates
[thirdparty/openssl.git] / include / internal / quic_types.h
1 /*
2 * Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
10 #ifndef OSSL_QUIC_TYPES_H
11 # define OSSL_QUIC_TYPES_H
12
13 # include <openssl/ssl.h>
14 # include <internal/ssl.h>
15 # include <assert.h>
16 # include <string.h>
17
18 # ifndef OPENSSL_NO_QUIC
19
20 /* QUIC encryption levels. */
21 enum {
22 QUIC_ENC_LEVEL_INITIAL = 0,
23 QUIC_ENC_LEVEL_HANDSHAKE,
24 QUIC_ENC_LEVEL_0RTT,
25 QUIC_ENC_LEVEL_1RTT,
26 QUIC_ENC_LEVEL_NUM /* Must be the ultimate entry */
27 };
28
29 /* QUIC packet number spaces. */
30 enum {
31 QUIC_PN_SPACE_INITIAL = 0,
32 QUIC_PN_SPACE_HANDSHAKE,
33 /* New entries must go here, so that QUIC_PN_SPACE_APP is the penultimate */
34 QUIC_PN_SPACE_APP,
35 QUIC_PN_SPACE_NUM /* Must be the ultimate entry */
36 };
37
38 static ossl_unused ossl_inline uint32_t
39 ossl_quic_enc_level_to_pn_space(uint32_t enc_level)
40 {
41 switch (enc_level) {
42 case QUIC_ENC_LEVEL_INITIAL:
43 return QUIC_PN_SPACE_INITIAL;
44 case QUIC_ENC_LEVEL_HANDSHAKE:
45 return QUIC_PN_SPACE_HANDSHAKE;
46 case QUIC_ENC_LEVEL_0RTT:
47 case QUIC_ENC_LEVEL_1RTT:
48 return QUIC_PN_SPACE_APP;
49 default:
50 assert(0);
51 return QUIC_PN_SPACE_APP;
52 }
53 }
54
55 /* QUIC packet number representation. */
56 typedef uint64_t QUIC_PN;
57 # define QUIC_PN_INVALID UINT64_MAX
58
59 static ossl_unused ossl_inline QUIC_PN ossl_quic_pn_max(QUIC_PN a, QUIC_PN b)
60 {
61 return a > b ? a : b;
62 }
63
64 static ossl_unused ossl_inline QUIC_PN ossl_quic_pn_min(QUIC_PN a, QUIC_PN b)
65 {
66 return a < b ? a : b;
67 }
68
69 static ossl_unused ossl_inline int ossl_quic_pn_valid(QUIC_PN pn)
70 {
71 return pn < (((QUIC_PN)1) << 62);
72 }
73
74 /* QUIC connection ID representation. */
75 # define QUIC_MAX_CONN_ID_LEN 20
76
77 typedef struct quic_conn_id_st {
78 unsigned char id_len, id[QUIC_MAX_CONN_ID_LEN];
79 } QUIC_CONN_ID;
80
81 static ossl_unused ossl_inline int ossl_quic_conn_id_eq(const QUIC_CONN_ID *a,
82 const QUIC_CONN_ID *b)
83 {
84 if (a->id_len != b->id_len || a->id_len > QUIC_MAX_CONN_ID_LEN)
85 return 0;
86 return memcmp(a->id, b->id, a->id_len) == 0;
87 }
88
89 # define QUIC_MIN_INITIAL_DGRAM_LEN 1200
90
91 # define QUIC_DEFAULT_ACK_DELAY_EXP 3
92 # define QUIC_MAX_ACK_DELAY_EXP 20
93
94 # define QUIC_DEFAULT_MAX_ACK_DELAY 25
95
96 # define QUIC_MIN_ACTIVE_CONN_ID_LIMIT 2
97
98 /* Arbitrary choice of default idle timeout (not an RFC value). */
99 # define QUIC_DEFAULT_IDLE_TIMEOUT 30000
100
101 # define QUIC_STATELESS_RESET_TOKEN_LEN 16
102
103 typedef struct {
104 unsigned char token[QUIC_STATELESS_RESET_TOKEN_LEN];
105 } QUIC_STATELESS_RESET_TOKEN;
106
107 /*
108 * An encoded preferred_addr transport parameter cannot be shorter or longer
109 * than these lengths in bytes.
110 */
111 # define QUIC_MIN_ENCODED_PREFERRED_ADDR_LEN 41
112 # define QUIC_MAX_ENCODED_PREFERRED_ADDR_LEN 61
113
114 # endif
115
116 #endif