Sunshine latest
Self-hosted game stream host for Moonlight.
crypto.h File Reference

Declarations for cryptography functions. More...

#include <array>
#include <openssl/evp.h>
#include <openssl/rand.h>
#include <openssl/sha.h>
#include <openssl/x509.h>
#include "utility.h"
Include dependency graph for crypto.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  crypto::cipher::cbc_t
 
class  crypto::cert_chain_t
 
class  crypto::cipher::cipher_t
 
struct  crypto::creds_t
 
class  crypto::cipher::ecb_t
 
class  crypto::cipher::gcm_t
 

Typedefs

using crypto::aes_t = std::vector<std::uint8_t>
 
using crypto::bignum_t = util::safe_ptr<BIGNUM, BN_free>
 
using crypto::bio_t = util::safe_ptr<BIO, BIO_free_all>
 
using crypto::cipher_ctx_t = util::safe_ptr<EVP_CIPHER_CTX, EVP_CIPHER_CTX_free>
 
using crypto::md_ctx_t = util::safe_ptr<EVP_MD_CTX, md_ctx_destroy>
 
using crypto::pkey_ctx_t = util::safe_ptr<EVP_PKEY_CTX, EVP_PKEY_CTX_free>
 
using crypto::pkey_t = util::safe_ptr<EVP_PKEY, EVP_PKEY_free>
 
using crypto::sha256_t = std::array<std::uint8_t, SHA256_DIGEST_LENGTH>
 
using crypto::x509_store_ctx_t = util::safe_ptr<X509_STORE_CTX, X509_STORE_CTX_free>
 
using crypto::x509_store_t = util::safe_ptr<X509_STORE, X509_STORE_free>
 
using crypto::x509_t = util::safe_ptr<X509, X509_free>
 

Functions

aes_t crypto::gen_aes_key (const std::array< uint8_t, 16 > &salt, const std::string_view &pin)
 
creds_t crypto::gen_creds (const std::string_view &cn, std::uint32_t key_bits)
 
sha256_t crypto::hash (const std::string_view &plaintext)
 Hashes the given plaintext using SHA-256.
 
void crypto::md_ctx_destroy (EVP_MD_CTX *ctx)
 
std::string crypto::pem (pkey_t &pkey)
 
std::string crypto::pem (x509_t &x509)
 
pkey_t crypto::pkey (const std::string_view &k)
 
std::string crypto::rand (std::size_t bytes)
 
std::string crypto::rand_alphabet (std::size_t bytes, const std::string_view &alphabet)
 
constexpr std::size_t crypto::cipher::round_to_pkcs7_padded (std::size_t size)
 
std::vector< uint8_t > crypto::sign256 (const pkey_t &pkey, const std::string_view &data)
 
std::string_view crypto::signature (const x509_t &x)
 
bool crypto::verify256 (const x509_t &x509, const std::string_view &data, const std::string_view &signature)
 
x509_t crypto::x509 (const std::string_view &x)
 

Variables

constexpr std::size_t crypto::cipher::tag_size = 16
 

Detailed Description

Declarations for cryptography functions.

Function Documentation

◆ hash()

sha256_t crypto::hash ( const std::string_view & plaintext)

Hashes the given plaintext using SHA-256.

Parameters
plaintext
Returns
The SHA-256 hash of the plaintext.