Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
crypto.h File Reference

Declarations for cryptography functions. More...

#include <array>
#include <list>
#include <openssl/evp.h>
#include <openssl/rand.h>
#include <openssl/sha.h>
#include <openssl/x509.h>
#include <nlohmann/json.hpp>
#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

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

Typedefs

using crypto::sha256_t = std::array<std::uint8_t, SHA256_DIGEST_LENGTH>
using crypto::aes_t = std::vector<std::uint8_t>
using crypto::x509_t = util::safe_ptr<X509, X509_free>
using crypto::x509_store_t = util::safe_ptr<X509_STORE, X509_STORE_free>
using crypto::x509_store_ctx_t = util::safe_ptr<X509_STORE_CTX, X509_STORE_CTX_free>
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::bio_t = util::safe_ptr<BIO, BIO_free_all>
using crypto::pkey_t = util::safe_ptr<EVP_PKEY, EVP_PKEY_free>
using crypto::pkey_ctx_t = util::safe_ptr<EVP_PKEY_CTX, EVP_PKEY_CTX_free>
using crypto::bignum_t = util::safe_ptr<BIGNUM, BN_free>
using crypto::p_named_cert_t = std::shared_ptr<named_cert_t>

Enumerations

enum class  crypto::PERM : uint32_t {
  _reserved = 1 , _input = _reserved << 8 , input_controller = _input << 0 , input_touch = _input << 1 ,
  input_pen = _input << 2 , input_mouse = _input << 3 , input_kbd = _input << 4 , _all_inputs = input_controller | input_touch | input_pen | input_mouse | input_kbd ,
  _operation = _input << 8 , clipboard_set = _operation << 0 , clipboard_read = _operation << 1 , file_upload = _operation << 2 ,
  file_dwnload = _operation << 3 , server_cmd = _operation << 4 , _all_opeiations = clipboard_set | clipboard_read | file_upload | file_dwnload | server_cmd , _action = _operation << 8 ,
  list = _action << 0 , view = _action << 1 , launch = _action << 2 , _allow_view = view | launch ,
  _all_actions = list | view | launch , _default = view | list , _no = 0 , _all = _all_inputs | _all_opeiations | _all_actions
}
 The permissions of a client. More...

Functions

void crypto::md_ctx_destroy (EVP_MD_CTX *ctx)
constexpr PERM crypto::operator& (PERM x, PERM y)
constexpr bool crypto::operator! (PERM p)
sha256_t crypto::hash (const std::string_view &plaintext)
 Hashes the given plaintext using SHA-256.
aes_t crypto::gen_aes_key (const std::array< uint8_t, 16 > &salt, const std::string_view &pin)
x509_t crypto::x509 (const std::string_view &x)
pkey_t crypto::pkey (const std::string_view &k)
std::string crypto::pem (x509_t &x509)
std::string crypto::pem (pkey_t &pkey)
std::vector< uint8_t > crypto::sign256 (const pkey_t &pkey, const std::string_view &data)
bool crypto::verify256 (const x509_t &x509, const std::string_view &data, const std::string_view &signature)
creds_t crypto::gen_creds (const std::string_view &cn, std::uint32_t key_bits)
std::string_view crypto::signature (const x509_t &x)
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)

Variables

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

Detailed Description

Declarations for cryptography functions.

Definition in file crypto.h.

Typedef Documentation

◆ aes_t

using crypto::aes_t = std::vector<std::uint8_t>

Definition at line 31 of file crypto.h.

◆ bignum_t

using crypto::bignum_t = util::safe_ptr<BIGNUM, BN_free>

Definition at line 40 of file crypto.h.

◆ bio_t

using crypto::bio_t = util::safe_ptr<BIO, BIO_free_all>

Definition at line 37 of file crypto.h.

◆ cipher_ctx_t

using crypto::cipher_ctx_t = util::safe_ptr<EVP_CIPHER_CTX, EVP_CIPHER_CTX_free>

Definition at line 35 of file crypto.h.

