Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
crypto_aes_gcm.h
1#ifndef SOURCEMETA_CORE_CRYPTO_AES_GCM_H_
2#define SOURCEMETA_CORE_CRYPTO_AES_GCM_H_
3
4#ifndef SOURCEMETA_CORE_CRYPTO_EXPORT
5#include <sourcemeta/core/crypto_export.h>
6#endif
7
8#include <cassert> // assert
9#include <optional> // std::optional
10#include <string> // std::string
11#include <string_view> // std::string_view
12
13namespace sourcemeta::core {
14
20 std::string data;
21
23 [[nodiscard]] auto ciphertext() const -> std::string_view {
24 assert(this->data.size() >= 16);
25 return std::string_view{this->data}.substr(0, this->data.size() - 16);
26 }
27
29 [[nodiscard]] auto tag() const -> std::string_view {
30 assert(this->data.size() >= 16);
31 return std::string_view{this->data}.substr(this->data.size() - 16);
32 }
33};
34
49auto SOURCEMETA_CORE_CRYPTO_EXPORT aes_gcm_encrypt(
50 const std::string_view key, const std::string_view iv,
51 const std::string_view associated_data, const std::string_view plaintext)
52 -> std::optional<AESGCMCiphertext>;
53
70auto SOURCEMETA_CORE_CRYPTO_EXPORT aes_gcm_decrypt(
71 const std::string_view key, const std::string_view iv,
72 const std::string_view associated_data, const std::string_view ciphertext,
73 const std::string_view tag) -> std::optional<std::string>;
74
92auto SOURCEMETA_CORE_CRYPTO_EXPORT
93aes_256_gcm_seal(const std::string_view key, const std::string_view plaintext)
94 -> std::optional<std::string>;
95
110auto SOURCEMETA_CORE_CRYPTO_EXPORT
111aes_256_gcm_unseal(const std::string_view key, const std::string_view sealed)
112 -> std::optional<std::string>;
113
114} // namespace sourcemeta::core
115
116#endif
auto ciphertext() const -> std::string_view
The ciphertext, the same length as the plaintext.
Definition crypto_aes_gcm.h:23
std::string data
The ciphertext followed by its 16-byte authentication tag.
Definition crypto_aes_gcm.h:20
auto tag() const -> std::string_view
The 16-byte authentication tag.
Definition crypto_aes_gcm.h:29
auto SOURCEMETA_CORE_CRYPTO_EXPORT aes_256_gcm_unseal(const std::string_view key, const std::string_view sealed) -> std::optional< std::string >
auto SOURCEMETA_CORE_CRYPTO_EXPORT aes_gcm_encrypt(const std::string_view key, const std::string_view iv, const std::string_view associated_data, const std::string_view plaintext) -> std::optional< AESGCMCiphertext >
auto SOURCEMETA_CORE_CRYPTO_EXPORT aes_gcm_decrypt(const std::string_view key, const std::string_view iv, const std::string_view associated_data, const std::string_view ciphertext, const std::string_view tag) -> std::optional< std::string >
auto SOURCEMETA_CORE_CRYPTO_EXPORT aes_256_gcm_seal(const std::string_view key, const std::string_view plaintext) -> std::optional< std::string >
Definition crypto_aes_gcm.h:18