/*
- * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
# ifndef OPENSSL_NO_QUIC
/* QUIC encryption levels. */
-# define QUIC_ENC_LEVEL_INITIAL 0
-# define QUIC_ENC_LEVEL_HANDSHAKE 1
-# define QUIC_ENC_LEVEL_0RTT 2
-# define QUIC_ENC_LEVEL_1RTT 3
-# define QUIC_ENC_LEVEL_NUM 4
+enum {
+ QUIC_ENC_LEVEL_INITIAL = 0,
+ QUIC_ENC_LEVEL_HANDSHAKE,
+ QUIC_ENC_LEVEL_0RTT,
+ QUIC_ENC_LEVEL_1RTT,
+ QUIC_ENC_LEVEL_NUM /* Must be the ultimate entry */
+};
/* QUIC packet number spaces. */
-# define QUIC_PN_SPACE_INITIAL 0
-# define QUIC_PN_SPACE_HANDSHAKE 1
-# define QUIC_PN_SPACE_APP 2
-# define QUIC_PN_SPACE_NUM 3
+enum {
+ QUIC_PN_SPACE_INITIAL = 0,
+ QUIC_PN_SPACE_HANDSHAKE,
+ /* New entries must go here, so that QUIC_PN_SPACE_APP is the penultimate */
+ QUIC_PN_SPACE_APP,
+ QUIC_PN_SPACE_NUM /* Must be the ultimate entry */
+};
static ossl_unused ossl_inline uint32_t
ossl_quic_enc_level_to_pn_space(uint32_t enc_level)
}
}
-/* QUIC packet number spaces. */
-# define QUIC_PN_SPACE_INITIAL 0
-# define QUIC_PN_SPACE_HANDSHAKE 1
-# define QUIC_PN_SPACE_APP 2
-# define QUIC_PN_SPACE_NUM 3
-
/* QUIC packet number representation. */
typedef uint64_t QUIC_PN;
# define QUIC_PN_INVALID UINT64_MAX
return a < b ? a : b;
}
+static ossl_unused ossl_inline int ossl_quic_pn_valid(QUIC_PN pn)
+{
+ return pn < (((QUIC_PN)1) << 62);
+}
+
/* QUIC connection ID representation. */
# define QUIC_MAX_CONN_ID_LEN 20
+# define QUIC_MIN_ODCID_LEN 8 /* RFC 9000 s. 7.2 */
typedef struct quic_conn_id_st {
unsigned char id_len, id[QUIC_MAX_CONN_ID_LEN];
return memcmp(a->id, b->id, a->id_len) == 0;
}
+/*
+ * Generates a random CID of the given length. libctx may be NULL.
+ * Returns 1 on success or 0 on failure.
+ */
+int ossl_quic_gen_rand_conn_id(OSSL_LIB_CTX *libctx, size_t len,
+ QUIC_CONN_ID *cid);
+
# define QUIC_MIN_INITIAL_DGRAM_LEN 1200
# define QUIC_DEFAULT_ACK_DELAY_EXP 3
# define QUIC_STATELESS_RESET_TOKEN_LEN 16
+typedef struct {
+ unsigned char token[QUIC_STATELESS_RESET_TOKEN_LEN];
+} QUIC_STATELESS_RESET_TOKEN;
+
+/*
+ * An encoded preferred_addr transport parameter cannot be shorter or longer
+ * than these lengths in bytes.
+ */
+# define QUIC_MIN_ENCODED_PREFERRED_ADDR_LEN 41
+# define QUIC_MAX_ENCODED_PREFERRED_ADDR_LEN 61
+
# endif
#endif