8#include <openssl/evp.h>
9#include <openssl/rand.h>
10#include <openssl/sha.h>
11#include <openssl/x509.h>
22 md_ctx_destroy(EVP_MD_CTX *);
24 using sha256_t = std::array<std::uint8_t, SHA256_DIGEST_LENGTH>;
26 using aes_t = std::vector<std::uint8_t>;
43 hash(
const std::string_view &plaintext);
46 gen_aes_key(
const std::array<uint8_t, 16> &salt,
const std::string_view &pin);
49 x509(
const std::string_view &x);
51 pkey(
const std::string_view &k);
58 sign256(
const pkey_t &pkey,
const std::string_view &data);
60 verify256(
const x509_t &x509,
const std::string_view &data,
const std::string_view &signature);
63 gen_creds(
const std::string_view &cn, std::uint32_t key_bits);
66 signature(
const x509_t &x);
69 rand(std::size_t bytes);
71 rand_alphabet(std::size_t bytes,
72 const std::string_view &alphabet = std::string_view {
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!%&()=-" });
85 verify(x509_t::element_type *cert);
88 std::vector<std::pair<x509_t, x509_store_t>> _certs;
93 constexpr std::size_t tag_size = 16;
95 round_to_pkcs7_padded(std::size_t size) {
96 return ((size + 15) / 16) * 16;
114 operator=(
ecb_t &&)
noexcept =
default;
116 ecb_t(
const aes_t &key,
bool padding =
true);
119 encrypt(
const std::string_view &plaintext, std::vector<std::uint8_t> &cipher);
121 decrypt(
const std::string_view &cipher, std::vector<std::uint8_t> &plaintext);
129 operator=(
gcm_t &&)
noexcept =
default;
131 gcm_t(
const crypto::aes_t &key,
bool padding =
true);
142 encrypt(
const std::string_view &plaintext, std::uint8_t *tag, std::uint8_t *ciphertext, aes_t *iv);
153 encrypt(
const std::string_view &plaintext, std::uint8_t *tagged_cipher, aes_t *iv);
156 decrypt(
const std::string_view &cipher, std::vector<std::uint8_t> &plaintext, aes_t *iv);
164 operator=(
cbc_t &&)
noexcept =
default;
166 cbc_t(
const crypto::aes_t &key,
bool padding =
true);
177 encrypt(
const std::string_view &plaintext, std::uint8_t *cipher, aes_t *iv);
const char * verify(x509_t::element_type *cert)
Verify the certificate chain. When certificates from two or more instances of Moonlight have been add...
Definition crypto.cpp:56
int encrypt(const std::string_view &plaintext, std::uint8_t *cipher, aes_t *iv)
Encrypts the plaintext using AES CBC mode. length of cipher must be at least: round_to_pkcs7_padded(p...
Definition crypto.cpp:288
int encrypt(const std::string_view &plaintext, std::uint8_t *tag, std::uint8_t *ciphertext, aes_t *iv)
Encrypts the plaintext using AES GCM mode.
Definition crypto.cpp:189
sha256_t hash(const std::string_view &plaintext)
Hashes the given plaintext using SHA-256.
Definition crypto.cpp:342
Declarations for utility functions.