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