quic_types.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2022 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. #ifndef OSSL_QUIC_TYPES_H
  10. # define OSSL_QUIC_TYPES_H
  11. # include <openssl/ssl.h>
  12. # include <assert.h>
  13. # include <string.h>
  14. /* QUIC encryption levels. */
  15. #define QUIC_ENC_LEVEL_INITIAL 0
  16. #define QUIC_ENC_LEVEL_HANDSHAKE 1
  17. #define QUIC_ENC_LEVEL_0RTT 2
  18. #define QUIC_ENC_LEVEL_1RTT 3
  19. #define QUIC_ENC_LEVEL_NUM 4
  20. /* QUIC packet number spaces. */
  21. #define QUIC_PN_SPACE_INITIAL 0
  22. #define QUIC_PN_SPACE_HANDSHAKE 1
  23. #define QUIC_PN_SPACE_APP 2
  24. #define QUIC_PN_SPACE_NUM 3
  25. static ossl_unused ossl_inline uint32_t
  26. ossl_quic_enc_level_to_pn_space(uint32_t enc_level)
  27. {
  28. switch (enc_level) {
  29. case QUIC_ENC_LEVEL_INITIAL:
  30. return QUIC_PN_SPACE_INITIAL;
  31. case QUIC_ENC_LEVEL_HANDSHAKE:
  32. return QUIC_PN_SPACE_HANDSHAKE;
  33. case QUIC_ENC_LEVEL_0RTT:
  34. case QUIC_ENC_LEVEL_1RTT:
  35. return QUIC_PN_SPACE_APP;
  36. default:
  37. assert(0);
  38. return QUIC_PN_SPACE_APP;
  39. }
  40. }
  41. /* QUIC packet number spaces. */
  42. #define QUIC_PN_SPACE_INITIAL 0
  43. #define QUIC_PN_SPACE_HANDSHAKE 1
  44. #define QUIC_PN_SPACE_APP 2
  45. #define QUIC_PN_SPACE_NUM 3
  46. /* QUIC packet number representation. */
  47. typedef uint64_t QUIC_PN;
  48. # define QUIC_PN_INVALID UINT64_MAX
  49. static ossl_unused ossl_inline QUIC_PN ossl_quic_pn_max(QUIC_PN a, QUIC_PN b)
  50. {
  51. return a > b ? a : b;
  52. }
  53. static ossl_unused ossl_inline QUIC_PN ossl_quic_pn_min(QUIC_PN a, QUIC_PN b)
  54. {
  55. return a < b ? a : b;
  56. }
  57. /* QUIC connection ID representation. */
  58. #define QUIC_MAX_CONN_ID_LEN 20
  59. typedef struct quic_conn_id_st {
  60. unsigned char id_len, id[QUIC_MAX_CONN_ID_LEN];
  61. } QUIC_CONN_ID;
  62. static ossl_unused ossl_inline int ossl_quic_conn_id_eq(const QUIC_CONN_ID *a,
  63. const QUIC_CONN_ID *b)
  64. {
  65. if (a->id_len != b->id_len || a->id_len > QUIC_MAX_CONN_ID_LEN)
  66. return 0;
  67. return memcmp(a->id, b->id, a->id_len) == 0;
  68. }
  69. #define QUIC_MIN_INITIAL_DGRAM_LEN 1200
  70. #endif