Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
keys.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
7#include <array>
8#include <cstdint>
9#include <string>
10
12{
13
14// ============================================================================
15// Constants
16// ============================================================================
17
19constexpr size_t aes_128_key_size = 16;
20
22constexpr size_t aes_256_key_size = 32;
23
25constexpr size_t aead_iv_size = 12;
26
28constexpr size_t aead_tag_size = 16;
29
31constexpr size_t secret_size = 32;
32
34constexpr size_t hp_key_size = 16;
35
37constexpr size_t hp_sample_size = 16;
38
39// ============================================================================
40// Encryption Levels
41// ============================================================================
42
53enum class encryption_level : uint8_t
54{
55 initial = 0,
56 handshake = 1,
57 zero_rtt = 2,
58 application = 3
59};
60
66[[nodiscard]] auto encryption_level_to_string(encryption_level level) -> std::string;
67
72[[nodiscard]] constexpr auto encryption_level_count() noexcept -> size_t
73{
74 return 4;
75}
76
77// ============================================================================
78// Key Structures
79// ============================================================================
80
92{
94 std::array<uint8_t, secret_size> secret{};
95
97 std::array<uint8_t, aes_128_key_size> key{};
98
100 std::array<uint8_t, aead_iv_size> iv{};
101
103 std::array<uint8_t, hp_key_size> hp_key{};
104
109 [[nodiscard]] auto is_valid() const noexcept -> bool;
110
114 void clear() noexcept;
115
121 [[nodiscard]] auto operator==(const quic_keys& other) const noexcept -> bool;
122
126 [[nodiscard]] auto operator!=(const quic_keys& other) const noexcept -> bool;
127};
128
134{
137
141 [[nodiscard]] auto is_valid() const noexcept -> bool;
142
146 void clear() noexcept;
147};
148
149} // namespace kcenon::network::protocols::quic
auto encryption_level_to_string(encryption_level level) -> std::string
Convert encryption level to string for debugging.
Definition keys.cpp:13
constexpr size_t aes_256_key_size
AES-256-GCM key size in bytes.
Definition keys.h:22
constexpr size_t secret_size
Traffic secret size (SHA-256 output)
Definition keys.h:31
constexpr size_t aead_tag_size
AEAD authentication tag size in bytes.
Definition keys.h:28
constexpr size_t hp_sample_size
Header protection sample size.
Definition keys.h:37
constexpr size_t aes_128_key_size
AES-128-GCM key size in bytes.
Definition keys.h:19
encryption_level
QUIC encryption levels (RFC 9001 Section 4)
Definition keys.h:54
@ application
1-RTT application data encryption
constexpr auto encryption_level_count() noexcept -> size_t
Get the encryption level count.
Definition keys.h:72
constexpr size_t aead_iv_size
AEAD IV/nonce size in bytes.
Definition keys.h:25
constexpr size_t hp_key_size
Header protection key size for AES-128.
Definition keys.h:34
A pair of read and write keys for bidirectional communication.
Definition keys.h:134
quic_keys read
Keys for decrypting received packets.
Definition keys.h:135
quic_keys write
Keys for encrypting outgoing packets.
Definition keys.h:136
QUIC encryption keys for a single encryption level (RFC 9001 Section 5)
Definition keys.h:92
auto is_valid() const noexcept -> bool
Check if keys are initialized (non-zero)
Definition keys.cpp:30
std::array< uint8_t, hp_key_size > hp_key
Header protection key.
Definition keys.h:103
void clear() noexcept
Clear all key material securely.
Definition keys.cpp:36
std::array< uint8_t, aes_128_key_size > key
AEAD encryption key (AES-128-GCM by default)
Definition keys.h:97
std::array< uint8_t, secret_size > secret
Traffic secret (used for key updates)
Definition keys.h:94
std::array< uint8_t, aead_iv_size > iv
AEAD initialization vector.
Definition keys.h:100