quic_record_util.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #ifndef OSSL_QUIC_RECORD_UTIL_H
  10. # define OSSL_QUIC_RECORD_UTIL_H
  11. # include <openssl/ssl.h>
  12. # include "internal/quic_types.h"
  13. # ifndef OPENSSL_NO_QUIC
  14. struct ossl_qrx_st;
  15. struct ossl_qtx_st;
  16. /*
  17. * QUIC Key Derivation Utilities
  18. * =============================
  19. */
  20. /* HKDF-Extract(salt, IKM) (RFC 5869) */
  21. int ossl_quic_hkdf_extract(OSSL_LIB_CTX *libctx,
  22. const char *propq,
  23. const EVP_MD *md,
  24. const unsigned char *salt, size_t salt_len,
  25. const unsigned char *ikm, size_t ikm_len,
  26. unsigned char *out, size_t out_len);
  27. /*
  28. * A QUIC client sends its first INITIAL packet with a random DCID, which
  29. * is used to compute the secrets used for INITIAL packet encryption in both
  30. * directions (both client-to-server and server-to-client).
  31. *
  32. * This function performs the necessary DCID-based key derivation, and then
  33. * provides the derived key material for the INITIAL encryption level to a QRX
  34. * instance, a QTX instance, or both.
  35. *
  36. * This function derives the necessary key material and then:
  37. * - if qrx is non-NULL, provides the appropriate secret to it;
  38. * - if qtx is non-NULL, provides the appropriate secret to it.
  39. *
  40. * If both qrx and qtx are NULL, this is a no-op. This function is equivalent to
  41. * making the appropriate calls to ossl_qrx_provide_secret() and
  42. * ossl_qtx_provide_secret().
  43. *
  44. * It is possible to use a QRX or QTX without ever calling this, for example if
  45. * there is no desire to handle INITIAL packets (e.g. if a QRX/QTX is
  46. * instantiated to succeed a previous QRX/QTX and handle a connection which is
  47. * already established). However in this case you should make sure you call
  48. * ossl_qrx_discard_enc_level(); see the header for that function for more
  49. * details. Calling ossl_qtx_discard_enc_level() is not essential but could
  50. * protect against programming errors.
  51. *
  52. * Returns 1 on success or 0 on error.
  53. */
  54. int ossl_quic_provide_initial_secret(OSSL_LIB_CTX *libctx,
  55. const char *propq,
  56. const QUIC_CONN_ID *dst_conn_id,
  57. int is_server,
  58. struct ossl_qrx_st *qrx,
  59. struct ossl_qtx_st *qtx);
  60. /*
  61. * QUIC Record Layer Ciphersuite Info
  62. * ==================================
  63. */
  64. /* Available QUIC Record Layer (QRL) ciphersuites. */
  65. # define QRL_SUITE_AES128GCM 1 /* SHA256 */
  66. # define QRL_SUITE_AES256GCM 2 /* SHA384 */
  67. # define QRL_SUITE_CHACHA20POLY1305 3 /* SHA256 */
  68. /* Returns cipher name in bytes or NULL if suite ID is invalid. */
  69. const char *ossl_qrl_get_suite_cipher_name(uint32_t suite_id);
  70. /* Returns hash function name in bytes or NULL if suite ID is invalid. */
  71. const char *ossl_qrl_get_suite_md_name(uint32_t suite_id);
  72. /* Returns secret length in bytes or 0 if suite ID is invalid. */
  73. uint32_t ossl_qrl_get_suite_secret_len(uint32_t suite_id);
  74. /* Returns key length in bytes or 0 if suite ID is invalid. */
  75. uint32_t ossl_qrl_get_suite_cipher_key_len(uint32_t suite_id);
  76. /* Returns IV length in bytes or 0 if suite ID is invalid. */
  77. uint32_t ossl_qrl_get_suite_cipher_iv_len(uint32_t suite_id);
  78. /* Returns AEAD auth tag length in bytes or 0 if suite ID is invalid. */
  79. uint32_t ossl_qrl_get_suite_cipher_tag_len(uint32_t suite_id);
  80. /* Returns a QUIC_HDR_PROT_CIPHER_* value or 0 if suite ID is invalid. */
  81. uint32_t ossl_qrl_get_suite_hdr_prot_cipher_id(uint32_t suite_id);
  82. /* Returns header protection key length in bytes or 0 if suite ID is invalid. */
  83. uint32_t ossl_qrl_get_suite_hdr_prot_key_len(uint32_t suite_id);
  84. /*
  85. * Returns maximum number of packets which may be safely encrypted with a suite
  86. * or 0 if suite ID is invalid.
  87. */
  88. uint64_t ossl_qrl_get_suite_max_pkt(uint32_t suite_id);
  89. /*
  90. * Returns maximum number of RX'd packets which may safely fail AEAD decryption
  91. * for a given suite or 0 if suite ID is invalid.
  92. */
  93. uint64_t ossl_qrl_get_suite_max_forged_pkt(uint32_t suite_id);
  94. # endif
  95. #endif