StormByte-Crypto 3.1.0
C++26 cryptography module of the StormByte suite
Loading...
Searching...
No Matches
aead.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
45#include <StormByte/expected.hxx>
46#include <StormByte/safe/binary.hxx>
47#include <StormByte/safe/secure_binary.hxx>
48
49#include <cstddef>
50#include <cstdint>
51#include <span>
52
57 enum class Algorithm {
60 };
61
74
75 inline constexpr std::size_t NonceSize = 12;
76 inline constexpr std::size_t TagSize = 16;
77 inline constexpr std::uint64_t MaxMessageSize = (std::uint64_t{1} << 36) - 32;
78 inline constexpr std::uint64_t MaxAADSize = (std::uint64_t{1} << 61) - 1;
79
90}
91
93
97
111 Algorithm algorithm,
112 const Secure::Password& key,
113 std::span<const std::byte> nonce,
114 std::span<const std::byte> plaintext,
115 std::span<const std::byte> aad = {}
116 );
117
133 Algorithm algorithm,
134 const Secure::Password& key,
135 std::span<const std::byte> nonce,
136 std::span<const std::byte> ciphertext,
137 std::span<const std::byte> tag,
138 std::span<const std::byte> aad = {}
139 );
140}
Shared, wiped container for passwords and raw key material.
Definition password.hxx:108
STORMBYTE_DECLARE_MAYBE_SAFE(class StormByte::System::Device::Access)
Definition aead.hxx:53
ExpectedPlaintext Open(Algorithm algorithm, const Secure::Password &key, std::span< const std::byte > nonce, std::span< const std::byte > ciphertext, std::span< const std::byte > tag, std::span< const std::byte > aad={})
Authenticate the entire ciphertext before returning any plaintext.
ExpectedSealed Seal(Algorithm algorithm, const Secure::Password &key, std::span< const std::byte > nonce, std::span< const std::byte > plaintext, std::span< const std::byte > aad={})
Encrypt binary plaintext with a raw AES key and detached full tag.
StormByte::Expected< Sealed, Error > ExpectedSealed
Definition aead.hxx:95
Algorithm
Supported raw-key authenticated encryption algorithms.
Definition aead.hxx:57
@ AES128GCM
AES-GCM with an exactly 16-byte key.
Definition aead.hxx:58
@ AES256GCM
AES-GCM with an exactly 32-byte key.
Definition aead.hxx:59
constexpr std::uint64_t MaxMessageSize
GCM byte limit.
Definition aead.hxx:77
StormByte::Expected< StormByte::Safe::SecureBinary, Error > ExpectedPlaintext
Definition aead.hxx:96
constexpr std::uint64_t MaxAADSize
GCM AAD byte limit.
Definition aead.hxx:78
Error
Typed validation, authentication and backend failures.
Definition aead.hxx:65
@ BackendFailure
Definition aead.hxx:72
@ AuthenticationFailed
Definition aead.hxx:71
@ InvalidKeySize
Definition aead.hxx:67
@ InputTooLong
Definition aead.hxx:70
@ UnsupportedAlgorithm
Definition aead.hxx:66
@ InvalidNonceSize
Definition aead.hxx:68
@ InvalidTagSize
Definition aead.hxx:69
constexpr std::size_t TagSize
Only full 128-bit tags are accepted.
Definition aead.hxx:76
constexpr std::size_t NonceSize
Only 96-bit nonces are accepted.
Definition aead.hxx:75
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
Detached public ciphertext and full-length authentication tag.
Definition aead.hxx:86
StormByte::Safe::Binary tag
Definition aead.hxx:88
StormByte::Safe::Binary ciphertext
Definition aead.hxx:87
#define STORMBYTE_CRYPTO_PUBLIC
Definition visibility.h:53