Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
crypto_aes_cbc_hmac.h
1#ifndef SOURCEMETA_CORE_CRYPTO_AES_CBC_HMAC_H_
2#define SOURCEMETA_CORE_CRYPTO_AES_CBC_HMAC_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 std::string::size_type tag_length;
24
26 [[nodiscard]] auto ciphertext() const -> std::string_view {
27 assert(this->data.size() >= this->tag_length);
28 return std::string_view{this->data}.substr(0, this->data.size() -
29 this->tag_length);
30 }
31
33 [[nodiscard]] auto tag() const -> std::string_view {
34 assert(this->data.size() >= this->tag_length);
35 return std::string_view{this->data}.substr(this->data.size() -
36 this->tag_length);
37 }
38};
39
57auto SOURCEMETA_CORE_CRYPTO_EXPORT aes_cbc_hmac_encrypt(
58 const std::string_view key, const std::string_view iv,
59 const std::string_view associated_data, const std::string_view plaintext)
60 -> std::optional<AESCBCHMACCiphertext>;
61
80auto SOURCEMETA_CORE_CRYPTO_EXPORT aes_cbc_hmac_decrypt(
81 const std::string_view key, const std::string_view iv,
82 const std::string_view associated_data, const std::string_view ciphertext,
83 const std::string_view tag) -> std::optional<std::string>;
84
85} // namespace sourcemeta::core
86
87#endif
std::string::size_type tag_length
The length in bytes of the trailing authentication tag.
Definition crypto_aes_cbc_hmac.h:23
auto ciphertext() const -> std::string_view
The ciphertext, a whole number of 16-byte blocks.
Definition crypto_aes_cbc_hmac.h:26
auto tag() const -> std::string_view
The authentication tag.
Definition crypto_aes_cbc_hmac.h:33
std::string data
The ciphertext followed by its authentication tag.
Definition crypto_aes_cbc_hmac.h:20
auto SOURCEMETA_CORE_CRYPTO_EXPORT aes_cbc_hmac_encrypt(const std::string_view key, const std::string_view iv, const std::string_view associated_data, const std::string_view plaintext) -> std::optional< AESCBCHMACCiphertext >
auto SOURCEMETA_CORE_CRYPTO_EXPORT aes_cbc_hmac_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 >
Definition crypto_aes_cbc_hmac.h:18