quic_srt_gen.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 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_INTERNAL_QUIC_SRT_GEN_H
  10. # define OSSL_INTERNAL_QUIC_SRT_GEN_H
  11. # pragma once
  12. # include "internal/e_os.h"
  13. # include "internal/time.h"
  14. # include "internal/quic_types.h"
  15. # include "internal/quic_wire.h"
  16. # ifndef OPENSSL_NO_QUIC
  17. /*
  18. * QUIC Stateless Reset Token Generator
  19. * ====================================
  20. *
  21. * This generates 16-byte QUIC Stateless Reset Tokens given a secret symmetric
  22. * key and a DCID. Because the output is deterministic with regards to these
  23. * inputs, assuming the same key is used between invocations of a process, we
  24. * are able to generate the same stateless reset token in a subsequent process,
  25. * thereby allowing us to achieve stateless reset of a peer which still thinks
  26. * it is connected to a past process at the same UDP address.
  27. */
  28. typedef struct quic_srt_gen_st QUIC_SRT_GEN;
  29. /*
  30. * Create a new stateless reset token generator using the given key as input.
  31. * The key may be of arbitrary length.
  32. *
  33. * The caller is responsible for performing domain separation with regards to
  34. * the key; i.e., the caller is responsible for ensuring the key is never used
  35. * in any other context.
  36. */
  37. QUIC_SRT_GEN *ossl_quic_srt_gen_new(OSSL_LIB_CTX *libctx, const char *propq,
  38. const unsigned char *key, size_t key_len);
  39. /* Free the stateless reset token generator. No-op if srt_gen is NULL. */
  40. void ossl_quic_srt_gen_free(QUIC_SRT_GEN *srt_gen);
  41. /*
  42. * Calculates a token using the given DCID and writes it to *token. Returns 0 on
  43. * failure.
  44. */
  45. int ossl_quic_srt_gen_calculate_token(QUIC_SRT_GEN *srt_gen,
  46. const QUIC_CONN_ID *dcid,
  47. QUIC_STATELESS_RESET_TOKEN *token);
  48. # endif
  49. #endif