/crypto
Cryptographic hashing (SHA-256), HMAC authentication, AES-GCM/AEAD helpers, CSPRNG tokens, and constant-time equality.
Functions & symbols#
hash-password#
Hashes `password` with a fresh random salt using PBKDF2-HMAC-SHA256 and returns an encoded PHC-style hash string.
| Parameter | Type | Optional | Description |
|---|---|---|---|
password | String | required | Plaintext password |
iterations | Int | optional | Optional PBKDF2-HMAC-SHA256 iteration count (default 600000) |
Any(let pw-hash (crypto/hash-password "hunter2"))hmac-sha256#
Computes an HMAC-SHA256 authentication tag and returns a lowercase hex string.
| Parameter | Type | Optional | Description |
|---|---|---|---|
key | String | Slab | required | Secret HMAC key |
message | String | Slab | required | Message payload to authenticate |
Any(crypto/hmac-sha256 secret payload)random-bytes#
Generates `count` cryptographically secure random bytes using the OS CSPRNG.
| Parameter | Type | Optional | Description |
|---|---|---|---|
count | Int | required | Number of cryptographically secure bytes |
Any(let nonce (crypto/random-bytes 16))random-hex#
Generates `byte_count` CSPRNG bytes formatted as a lowercase hex string (`2 * byte_count` chars).
| Parameter | Type | Optional | Description |
|---|---|---|---|
byte_count | Int | required | Number of random bytes to generate before hex encoding |
Any(let token (crypto/random-hex 32))random-urlsafe#
Generates a URL-safe Base64 token (no padding) suitable for session IDs and CSRF nonces.
| Parameter | Type | Optional | Description |
|---|---|---|---|
byte_count | Int | optional | Optional byte count (defaults to 32) |
Any(let csrf-token (crypto/random-urlsafe 32))sha256#
Computes the SHA-256 cryptographic digest and returns a 64-character lowercase hex string.
| Parameter | Type | Optional | Description |
|---|---|---|---|
data | String | Slab | required | Input data to hash |
Any(crypto/sha256 "hello")timing-safe-eq?#
Compares two strings or byte Slabs in constant time to prevent timing side-channel attacks.
| Parameter | Type | Optional | Description |
|---|---|---|---|
a | String | Slab | required | First digest or secret |
b | String | Slab | required | Second digest or secret |
Any(crypto/timing-safe-eq? expected actual)verify-password#
Verifies a plaintext password against a stored PBKDF2 hash in constant time.
| Parameter | Type | Optional | Description |
|---|---|---|---|
password | String | required | Candidate plaintext password |
stored_hash | String | required | Stored hash returned by `hash-password` |
Any(crypto/verify-password "hunter2" pw-hash)