calog/libs/calogCrypto.h
2026-09-12 01:20:52 -05:00

30 lines
1.5 KiB
C

// calogCrypto.h -- calog cryptography library.
//
// Bridges binary-safe calog strings to OpenSSL's one-shot primitives, so any engine gets
// hashing, HMAC, randomness, and common encodings without an engine-specific library:
// cryptoHashSha256(data) -> lowercase hex digest (64 chars)
// cryptoHashSha1(data) -> lowercase hex digest (40 chars)
// cryptoHmacSha256(key, data) -> lowercase hex HMAC-SHA-256 (64 chars)
// cryptoRandomBytes(count) -> binary string of count cryptographically-random bytes
// cryptoBase64Encode(data) -> base64 text
// cryptoBase64Decode(text) -> decoded binary string
// cryptoHexEncode(data) -> lowercase hex text
// cryptoHexDecode(hexText) -> decoded binary string
// cryptoUuid() -> random RFC 4122 version-4 UUID string
// cryptoPbkdf2(password, salt, iterations, length)
// -> lowercase hex PBKDF2-HMAC-SHA256 key of length bytes
// cryptoEquals(a, b) -> whether two strings match, compared in constant time
// All natives are binary-safe and INLINE (pure computation over OpenSSL one-shots, no shared
// state), so there is nothing to shut down. Inline also means a slow one -- cryptoPbkdf2 is
// meant to be slow -- costs the calling script's thread rather than the host's.
#ifndef CALOG_CRYPTO_H
#define CALOG_CRYPTO_H
#include "calog.h"
// Register the crypto natives on a runtime. Stateless: safe to call on any number of
// runtimes, and there is no matching shutdown.
int32_t calogCryptoRegister(CalogT *calog);
#endif