32inline std::string
hex_encode(
const uint8_t* data,
size_t size) {
33 static const char* d =
"0123456789abcdef";
35 out.reserve(size * 2);
36 for (
size_t i = 0; i < size; ++i) {
37 out.push_back(d[data[i] >> 4]);
38 out.push_back(d[data[i] & 0xF]);
42inline std::string
hex_encode(
const std::vector<uint8_t>& bytes) {
54std::vector<uint8_t>
sha256(
const uint8_t* data,
size_t size);
55std::vector<uint8_t>
sha256(std::string_view data);
64 std::uint64_t max_bytes);
68std::vector<uint8_t>
sha1(
const uint8_t* data,
size_t size);
69std::vector<uint8_t>
sha1(std::string_view data);
72std::vector<uint8_t>
md5(
const uint8_t* data,
size_t size);
73std::vector<uint8_t>
md5(std::string_view data);
76std::string
md5_hex(std::string_view data);
83 const uint8_t* plaintext,
size_t size,
84 const uint8_t* key_32,
const uint8_t* iv_16);
88 const uint8_t* ciphertext,
size_t size,
89 const uint8_t* key_32,
const uint8_t* iv_16);
98 const uint8_t* key,
size_t key_size,
99 const uint8_t* data,
size_t data_size);
100std::optional<std::vector<uint8_t>>
hmac_sha256(std::string_view key,
101 std::string_view data);
108 const uint8_t* key,
size_t key_size,
109 const uint8_t* data,
size_t data_size);
124 const uint8_t* plaintext,
size_t plaintext_size,
125 const uint8_t* key_32,
126 const uint8_t* iv_12,
size_t iv_size,
127 const uint8_t* aad,
size_t aad_size);
135 const uint8_t* ciphertext,
size_t ciphertext_size,
136 const uint8_t* key_32,
137 const uint8_t* iv_12,
size_t iv_size,
138 const uint8_t* aad,
size_t aad_size,
139 const uint8_t* tag_16);
178 const uint8_t* seed_32,
size_t seed_size);
184 const uint8_t* private_key_64,
size_t private_key_size,
185 const uint8_t* message,
size_t message_size);
191 const uint8_t* public_key_32,
size_t public_key_size,
192 const uint8_t* signature_64,
size_t signature_size,
193 const uint8_t* message,
size_t message_size);
230 const uint8_t* private_key_32,
size_t private_key_size);
243 const uint8_t* private_key_32,
size_t private_key_size,
244 const uint8_t* peer_public_key_32,
size_t peer_public_key_size);
Definition generated_event_source.hpp:33
constexpr size_t x25519_shared_secret_size
Definition crypto.hpp:212
std::vector< uint8_t > md5(const uint8_t *data, size_t size)
Compute MD5 hash. Returns 16-byte digest. (Legacy use only.).
std::optional< X25519KeyPair > x25519_keypair_generate()
Generate a fresh X25519 keypair using mbedTLS CTR-DRBG for entropy.
constexpr size_t x25519_public_key_size
X25519 key and output sizes (RFC 7748 §5).
Definition crypto.hpp:210
std::optional< std::vector< uint8_t > > ed25519_sign(const uint8_t *private_key_64, size_t private_key_size, const uint8_t *message, size_t message_size)
Sign a message with an Ed25519 private key (64-byte NaCl-form).
std::optional< std::vector< uint8_t > > hmac_sha1(const uint8_t *key, size_t key_size, const uint8_t *data, size_t data_size)
Compute HMAC-SHA1(key, data).
std::string sha256_hex(const uint8_t *data, size_t size)
Compute SHA-256 hash as hex string (64 chars).
std::optional< std::vector< uint8_t > > aes_decrypt(const uint8_t *ciphertext, size_t size, const uint8_t *key_32, const uint8_t *iv_16)
AES-256-CBC decrypt. Returns plaintext (PKCS7 unpadded).
std::string hex_encode(const uint8_t *data, size_t size)
Lowercase-hex encode raw bytes.
Definition crypto.hpp:32
bool constant_time_equal(const uint8_t *a, const uint8_t *b, size_t size)
Constant-time byte comparison.
std::optional< Ed25519KeyPair > ed25519_keypair_generate()
Generate a fresh Ed25519 keypair using mbedTLS CTR-DRBG for entropy.
std::optional< std::vector< uint8_t > > hmac_sha256(const uint8_t *key, size_t key_size, const uint8_t *data, size_t data_size)
Compute HMAC-SHA256(key, data).
std::optional< std::vector< uint8_t > > aes_gcm_decrypt(const uint8_t *ciphertext, size_t ciphertext_size, const uint8_t *key_32, const uint8_t *iv_12, size_t iv_size, const uint8_t *aad, size_t aad_size, const uint8_t *tag_16)
AES-256-GCM decrypt + verify the 16-byte tag.
std::optional< std::vector< uint8_t > > aes_encrypt(const uint8_t *plaintext, size_t size, const uint8_t *key_32, const uint8_t *iv_16)
AES-256-CBC encrypt.
constexpr size_t ed25519_seed_size
Definition crypto.hpp:161
void secure_zero_memory(void *data, size_t size) noexcept
Overwrite sensitive bytes through volatile stores so the wipe is not removed as a dead store when the...
std::string machine_id()
Generate a machine-specific fingerprint (deterministic per machine).
std::vector< uint8_t > sha1(const uint8_t *data, size_t size)
Compute SHA-1 hash.
constexpr size_t ed25519_private_key_size
Definition crypto.hpp:160
bool ed25519_verify(const uint8_t *public_key_32, size_t public_key_size, const uint8_t *signature_64, size_t signature_size, const uint8_t *message, size_t message_size)
Verify a 64-byte detached signature against a message + 32-byte public key.
constexpr size_t ed25519_public_key_size
Ed25519 key sizes (RFC 8032 §5.1).
Definition crypto.hpp:159
std::string md5_hex(std::string_view data)
Compute MD5 hash as hex string (32 chars).
std::vector< uint8_t > sha256(const uint8_t *data, size_t size)
Compute SHA-256 hash.
constexpr size_t ed25519_signature_size
Definition crypto.hpp:162
constexpr size_t x25519_private_key_size
Definition crypto.hpp:211
std::optional< std::vector< uint8_t > > secure_random_bytes(size_t size)
Generate bytes from the runtime's entropy-seeded CTR-DRBG.
std::optional< GcmOutput > aes_gcm_encrypt(const uint8_t *plaintext, size_t plaintext_size, const uint8_t *key_32, const uint8_t *iv_12, size_t iv_size, const uint8_t *aad, size_t aad_size)
AES-256-GCM encrypt with optional Additional Authenticated Data (AAD).
std::optional< X25519KeyPair > x25519_keypair_from_private_key(const uint8_t *private_key_32, size_t private_key_size)
Recover the public key for an existing 32-byte private scalar.
std::optional< std::string > sha256_file_hex(const std::filesystem::path &path, std::uint64_t max_bytes)
Stream a file through SHA-256 without retaining its contents in memory.
std::optional< Ed25519KeyPair > ed25519_keypair_from_seed(const uint8_t *seed_32, size_t seed_size)
Derive a deterministic Ed25519 keypair from a 32-byte seed.
std::optional< std::vector< uint8_t > > x25519_shared_secret(const uint8_t *private_key_32, size_t private_key_size, const uint8_t *peer_public_key_32, size_t peer_public_key_size)
Compute the raw X25519 shared secret between our private key and a peer's public key.
Ed25519 keypair (NaCl convention: secret key contains seed || public key).
Definition crypto.hpp:165
std::vector< uint8_t > public_key
32 bytes
Definition crypto.hpp:166
std::vector< uint8_t > private_key
64 bytes (seed || public_key)
Definition crypto.hpp:167
Output of AES-GCM encryption: ciphertext + 16-byte authentication tag.
Definition crypto.hpp:114
std::vector< uint8_t > ciphertext
Definition crypto.hpp:115
std::vector< uint8_t > tag
16 bytes
Definition crypto.hpp:116
X25519 keypair.
Definition crypto.hpp:216
std::vector< uint8_t > private_key
32 bytes
Definition crypto.hpp:218
std::vector< uint8_t > public_key
32 bytes
Definition crypto.hpp:217