Part V · Complete Tooling, CLI & Standard Library Reference
Appendix B.3
Standard Library Reference: Classical Crypto, NIST PQC & Authentication
Complete AST-verified API reference for 16 AEAD, hash, curve, FIPS 203/204/205 PQC, and JWT/OAuth2/TOTP modules
Zero-FFI cryptography and authentication: AES-GCM, XChaCha20-Poly1305, SHA-2/3, BLAKE2b, Argon2id, X25519/Ed25519, crypto/seal, NIST ML-KEM/ML-DSA/SLH-DSA, and auth/*.
Module (use [...]) | Source File | Capabilities | Types | Functions |
|---|---|---|---|---|
auth/jwt | lib/auth/jwt.vk | ..clocks | 2 | 9 |
auth/oauth2 | lib/auth/oauth2.vk | Zero host capabilities | 2 | 8 |
auth/totp | lib/auth/totp.vk | ..clocks | 0 | 8 |
crypto/aes | lib/crypto/aes.vk | Zero host capabilities | 0 | 3 |
crypto/blake | lib/crypto/blake.vk | Zero host capabilities | 0 | 4 |
crypto/chacha20 | lib/crypto/chacha20.vk | Zero host capabilities | 0 | 8 |
crypto/kdf | lib/crypto/kdf.vk | Zero host capabilities | 0 | 3 |
crypto/mldsa | lib/crypto/mldsa.vk | Zero host capabilities | 1 | 5 |
crypto/mlkem | lib/crypto/mlkem.vk | Zero host capabilities | 2 | 5 |
crypto/seal | lib/crypto/seal.vk | Zero host capabilities | 1 | 5 |
crypto/sha256 | lib/crypto/sha256.vk | Zero host capabilities | 1 | 22 |
crypto/sha3 | lib/crypto/sha3.vk | Zero host capabilities | 1 | 8 |
crypto/sig | lib/crypto/sig.vk | Zero host capabilities | 0 | 24 |
crypto/slhdsa | lib/crypto/slhdsa.vk | Zero host capabilities | 1 | 5 |
crypto/x25519 | lib/crypto/x25519.vk | Zero host capabilities | 0 | 6 |
crypto/x509 | lib/crypto/x509.vk | ..clocks | 0 | 10 |
Module auth/jwt
Exported Structs & Interfaces
JwtToken:JwtToken = struct { alg str, header map, claims map, signing_input str, signature bytes }— Decoded JWT components returned bydecode-unverifiedandverify-*.ClaimOpts:ClaimOpts = struct { now_sec i64 = ..., leeway_sec i64 = ..., issuer str = ..., audience str = ... }— Options forvalidate-claims. Zero/empty values skip the corresponding check.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
decode-unverified | decode-unverified = fn [token str] JwtToken | Decodes a compact JWS string (header.payload.signature) without verifying the signature. |
sign-hs256 | sign-hs256 = fn [key bytes, claims map] str | Signs claims using HS256 (HMAC-SHA256). |
verify-hs256 | verify-hs256 = fn [token str, key bytes] JwtToken | Verifies an HS256 JWT using constant-time MAC comparison. |
sign-eddsa | sign-eddsa = fn [seed32 bytes, claims map] str | Signs claims using EdDSA (RFC 8032 Ed25519) with a 32-byte seed. |
verify-eddsa | verify-eddsa = fn [token str, pubkey32 bytes] JwtToken | Verifies an EdDSA (Ed25519) JWT against a 32-byte public key. |
sign-mldsa65 | sign-mldsa65 = fn [sk bytes, claims map] str | Signs claims using post-quantum ML-DSA-65 (FIPS 204). |
verify-mldsa65 | verify-mldsa65 = fn [token str, pk bytes] JwtToken | Verifies a post-quantum ML-DSA-65 JWT against an ML-DSA-65 public key. |
validate-claims | validate-claims = fn [claims map, opts ClaimOpts] enum | Validates standard JWT claims (exp, nbf, iss, aud). If opts.now_sec <= 0, queries live UTC wall-clock time via time/unix. |
parse-bearer | parse-bearer = fn [auth_header str] str | Extracts the bearer token from an HTTP Authorization header value ('Bearer <token>'). |
Verified Doctest (auth/jwt/decode-unverified)
VEKO
use [jwt = auth/jwt]
tok = jwt/sign-hs256 (bytes/from-str 'super-secret-key-32bytes-minimum!') { sub = 'alice', role = 'admin' }
dec = jwt/decode-unverified tok
if dec.alg != 'HS256' or dec.claims.sub != 'alice' [ err 'jwt decode' ] else [ .ok ]Module auth/oauth2
Exported Structs & Interfaces
PkcePair:PkcePair = struct { verifier str, challenge str, method str }— PKCE verifier and S256 challenge pair (RFC 7636).OAuthConfig:OAuthConfig = struct { client_id str, auth_url str, token_url str, redirect_uri str, scope str = ... }— OAuth 2.0 client configuration.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
pkce-challenge | pkce-challenge = fn [verifier str] str | Computes the RFC 7636 S256 code challenge (BASE64URL(SHA256(verifier))). |
generate-pkce | generate-pkce = fn [] PkcePair | Generates a fresh cryptographic PKCE S256 verifier/challenge pair using CSPRNG entropy. |
verify-pkce | verify-pkce = fn [verifier str, challenge str] bool | Verifies a PKCE verifier against an S256 challenge in constant time. |
generate-state | generate-state = fn [] str | Generates a 24-byte random base64url CSRF state token. |
authorize-url | authorize-url = fn [cfg OAuthConfig, state str, challenge str] str | Builds an OAuth 2.0 authorization URL with PKCE S256 parameters. |
token-exchange-body | token-exchange-body = fn [cfg OAuthConfig, code str, verifier str] str | Encodes an application/x-www-form-urlencoded body for the authorization-code + PKCE token exchange. |
refresh-token-body | refresh-token-body = fn [cfg OAuthConfig, refresh_token str] str | Encodes an application/x-www-form-urlencoded body for a refresh-token grant. |
bearer-header | bearer-header = fn [access_token str] str | Formats an Authorization header value ('Bearer <token>'). |
Verified Doctest (auth/oauth2/pkce-challenge)
VEKO
use [oa = auth/oauth2]
ch = oa/pkce-challenge 'dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk'
if ch != 'E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM' [ err 'rfc7636 vector' ] else [ .ok ]Module auth/totp
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
b32-encode | b32-encode = fn [data bytes] str | Encodes data into RFC 4648 Base32 (without '=' padding). |
b32-decode | b32-decode = fn [s str] bytes | Decodes RFC 4648 Base32 (case-insensitive, ignores spaces/-/=). |
hotp | hotp = fn [secret bytes, counter i64, alg enum, digits i64] str | Computes an RFC 4226 HOTP code (alg = .sha1 or .sha256, digits typically 6 or 8). |
totp-at | totp-at = fn [secret bytes, unix_sec i64, period i64, alg enum, digits i64] str | Computes an RFC 6238 TOTP code at Unix timestamp unix_sec with period (typically 30). |
totp-now | totp-now = fn [secret bytes] str | Computes the current 6-digit SHA-1 TOTP code (30s period) using live time/unix. |
verify-at | verify-at = fn [secret bytes, code str, unix_sec i64, period i64, alg enum, digits i64, skew_steps i64] bool | Verifies a TOTP code at unix_sec within +/- skew_steps periods using constant-time comparison. |
verify-now | verify-now = fn [secret bytes, code str] bool | Verifies a 6-digit SHA-1 TOTP code against current UTC time allowing +/- 1 time step (30s). |
otpauth-uri | otpauth-uri = fn [issuer str, account str, secret bytes, alg enum, digits i64, period i64] str | Builds an otpauth://totp/... provisioning URI for authenticator apps. |
Verified Doctest (auth/totp/b32-encode)
VEKO
use [totp = auth/totp]
e = totp/b32-encode (bytes/from-str 'foobar')
if e != 'MZXW6YTBOI' or (bytes/to-str (totp/b32-decode e)) != 'foobar' [ err 'base32' ] else [ .ok ]Module crypto/aes
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
encrypt-block | encrypt-block = fn [key bytes, blk bytes] bytes | Encrypts a single 16-byte block using AES-128 (16-byte key) or AES-256 (32-byte key). |
gcm-encrypt | gcm-encrypt = fn [key bytes, nonce bytes, plaintext bytes, aad bytes] bytes | Encrypts plaintext with AES-128-GCM (16-byte key) or AES-256-GCM (32-byte key), 12-byte nonce, and associated data aad, returning ciphertext || 16-byte tag. |
gcm-decrypt | gcm-decrypt = fn [key bytes, nonce bytes, ct_and_tag bytes, aad bytes] bytes | Authenticates and decrypts ct_and_tag (ciphertext || 16-byte tag) with AES-128-GCM or AES-256-GCM. Returns err if authentication fails. |
Verified Doctest (crypto/aes/encrypt-block)
VEKO
use [aes = crypto/aes, hex = codec/hex]
k = hex/decode '000102030405060708090a0b0c0d0e0f'
p = hex/decode '00112233445566778899aabbccddeeff'
c = hex/encode (aes/encrypt-block k p)
if c != '69c4e0d86a7b0430d8cdb78070b4c55a' [ err 'aes-128-ecb vector mismatch' ] else [ .ok ]Module crypto/blake
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
blake2b-keyed | blake2b-keyed = fn [msg bytes, key bytes, out_len i64] bytes | Computes an RFC 7693 BLAKE2b digest of out_len (1..64) bytes with optional key (0..64 bytes). |
blake2b | blake2b = fn [msg bytes, out_len i64] bytes | Computes an unkeyed BLAKE2b digest of out_len (1..64) bytes. |
blake2b-256 | blake2b-256 = fn [msg bytes] bytes | Computes a 32-byte (256-bit) BLAKE2b digest. |
blake2b-512 | blake2b-512 = fn [msg bytes] bytes | Computes a 64-byte (512-bit) BLAKE2b digest. |
Verified Doctest (crypto/blake/blake2b-keyed)
VEKO
use [b2 = crypto/blake, hex = codec/hex]
h = hex/encode (b2/blake2b-512 (bytes/from-str 'abc'))
if h != 'ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923' [
err 'blake2b-512 vector mismatch'
] else [ .ok ]Module crypto/chacha20
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
chacha20-block | chacha20-block = fn [key bytes, counter i64, nonce bytes] any | Produces one 64-byte ChaCha20 keystream block for key (32 bytes), counter, nonce (12 bytes). |
chacha20-xor | chacha20-xor = fn [key bytes, counter i64, nonce bytes, data bytes] any | Encrypts/decrypts data with ChaCha20 starting at counter. |
poly1305-mac | poly1305-mac = fn [otk bytes, msg bytes] any | RFC 8439 Poly1305 130-bit MAC using 5 x 26-bit positive limbs (< 2^56 max intermediate). |
aead-encrypt | aead-encrypt = fn [key bytes, nonce bytes, aad bytes, plaintext bytes] any | RFC 8439 ChaCha20-Poly1305 AEAD encryption returning ciphertext || tag(16). |
aead-decrypt | aead-decrypt = fn [key bytes, nonce bytes, aad bytes, ct_and_tag bytes] any | RFC 8439 ChaCha20-Poly1305 AEAD decryption verifying 16-byte trailing tag in constant time. |
hchacha20 | hchacha20 = fn [key bytes, nonce16 bytes] bytes | Computes the 32-byte HChaCha20 subkey from key (32 bytes) and nonce16 (16 bytes). |
xchacha20-poly1305-encrypt | xchacha20-poly1305-encrypt = fn [key bytes, nonce24 bytes, aad bytes, plaintext bytes] any | XChaCha20-Poly1305 AEAD encryption with 32-byte key and 24-byte nonce24, returning ciphertext || tag(16). |
xchacha20-poly1305-decrypt | xchacha20-poly1305-decrypt = fn [key bytes, nonce24 bytes, aad bytes, ct_and_tag bytes] any | XChaCha20-Poly1305 AEAD decryption verifying 16-byte trailing tag in constant time. |
Verified Doctest (crypto/chacha20/hchacha20)
VEKO
use [cc = crypto/chacha20, hex = codec/hex]
k = hex/decode '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'
n = hex/decode '000000090000004a0000000031415927'
subk = hex/encode (cc/hchacha20 k n)
if subk != '82413b4227b27bfed30e42508a877d73a0f9e4d58a74a853c12ec41326d3ecdc' [
err 'hchacha20 RFC vector mismatch'
] else [ .ok ]Module crypto/kdf
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
pbkdf2-sha256 | pbkdf2-sha256 = fn [password bytes, salt bytes, iters i64, dk_len i64] bytes | Derives dk_len bytes using PBKDF2-HMAC-SHA256 (iters >= 1). |
argon2id | argon2id = fn [password bytes, salt bytes, mem_kib i64, iters i64, tag_len i64] bytes | Derives tag_len bytes using RFC 9106 Argon2id (p=1 lane, mem_kib >= 8 KiB, iters >= 1). |
verify-tag | verify-tag = fn [a bytes, b bytes] bool | Constant-time comparison for derived tags/hashes. |
Verified Doctest (crypto/kdf/pbkdf2-sha256)
VEKO
use [kdf = crypto/kdf, hex = codec/hex]
// RFC 6070-equivalent PBKDF2-HMAC-SHA256 vector: password='password', salt='salt', c=1, dkLen=32
dk = hex/encode (kdf/pbkdf2-sha256 (bytes/from-str 'password') (bytes/from-str 'salt') 1 32)
if dk != '120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b' [
err 'pbkdf2-sha256 vector mismatch'
] else [ .ok ]Module crypto/mldsa
Exported Structs & Interfaces
KeyPair:KeyPair = struct { param enum, pk bytes, sk bytes }— Signing key pair produced bymldsa/keygenormldsa/keygen-deterministic.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
keygen-deterministic | keygen-deterministic = fn [param enum, xi bytes] KeyPair | Deterministic FIPS 204 ML-DSA key generation from a 32-byte seed xi. |
keygen | keygen = fn [param enum] KeyPair | Generates a fresh ML-DSA key pair using the OS/hardware CSPRNG. |
sign-deterministic | sign-deterministic = fn [param enum, sk bytes, msg bytes, rnd32 bytes] bytes | Deterministic FIPS 204 ML-DSA signing with explicit 32-byte randomness rnd32 (all-zero for pure deterministic mode). |
sign | sign = fn [param enum, sk bytes, msg bytes] bytes | Signs msg with ML-DSA using fresh hedged CSPRNG randomness. |
verify | verify = fn [param enum, pk bytes, msg bytes, sig bytes] bool | Verifies a FIPS 204 ML-DSA signature against pk and msg. |
Verified Doctest (crypto/mldsa/keygen-deterministic)
VEKO
use [dsa = crypto/mldsa]
xi = bytes/fill 32 0x42
kp = dsa/keygen-deterministic .mldsa44 xi
msg = bytes/from-str 'post-quantum veko signature'
sig = dsa/sign-deterministic .mldsa44 kp.sk msg (bytes/fill 32 0)
ok = dsa/verify .mldsa44 kp.pk msg sig
bad = dsa/verify .mldsa44 kp.pk (bytes/from-str 'tampered') sig
if (not ok) or bad or (len kp.pk) != 1312 [ err 'mldsa-44 failed' ] else [ .ok ]Module crypto/mlkem
Exported Structs & Interfaces
KeyPair:KeyPair = struct { param enum, ek bytes, dk bytes }— Key pair produced bymlkem/keygenormlkem/keygen-deterministic.EncapsResult:EncapsResult = struct { ciphertext bytes, shared_secret bytes }— Encapsulation output produced bymlkem/encapsormlkem/encaps-deterministic.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
keygen-deterministic | keygen-deterministic = fn [param enum, d_seed bytes, z_seed bytes] KeyPair | Deterministic FIPS 203 ML-KEM key generation from 32-byte d_seed and 32-byte z_seed. |
keygen | keygen = fn [param enum] KeyPair | Generates a fresh ML-KEM key pair using the OS/hardware CSPRNG (random/bytes). |
encaps-deterministic | encaps-deterministic = fn [param enum, ek bytes, m32 bytes] EncapsResult | Deterministic FIPS 203 ML-KEM encapsulation using 32-byte message seed m32. |
encaps | encaps = fn [param enum, ek bytes] EncapsResult | Encapsulates a fresh 32-byte shared secret to ek using the OS/hardware CSPRNG. |
decaps | decaps = fn [param enum, dk bytes, ct bytes] bytes | FIPS 203 ML-KEM decapsulation with constant-time implicit rejection on tampered ciphertexts. |
Verified Doctest (crypto/mlkem/keygen-deterministic)
VEKO
use [kem = crypto/mlkem]
d = bytes/fill 32 0x11
z = bytes/fill 32 0x22
m = bytes/fill 32 0x33
kp = kem/keygen-deterministic .mlkem512 d z
enc = kem/encaps-deterministic .mlkem512 kp.ek m
ss2 = kem/decaps .mlkem512 kp.dk enc.ciphertext
if ss2 != enc.shared_secret or (len kp.ek) != 800 or (len enc.ciphertext) != 768 [
err 'mlkem-512 roundtrip failed'
] else [ .ok ]Module crypto/seal
Exported Structs & Interfaces
Sealed:sealed Sealed = struct { version i64, algorithm enum, nonce bytes, aad bytes, ciphertext bytes }— Opaque sealed ciphertext envelope (cannot be constructed or mutated outsidecrypto/seal).
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
encrypt | encrypt = fn [key bytes, plaintext bytes, aad bytes] Sealed | Seals plaintext under a 32-byte AES-256-GCM key and associated data aad using a fresh 12-byte CSPRNG nonce. |
encrypt-with-nonce | encrypt-with-nonce = fn [key bytes, nonce bytes, plaintext bytes, aad bytes] Sealed | Deterministic sealing with an explicit 12-byte nonce (for reproducible test vectors; never reuse a nonce!). |
with-open | with-open = fn [env Sealed, key bytes, use_fn fn[bytes->any]] any | Unseals env under key, passes the plaintext into use_fn, zeroizes the temporary plaintext buffer unconditionally via defer, and returns the non-secret result of (use_fn pt). |
to-bytes | to-bytes = fn [env Sealed] bytes | Serializes a Sealed envelope into portable wire bytes ('VKSL' || ver(u8) || nonce_len(u8) || aad_len(u16_be) || nonce || aad || ct). |
from-bytes | from-bytes = fn [wire bytes] Sealed | Parses portable wire bytes produced by seal/to-bytes back into a Sealed envelope. |
Verified Doctest (crypto/seal/encrypt)
VEKO
use [seal = crypto/seal]
key = bytes/fill 32 0x33
env = seal/encrypt key (bytes/from-str 'top-secret-token') (bytes/from-str 'ctx=vault')
ok_len = seal/with-open env key fn [pt] [ len pt ]
if ok_len != 16 [ err 'seal roundtrip' ] else [ .ok ]Module crypto/sha256
Exported Structs & Interfaces
Sha256State:Sha256State = struct { h block[i64], buf bytes, total i64 = ... }— Streaming SHA-256 hash state.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
u32 | u32 = fn [x i64] i64 | Exported crypto/sha256/u32 operation. |
sha256 | sha256 = fn [msg bytes] bytes | Computes the 32-byte SHA-256 digest of msg. |
sha256-init | sha256-init = fn [] Sha256State | Exported crypto/sha256/sha256-init operation. |
sha256-update | sha256-update = fn [mut st Sha256State, data bytes] | Exported crypto/sha256/sha256-update operation. |
sha256-digest | sha256-digest = fn [st Sha256State] bytes | Exported crypto/sha256/sha256-digest operation. |
sha512 | sha512 = fn [msg bytes] bytes | Computes the 64-byte SHA-512 digest of msg (used by Ed25519). |
hmac-sha256 | hmac-sha256 = fn [key bytes, data bytes] bytes | Exported crypto/sha256/hmac-sha256 operation. |
hkdf-extract | hkdf-extract = fn [salt bytes, ikm bytes] bytes | Exported crypto/sha256/hkdf-extract operation. |
hkdf-expand | hkdf-expand = fn [prk bytes, info bytes, out_len i64] bytes | Exported crypto/sha256/hkdf-expand operation. |
hkdf-expand-label | hkdf-expand-label = fn [secret bytes, label str, context bytes, out_len i64] bytes | Exported crypto/sha256/hkdf-expand-label operation. |
derive-secret | derive-secret = fn [secret bytes, label str, transcript_hash bytes] bytes | Exported crypto/sha256/derive-secret operation. |
ct-eq | ct-eq = fn [a bytes, b bytes] bool | Exported crypto/sha256/ct-eq operation. |
to-hex | to-hex = fn [data bytes] str | Exported crypto/sha256/to-hex operation. |
sha384 | sha384 = fn [msg bytes] bytes | Computes the 48-byte FIPS 180-4 SHA-384 digest of msg. |
hmac-sha384 | hmac-sha384 = fn [key bytes, data bytes] bytes | Computes RFC 2104 HMAC-SHA384 (48-byte MAC). |
hmac-sha512 | hmac-sha512 = fn [key bytes, data bytes] bytes | Computes RFC 2104 HMAC-SHA512 (64-byte MAC). |
hkdf-sha384-extract | hkdf-sha384-extract = fn [salt bytes, ikm bytes] bytes | RFC 5869 HKDF-Extract using HMAC-SHA384. |
hkdf-sha384-expand | hkdf-sha384-expand = fn [prk bytes, info bytes, out_len i64] bytes | RFC 5869 HKDF-Expand using HMAC-SHA384. |
hkdf-sha384-expand-label | hkdf-sha384-expand-label = fn [secret bytes, label str, context bytes, out_len i64] bytes | TLS 1.3 RFC 8446 §7.1 HKDF-Expand-Label using HMAC-SHA384 (for TLS_AES_256_GCM_SHA384 0x1302). |
derive-secret-sha384 | derive-secret-sha384 = fn [secret bytes, label str, transcript_hash bytes] bytes | TLS 1.3 RFC 8446 §7.1 Derive-Secret using SHA-384 (48-byte output). |
hkdf-sha512-extract | hkdf-sha512-extract = fn [salt bytes, ikm bytes] bytes | RFC 5869 HKDF-Extract using HMAC-SHA512. |
hkdf-sha512-expand | hkdf-sha512-expand = fn [prk bytes, info bytes, out_len i64] bytes | RFC 5869 HKDF-Expand using HMAC-SHA512. |
Verified Doctest (crypto/sha256/sha256)
VEKO
use [s2 = crypto/sha256]
if (s2/to-hex (s2/sha256 (bytes/from-str 'abc'))) != 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' [
err 'sha256 vector mismatch'
] else [ .ok ]Module crypto/sha3
Exported Structs & Interfaces
Sponge:Sponge = struct { state block[i64], rate i64, pos i64 }— Streaming Keccak-1600 sponge state (used by SHA3 and SHAKE128/256 XOFs, including NIST PQC).
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
keccak-f1600 | keccak-f1600 = fn [mut a block[i64]] | Applies the 24-round Keccak-f[1600] permutation in-place to a 25-lane block[i64]. |
xof-squeeze | xof-squeeze = fn [mut sp Sponge, out_len i64] bytes | Squeezes out_len bytes from an absorbed Sponge (can be called repeatedly for XOF streaming). |
shake128-init | shake128-init = fn [msg bytes] Sponge | Creates a streaming SHAKE128 XOF sponge absorbed with msg. |
shake256-init | shake256-init = fn [msg bytes] Sponge | Creates a streaming SHAKE256 XOF sponge absorbed with msg. |
sha3-256 | sha3-256 = fn [msg bytes] bytes | Computes the 32-byte FIPS 202 SHA3-256 digest of msg. |
sha3-512 | sha3-512 = fn [msg bytes] bytes | Computes the 64-byte FIPS 202 SHA3-512 digest of msg. |
shake128 | shake128 = fn [msg bytes, out_len i64] bytes | Computes out_len bytes of FIPS 202 SHAKE128 extendable output from msg. |
shake256 | shake256 = fn [msg bytes, out_len i64] bytes | Computes out_len bytes of FIPS 202 SHAKE256 extendable output from msg. |
Verified Doctest (crypto/sha3/sha3-256)
VEKO
use [s3 = crypto/sha3, hex = codec/hex]
h0 = hex/encode (s3/sha3-256 (bytes/with-cap 0))
h1 = hex/encode (s3/sha3-256 (bytes/from-str 'abc'))
if h0 != 'a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a' or h1 != '3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532' [
err 'sha3-256 vector mismatch'
] else [ .ok ]Module crypto/sig
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
bn-from-be | bn-from-be = fn [b bytes] block | Exported crypto/sig/bn-from-be operation. |
bn-to-be | bn-to-be = fn [a block, out_len i64] bytes | Exported crypto/sig/bn-to-be operation. |
bn-cmp | bn-cmp = fn [a block, b block] i64 | Exported crypto/sig/bn-cmp operation. |
bn-add | bn-add = fn [a block, b block] block | Exported crypto/sig/bn-add operation. |
bn-sub | bn-sub = fn [a block, b block] block | Computes a - b assuming a >= b. |
bn-mul | bn-mul = fn [a block, b block] block | Full multiplication a * b via Comba column accumulation (zero random-access writes). |
bn-mod | bn-mod = fn [a block, m block] block | Computes a mod m via bit-by-bit shift-subtract (exact for any modulus size). |
bn-mod-add | bn-mod-add = fn [a block, b block, m block] block | Exported crypto/sig/bn-mod-add operation. |
bn-mod-sub | bn-mod-sub = fn [a block, b block, m block] block | Exported crypto/sig/bn-mod-sub operation. |
bn-mod-pow | bn-mod-pow = fn [base_in block, exp block, m_in block] any | Computes base^exp mod m (m odd) via Montgomery binary exponentiation. |
rsa-pkcs1-sha256-verify | rsa-pkcs1-sha256-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] bool | Exported crypto/sig/rsa-pkcs1-sha256-verify operation. |
rsa-pkcs1-sha384-verify | rsa-pkcs1-sha384-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] bool | Exported crypto/sig/rsa-pkcs1-sha384-verify operation. |
rsa-pkcs1-sha512-verify | rsa-pkcs1-sha512-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] bool | Exported crypto/sig/rsa-pkcs1-sha512-verify operation. |
rsa-pss-sha256-verify | rsa-pss-sha256-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] bool | Exported crypto/sig/rsa-pss-sha256-verify operation. |
rsa-pss-sha384-verify | rsa-pss-sha384-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] bool | Verifies an RSA-PSS + SHA-384 (0x0805 rsa_pss_rsae_sha384, 48-byte salt) signature. |
rsa-pss-sha512-verify | rsa-pss-sha512-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] bool | Verifies an RSA-PSS + SHA-512 (0x0806 rsa_pss_rsae_sha512, 64-byte salt) signature. |
ecdsa-p256-verify | ecdsa-p256-verify = fn [pk_point bytes, msg bytes, sig_der bytes] bool | Exported crypto/sig/ecdsa-p256-verify operation. |
ecdsa-p384-verify | ecdsa-p384-verify = fn [pk_point bytes, msg bytes, sig_der bytes] bool | Exported crypto/sig/ecdsa-p384-verify operation. |
ecdsa-p256-pubkey | ecdsa-p256-pubkey = fn [priv32 bytes] bytes | Derives the 65-byte uncompressed SEC1 public key (0x04 || X(32) || Y(32)) from a 32-byte P-256 private scalar. |
ecdhe-p256 | ecdhe-p256 = fn [priv32 bytes, peer_pub65 bytes] bytes | Computes RFC 8446 Section 7.4.2 ECDHE P-256 (secp256r1, 0x0017) 32-byte shared secret X-coordinate. |
ecdsa-p256-sign | ecdsa-p256-sign = fn [priv32 bytes, msg bytes] bytes | Signs msg with ECDSA P-256 / SHA-256 using RFC 6979 deterministic nonces, returning ASN.1 DER (r, s). |
rsa-pss-sha256-sign | rsa-pss-sha256-sign = fn [mod_be bytes, priv_exp_be bytes, msg bytes, salt bytes] bytes | Signs msg using RSA-PSS + SHA-256 (0x0804) with a 32-byte salt, returning a k-byte signature. |
pkcs8-extract-private-key | pkcs8-extract-private-key = fn [pkcs8_der bytes] bytes | Extracts the inner private-key OCTET STRING from a PKCS#8 PrivateKeyInfo DER blob. |
parse-private-key-der | parse-private-key-der = fn [key_der bytes, label_hint str] any | Parses a PKCS#8 (PRIVATE KEY), SEC1 (EC PRIVATE KEY), or PKCS#1 (RSA PRIVATE KEY) DER blob. Returns { kind = .ed25519 | .p256 | .rsa, priv = bytes, n = bytes, d = bytes }. |
Verified Doctest (crypto/sig/ecdsa-p256-sign)
VEKO
use [sig = crypto/sig]
priv = bytes/fill 32 0x2a
pubk = sig/ecdsa-p256-pubkey priv
msg = bytes/from-str 'veko ecdsa p256 sign/verify'
signature = sig/ecdsa-p256-sign priv msg
if not (sig/ecdsa-p256-verify pubk msg signature) [ err 'ecdsa-p256 sign/verify failed' ] else [ .ok ]Module crypto/slhdsa
Exported Structs & Interfaces
KeyPair:KeyPair = struct { param enum, pk bytes, sk bytes }— Key pair produced byslhdsa/keygenorslhdsa/keygen-deterministic.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
keygen-deterministic | keygen-deterministic = fn [param enum, sk_seed bytes, sk_prf bytes, pk_seed bytes] KeyPair | Deterministic FIPS 205 SLH-DSA key generation from three n-byte seeds (sk_seed, sk_prf, pk_seed). |
keygen | keygen = fn [param enum] KeyPair | Generates a fresh SLH-DSA key pair using the OS/hardware CSPRNG. |
sign-deterministic | sign-deterministic = fn [param enum, sk bytes, msg bytes, opt_rand bytes] bytes | Deterministic FIPS 205 SLH-DSA signing (empty pure-mode context) with explicit 16-byte opt_rand. |
sign | sign = fn [param enum, sk bytes, msg bytes] bytes | Signs msg with SLH-DSA using fresh hedged CSPRNG randomness. |
verify | verify = fn [param enum, pk bytes, msg bytes, sig bytes] bool | Verifies a FIPS 205 SLH-DSA signature against pk and msg. |
Verified Doctest (crypto/slhdsa/keygen-deterministic)
VEKO
use [slh = crypto/slhdsa]
s1 = bytes/fill 16 0x01
s2 = bytes/fill 16 0x02
s3 = bytes/fill 16 0x03
kp = slh/keygen-deterministic .shake_128f s1 s2 s3
msg = bytes/from-str 'stateless hash-based veko signature'
sig = slh/sign-deterministic .shake_128f kp.sk msg (bytes/fill 16 0)
ok = slh/verify .shake_128f kp.pk msg sig
bad = slh/verify .shake_128f kp.pk (bytes/from-str 'bad') sig
if (not ok) or bad or (len kp.pk) != 32 [ err 'slhdsa-shake-128f failed' ] else [ .ok ]Module crypto/x25519
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
x25519 | x25519 = fn [scalar bytes, u_bytes bytes] any | RFC 7748 X25519(k, u) -> 32-byte shared secret or public point. |
x25519-base | x25519-base = fn [scalar bytes] any | Computes X25519(scalar, 9) public key (32 bytes). |
ed25519-pubkey | ed25519-pubkey = fn [seed bytes] any | Derives the 32-byte RFC 8032 Ed25519 public key from a 32-byte seed. |
ed25519-sign | ed25519-sign = fn [seed bytes, msg bytes] any | Produces a 64-byte RFC 8032 Ed25519 signature over msg using 32-byte seed. |
ed25519-sign-with-pk | ed25519-sign-with-pk = fn [seed bytes, pk bytes, msg bytes] any | Produces a 64-byte RFC 8032 Ed25519 signature reusing a precomputed 32-byte pk. |
ed25519-verify | ed25519-verify = fn [pk bytes, msg bytes, sig bytes] bool | Verifies an RFC 8032 Ed25519 signature (sig: 64B) on msg under pk (32B). |
Module crypto/x509
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
parse-cert | parse-cert = fn [cert_der bytes] any | Parses one DER-encoded X.509 certificate into a structured validation record. |
verify-sig-with-cert | verify-sig-with-cert = fn [signer map, sig_oid str, msg bytes, signature bytes] bool | Verifies an arbitrary message+signature against a parsed certificate's public key. |
verify-cert-issued-by | verify-cert-issued-by = fn [child map, parent map] bool | Verifies that parent issued and cryptographically signed child. |
match-hostname | match-hostname = fn [cert map, expected_host str] bool | Verifies SAN DNS/IP or fallback CN identity against expected_host. |
load-pem-roots | load-pem-roots = fn [pem_text str] any | Parses a PEM trust bundle string containing one or more CERTIFICATE blocks. |
builtin-roots-pem | builtin-roots-pem = fn [] str | Returns the built-in public CA PEM bundle (ISRG Root X1/X2/YE, DigiCert Global Root G2, GTS Root R1, Amazon Root CA 1, USERTrust/Sectigo). |
verify-chain | verify-chain = fn [chain_ders block, expected_host str, opts map] any | Verifies an X.509 certificate chain (leaf-first DER list) against hostname + validity window + PEM roots and/or SPKI SHA-256 pins. |
mint-ed25519-cert | mint-ed25519-cert = fn [cfg map] any | Mints a valid X.509 v3 DER certificate signed with Ed25519 (1.3.101.112). cfg: { issuer_cn, subject_cn, is_ca, san_dns, san_ips, subject_seed, signer_seed, serial } |
encode-p256-pkcs8-der | encode-p256-pkcs8-der = fn [priv32 bytes] any | Encodes a 32-byte ECDSA P-256 private scalar as a standard PKCS#8 PrivateKeyInfo DER blob. |
mint-p256-cert | mint-p256-cert = fn [cfg map] any | Mints a valid X.509 v3 DER certificate signed with ECDSA P-256 + SHA-256 (1.2.840.10045.4.3.2). cfg: { issuer_cn, subject_cn, is_ca, san_dns, san_ips, subject_priv, signer_priv, serial } |