◆ md_ctx_t

using crypto::md_ctx_t = util::safe_ptr<EVP_MD_CTX, md_ctx_destroy>

Definition at line 36 of file crypto.h.

◆ p_named_cert_t

using crypto::p_named_cert_t = std::shared_ptr<named_cert_t>

Definition at line 112 of file crypto.h.

◆ pkey_ctx_t

using crypto::pkey_ctx_t = util::safe_ptr<EVP_PKEY_CTX, EVP_PKEY_CTX_free>

Definition at line 39 of file crypto.h.

◆ pkey_t

using crypto::pkey_t = util::safe_ptr<EVP_PKEY, EVP_PKEY_free>

Definition at line 38 of file crypto.h.

◆ sha256_t

using crypto::sha256_t = std::array<std::uint8_t, SHA256_DIGEST_LENGTH>

Definition at line 29 of file crypto.h.

◆ x509_store_ctx_t

using crypto::x509_store_ctx_t = util::safe_ptr<X509_STORE_CTX, X509_STORE_CTX_free>

Definition at line 34 of file crypto.h.

◆ x509_store_t

using crypto::x509_store_t = util::safe_ptr<X509_STORE, X509_STORE_free>

Definition at line 33 of file crypto.h.

◆ x509_t

using crypto::x509_t = util::safe_ptr<X509, X509_free>

Definition at line 32 of file crypto.h.

Enumeration Type Documentation

◆ PERM

enum class crypto::PERM : uint32_t
strong

The permissions of a client.

Definition at line 45 of file crypto.h.

Function Documentation

◆ gen_aes_key()

aes_t crypto::gen_aes_key ( const std::array< uint8_t, 16 > & salt,
const std::string_view & pin )

Definition at line 348 of file crypto.cpp.

◆ gen_creds()

creds_t crypto::gen_creds ( const std::string_view & cn,
std::uint32_t key_bits )

Definition at line 459 of file crypto.cpp.

◆ 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.

Definition at line 364 of file crypto.cpp.

◆ md_ctx_destroy()

void crypto::md_ctx_destroy ( EVP_MD_CTX * ctx)

Definition at line 533 of file crypto.cpp.

◆ operator!()

bool crypto::operator! ( PERM p)
inlineconstexpr

Definition at line 82 of file crypto.h.

◆ operator&()

PERM crypto::operator& ( PERM x,
PERM y )
inlineconstexpr

Definition at line 77 of file crypto.h.

◆ pem() [1/2]

std::string crypto::pem ( pkey_t & pkey)

Definition at line 402 of file crypto.cpp.

◆ pem() [2/2]

std::string crypto::pem ( x509_t & x509)

Definition at line 392 of file crypto.cpp.

◆ pkey()

pkey_t crypto::pkey ( const std::string_view & k)

Definition at line 381 of file crypto.cpp.

◆ rand()

std::string crypto::rand ( std::size_t bytes)

Definition at line 426 of file crypto.cpp.

◆ rand_alphabet()

std::string crypto::rand_alphabet ( std::size_t bytes,
const std::string_view & alphabet )

Definition at line 537 of file crypto.cpp.

◆ round_to_pkcs7_padded()

std::size_t crypto::cipher::round_to_pkcs7_padded ( std::size_t size)
constexpr

Definition at line 155 of file crypto.h.

◆ sign256()

std::vector< uint8_t > crypto::sign256 ( const pkey_t & pkey,
const std::string_view & data )

Definition at line 505 of file crypto.cpp.

◆ signature()

std::string_view crypto::signature ( const x509_t & x)

Definition at line 412 of file crypto.cpp.

◆ verify256()

bool crypto::verify256 ( const x509_t & x509,
const std::string_view & data,
const std::string_view & signature )

Definition at line 529 of file crypto.cpp.

◆ x509()

x509_t crypto::x509 ( const std::string_view & x)

Definition at line 370 of file crypto.cpp.

Variable Documentation

◆ tag_size

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

Definition at line 153 of file crypto.h.