18#ifndef TRINITY_CRYPTO_GENERICS_HPP
19#define TRINITY_CRYPTO_GENERICS_HPP
32 template <
typename Cipher>
35 typename Cipher::IV iv;
40 template <
typename Container>
41 static void AppendToBack(std::vector<uint8>& data, Container
const& tail)
43 data.insert(data.end(), std::begin(tail), std::end(tail));
46 template <
typename Container>
50 for (
size_t i = 1, N =
std::size(tail); i <= N; ++i)
52 tail[N - i] = data.back();
61 template <
typename Cipher>
64 using IV =
typename Cipher::IV;
65 using Tag =
typename Cipher::Tag;
67 IV iv = Trinity::Impl::CryptoGenericsImpl::GenerateRandomIV<Cipher>();
73 bool success = cipher.Process(iv, data.data(), data.size(), tag);
81 template <
typename Cipher>
84 AEEncryptWithRandomIV<Cipher>(data, key.
ToByteArray<Cipher::KEY_SIZE_BYTES>());
87 template <
typename Cipher>
88 bool AEDecrypt(std::vector<uint8>& data,
typename Cipher::Key
const& key)
90 using IV =
typename Cipher::IV;
91 using Tag =
typename Cipher::Tag;
101 return cipher.Process(iv, data.data(), data.size(), tag);
104 template <
typename Cipher>
107 return AEDecrypt<Cipher>(data, key.
ToByteArray<Cipher::KEY_SIZE_BYTES>());
std::array< uint8, Size > ToByteArray(bool littleEndian=true) const
void AEEncryptWithRandomIV(std::vector< uint8 > &data, typename Cipher::Key const &key)
void TC_COMMON_API GetRandomBytes(uint8 *buf, size_t len)
bool AEDecrypt(std::vector< uint8 > &data, typename Cipher::Key const &key)
constexpr std::size_t size()
static Cipher::IV GenerateRandomIV()
static void SplitFromBack(std::vector< uint8 > &data, Container &tail)
static void AppendToBack(std::vector< uint8 > &data, Container const &tail)