StormByte-Crypto 3.1.0
C++26 cryptography module of the StormByte suite
Loading...
Searching...
No Matches
policy.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Crypto.
5 *
6 * StormByte-Crypto original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Crypto source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, in particular Crypto++, bundled libbzip2, the StormByte-Buffer
23 * tree and the StormByte suite it vendors), which remains under its own license.
24 *
25 * Neither license grants any patent rights. Any patent licenses required
26 * to use this software or third-party components must be obtained separately
27 * from the patent holders.
28 *
29 * StormByte-Crypto is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU Lesser General Public License for more details.
33 *
34 * You should have received a copy of the GNU Lesser General Public License
35 * version 3 along with StormByte-Crypto. If not, see
36 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
37 *
38 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
39 */
40
41#pragma once
42
46#include <StormByte/expected.hxx>
47#include <StormByte/safe/pointers.hxx>
48#include <StormByte/safe/vector.hxx>
49
50#include <cstdint>
51
56namespace StormByte {
61 namespace Crypto {
66 namespace TLS {
71 enum class Version: std::uint16_t {
72 TLS13 = 0x0304
73 };
74
79 enum class CipherSuite: std::uint16_t {
82 };
83
88 enum class Group: std::uint16_t {
89 X25519 = 0x001d,
90 Secp256r1 = 0x0017
91 };
92
97 enum class SignatureScheme: std::uint16_t {
100 };
101
118
189
199 }
200 }
201}
202
205
210namespace StormByte {
215 namespace Crypto {
220 namespace TLS {
224 class Policy;
225
230
235
246
255
263
279 public:
285
290 Policy(const Policy& other);
291
296 Policy(Policy&& other) noexcept;
297
301 ~Policy() noexcept;
302
308 Policy& operator=(const Policy& other);
309
315 Policy& operator=(Policy&& other) noexcept;
316
321 const Configuration& Preferences() const noexcept;
322
323 private:
329 explicit Policy(const Configuration& configuration);
330
337 friend ExpectedPolicy Validate(const Configuration& configuration);
338
339 StormByte::Safe::Shared<const Configuration> m_configuration;
340 };
341 }
342 }
343}
344
friend ExpectedPolicy Validate(const Configuration &configuration)
Permit snapshot construction only after designated-profile validation.
Policy(Policy &&other) noexcept
Retain the immutable snapshot without invalidating the source.
Policy(const Policy &other)
Share the immutable validated snapshot.
~Policy() noexcept
Release this snapshot reference; the last owner releases Base storage.
Policy()
Construct the validated default TLS 1.3 profile.
const Configuration & Preferences() const noexcept
Read the exact validated preferences; no mutable access.
STORMBYTE_DECLARE_MAYBE_SAFE(class StormByte::System::Device::Access)
Algorithm
Supported raw-key authenticated encryption algorithms.
Definition aead.hxx:57
Algorithm
Supported HKDF hash functions.
Definition hkdf.hxx:54
TLS 1.3 policy and buffer-driven session engine.
CipherSuite
TLS 1.3 suites supported by the buffer-driven session engine.
Definition policy.hxx:79
@ TLS_AES_256_GCM_SHA384
AES-256-GCM with SHA-384 transcript and HKDF.
Definition policy.hxx:81
@ TLS_AES_128_GCM_SHA256
AES-128-GCM with SHA-256 transcript and HKDF.
Definition policy.hxx:80
Version
Protocol versions designated for policy configuration.
Definition policy.hxx:71
@ TLS13
TLS 1.3 supported_versions identifier, not the record legacy version.
Definition policy.hxx:72
ExpectedCipherSuiteDefinition DescribeCipherSuite(CipherSuite suite)
Describe a registered suite's fixed AEAD and HKDF/transcript hash.
Error
Configuration failures; no connection or backend is exercised.
Definition policy.hxx:106
@ EmptyCipherSuites
No allowed cipher suite was specified.
Definition policy.hxx:108
@ UnsupportedVersion
Version is not exactly TLS 1.3.
Definition policy.hxx:107
@ EmptySignatureSchemes
No allowed signature scheme was specified.
Definition policy.hxx:114
@ DuplicateCipherSuite
A suite appears more than once.
Definition policy.hxx:110
@ EmptyGroups
No allowed group was specified.
Definition policy.hxx:111
@ DuplicateSignatureScheme
A scheme appears more than once.
Definition policy.hxx:116
@ DuplicateGroup
A group appears more than once.
Definition policy.hxx:113
@ UnsupportedGroup
A group is outside the designated initial profile.
Definition policy.hxx:112
@ UnsupportedCipherSuite
A suite is outside the designated initial profile.
Definition policy.hxx:109
@ UnsupportedSignatureScheme
A scheme is outside the supported TLS 1.3 profile.
Definition policy.hxx:115
Group
Named groups supported by the initial TLS 1.3 profile.
Definition policy.hxx:88
@ Secp256r1
NIST P-256 key agreement.
Definition policy.hxx:90
@ X25519
Curve25519 key agreement.
Definition policy.hxx:89
StormByte::Expected< Policy, Error > ExpectedPolicy
Validated policy or Base-owned typed configuration error.
Definition policy.hxx:229
SignatureScheme
TLS 1.3 signature schemes supported by the session engine.
Definition policy.hxx:97
@ ECDSA_SECP256R1_SHA256
P-256 ECDSA/SHA-256.
Definition policy.hxx:98
@ RSA_PSS_RSAE_SHA256
RSA-PSS/SHA-256 with an rsaEncryption certificate key.
Definition policy.hxx:99
StormByte::Expected< CipherSuiteDefinition, Error > ExpectedCipherSuiteDefinition
Fixed suite definition or Base-owned unsupported-suite error.
Definition policy.hxx:234
ExpectedPolicy Validate(const Configuration &configuration)
Validate only membership, nonempty lists and uniqueness for the profile.
Configuration InitialProfile()
All designated initial-profile entries in default preference order.
Crypto module of the StormByte suite.
Definition aead.hxx:53
Root namespace of the StormByte suite.
std::conditional_t< Type::Reference< T >, std::expected< std::reference_wrapper< std::remove_reference_t< T > >, Safe::Shared< E > >, std::expected< T, Safe::Shared< E > > > Expected
Fixed primitive mapping, not an independently selectable pair.
Definition policy.hxx:194
HKDF::Algorithm hash
Inseparable HKDF and TLS transcript hash designation.
Definition policy.hxx:197
AEAD::Algorithm aead
Raw-key authenticated encryption primitive.
Definition policy.hxx:195
Mutable input with independent ordered preference lists.
Definition policy.hxx:128
~Configuration() noexcept=default
Release the Base-owned preference lists.
StormByte::Safe::Vector< CipherSuite > cipher_suites
Allowed suites in descending preference order.
Definition policy.hxx:173
StormByte::Safe::Vector< Group > groups
Allowed groups in descending preference order, independent of suites.
Definition policy.hxx:180
StormByte::Safe::Vector< SignatureScheme > signature_schemes
Allowed signature schemes in descending preference order.
Definition policy.hxx:185
Configuration(const Configuration &other)=default
Independently copy the mutable preference lists.
Configuration()=default
Construct the mutable default TLS 1.3 profile.
Configuration(Configuration &&other) noexcept=default
Transfer the mutable lists, leaving the source lists empty.
Version version
Only TLS 1.3 is accepted.
Definition policy.hxx:168
#define STORMBYTE_CRYPTO_PUBLIC
Definition visibility.h:53