Tanguv0.35.0
Security & crypto8 exports
Raw Markdown

/crypto

Cryptographic hashing (SHA-256), HMAC authentication, AES-GCM/AEAD helpers, CSPRNG tokens, and constant-time equality.

(use /crypto)

Functions & symbols#

hash-password#

function
(hash-password password [iterations]) -> String

Hashes `password` with a fresh random salt using PBKDF2-HMAC-SHA256 and returns an encoded PHC-style hash string.

ParameterTypeOptionalDescription
passwordStringrequiredPlaintext password
iterationsIntoptionalOptional PBKDF2-HMAC-SHA256 iteration count (default 600000)
Returns:Any
(let pw-hash (crypto/hash-password "hunter2"))

hmac-sha256#

function
(hmac-sha256 key message) -> String

Computes an HMAC-SHA256 authentication tag and returns a lowercase hex string.

ParameterTypeOptionalDescription
keyString | SlabrequiredSecret HMAC key
messageString | SlabrequiredMessage payload to authenticate
Returns:Any
(crypto/hmac-sha256 secret payload)

random-bytes#

function
(random-bytes count) -> Slab

Generates `count` cryptographically secure random bytes using the OS CSPRNG.

ParameterTypeOptionalDescription
countIntrequiredNumber of cryptographically secure bytes
Returns:Any
(let nonce (crypto/random-bytes 16))

random-hex#

function
(random-hex byte-count) -> String

Generates `byte_count` CSPRNG bytes formatted as a lowercase hex string (`2 * byte_count` chars).

ParameterTypeOptionalDescription
byte_countIntrequiredNumber of random bytes to generate before hex encoding
Returns:Any
(let token (crypto/random-hex 32))

random-urlsafe#

function
(random-urlsafe [byte-count]) -> String

Generates a URL-safe Base64 token (no padding) suitable for session IDs and CSRF nonces.

ParameterTypeOptionalDescription
byte_countIntoptionalOptional byte count (defaults to 32)
Returns:Any
(let csrf-token (crypto/random-urlsafe 32))

sha256#

function
(sha256 data) -> String

Computes the SHA-256 cryptographic digest and returns a 64-character lowercase hex string.

ParameterTypeOptionalDescription
dataString | SlabrequiredInput data to hash
Returns:Any
(crypto/sha256 "hello")

timing-safe-eq?#

function
(timing-safe-eq? a b) -> Bool

Compares two strings or byte Slabs in constant time to prevent timing side-channel attacks.

ParameterTypeOptionalDescription
aString | SlabrequiredFirst digest or secret
bString | SlabrequiredSecond digest or secret
Returns:Any
(crypto/timing-safe-eq? expected actual)

verify-password#

function
(verify-password password stored-hash) -> Bool

Verifies a plaintext password against a stored PBKDF2 hash in constant time.

ParameterTypeOptionalDescription
passwordStringrequiredCandidate plaintext password
stored_hashStringrequiredStored hash returned by `hash-password`
Returns:Any
(crypto/verify-password "hunter2" pw-hash)

Related modules