wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
twogen.h
1#ifndef KUSWITCH_TWOGEN_H
2#define KUSWITCH_TWOGEN_H
3
5
6/* RFC 9001 6.3/6.5: an endpoint keeps the current 1-RTT keys and, after a key
7 * update, the immediately prior keys, so packets in flight under the old key
8 * can still be decrypted until the retention period ends. A received packet's
9 * Key Phase bit selects which generation decrypts it. */
10
21
22/* Initialise at generation 0 with the first 1-RTT keys; no old key yet. */
23void kuswitch_init(kuswitch_state* state, const initial_keys* gen0);
24
25/* RFC 9001 6.3: advance to the next generation. The current keys become old
26 * (retained), and next becomes current; generation increments. */
27void kuswitch_rotate(kuswitch_state* state, const initial_keys* next);
28
29/* RFC 9001 6.3: choose the keys that decrypt a packet carrying recv_phase_bit.
30 * Returns 1 with *keys set when a matching generation is available, 0 when the
31 * bit asks for an old generation that is not (or no longer) retained. */
32int kuswitch_key_for_phase(
33 const kuswitch_state* state, int recv_phase_bit, const initial_keys** keys);
34
35/* RFC 9001 6.5: drop the retained old key once its retention period ends. */
36void kuswitch_discard_old(kuswitch_state* state);
37
38#endif
RFC 9001 5.2: Initial packet protection keys derived from the client's Destination Connection ID.
One direction's packet protection keys (RFC 9001 5.1/5.2).
Definition initial.h:28
RFC 9001 6.3/6.5 two-generation key state: the current 1-RTT keys and, once a Key Update has happened...
Definition twogen.h:15
u64 generation
current send/receive generation, starts at 0
Definition twogen.h:18
initial_keys old
prior generation's keys (valid when have_old)
Definition twogen.h:17
int have_old
1 while old is populated and retained
Definition twogen.h:19
initial_keys cur
current generation's keys
Definition twogen.h:16
unsigned long u64
unsigned 64-bit integer
Definition types.h:13