Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
crypto.hpp File Reference
#include <string>
#include <string_view>
#include <vector>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <optional>

Go to the source code of this file.

Classes

struct  pulp::runtime::GcmOutput
 Output of AES-GCM encryption: ciphertext + 16-byte authentication tag. More...
struct  pulp::runtime::Ed25519KeyPair
 Ed25519 keypair (NaCl convention: secret key contains seed || public key). More...
struct  pulp::runtime::X25519KeyPair
 X25519 keypair. More...

Namespaces

namespace  pulp
namespace  pulp::runtime

Functions

std::optional< std::vector< uint8_t > > pulp::runtime::secure_random_bytes (size_t size)
 Generate bytes from the runtime's entropy-seeded CTR-DRBG.
void pulp::runtime::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 containing object is destroyed.
std::string pulp::runtime::hex_encode (const uint8_t *data, size_t size)
 Lowercase-hex encode raw bytes.
std::string pulp::runtime::hex_encode (const std::vector< uint8_t > &bytes)
std::vector< uint8_t > pulp::runtime::sha256 (const uint8_t *data, size_t size)
 Compute SHA-256 hash.
std::vector< uint8_t > pulp::runtime::sha256 (std::string_view data)
std::string pulp::runtime::sha256_hex (const uint8_t *data, size_t size)
 Compute SHA-256 hash as hex string (64 chars).
std::string pulp::runtime::sha256_hex (std::string_view data)
std::optional< std::string > pulp::runtime::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::vector< uint8_t > pulp::runtime::sha1 (const uint8_t *data, size_t size)
 Compute SHA-1 hash.
std::vector< uint8_t > pulp::runtime::sha1 (std::string_view data)
std::vector< uint8_t > pulp::runtime::md5 (const uint8_t *data, size_t size)
 Compute MD5 hash. Returns 16-byte digest. (Legacy use only.).
std::vector< uint8_t > pulp::runtime::md5 (std::string_view data)
std::string pulp::runtime::md5_hex (std::string_view data)
 Compute MD5 hash as hex string (32 chars).
std::optional< std::vector< uint8_t > > pulp::runtime::aes_encrypt (const uint8_t *plaintext, size_t size, const uint8_t *key_32, const uint8_t *iv_16)
 AES-256-CBC encrypt.
std::optional< std::vector< uint8_t > > pulp::runtime::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::optional< std::vector< uint8_t > > pulp::runtime::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 > > pulp::runtime::hmac_sha256 (std::string_view key, std::string_view data)
std::optional< std::vector< uint8_t > > pulp::runtime::hmac_sha1 (const uint8_t *key, size_t key_size, const uint8_t *data, size_t data_size)
 Compute HMAC-SHA1(key, data).
std::optional< GcmOutput > pulp::runtime::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< std::vector< uint8_t > > pulp::runtime::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.
bool pulp::runtime::constant_time_equal (const uint8_t *a, const uint8_t *b, size_t size)
 Constant-time byte comparison.
std::optional< Ed25519KeyPair > pulp::runtime::ed25519_keypair_generate ()
 Generate a fresh Ed25519 keypair using mbedTLS CTR-DRBG for entropy.
std::optional< Ed25519KeyPair > pulp::runtime::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 > > pulp::runtime::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).
bool pulp::runtime::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.
std::optional< X25519KeyPair > pulp::runtime::x25519_keypair_generate ()
 Generate a fresh X25519 keypair using mbedTLS CTR-DRBG for entropy.
std::optional< X25519KeyPair > pulp::runtime::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::vector< uint8_t > > pulp::runtime::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.
std::string pulp::runtime::machine_id ()
 Generate a machine-specific fingerprint (deterministic per machine).

Variables

constexpr size_t pulp::runtime::ed25519_public_key_size = 32
 Ed25519 key sizes (RFC 8032 §5.1).
constexpr size_t pulp::runtime::ed25519_private_key_size = 64
constexpr size_t pulp::runtime::ed25519_seed_size = 32
constexpr size_t pulp::runtime::ed25519_signature_size = 64
constexpr size_t pulp::runtime::x25519_public_key_size = 32
 X25519 key and output sizes (RFC 7748 §5).
constexpr size_t pulp::runtime::x25519_private_key_size = 32
constexpr size_t pulp::runtime::x25519_shared_secret_size = 32