veko-lang.org
Download Free EPUB 3.0

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 FileCapabilitiesTypesFunctions
auth/jwtlib/auth/jwt.vk..clocks29
auth/oauth2lib/auth/oauth2.vkZero host capabilities28
auth/totplib/auth/totp.vk..clocks08
crypto/aeslib/crypto/aes.vkZero host capabilities03
crypto/blakelib/crypto/blake.vkZero host capabilities04
crypto/chacha20lib/crypto/chacha20.vkZero host capabilities08
crypto/kdflib/crypto/kdf.vkZero host capabilities03
crypto/mldsalib/crypto/mldsa.vkZero host capabilities15
crypto/mlkemlib/crypto/mlkem.vkZero host capabilities25
crypto/seallib/crypto/seal.vkZero host capabilities15
crypto/sha256lib/crypto/sha256.vkZero host capabilities122
crypto/sha3lib/crypto/sha3.vkZero host capabilities18
crypto/siglib/crypto/sig.vkZero host capabilities024
crypto/slhdsalib/crypto/slhdsa.vkZero host capabilities15
crypto/x25519lib/crypto/x25519.vkZero host capabilities06
crypto/x509lib/crypto/x509.vk..clocks010

Module auth/jwt

Exported Structs & Interfaces

  • JwtToken: JwtToken = struct { alg str, header map, claims map, signing_input str, signature bytes } — Decoded JWT components returned by decode-unverified and verify-*.
  • ClaimOpts: ClaimOpts = struct { now_sec i64 = ..., leeway_sec i64 = ..., issuer str = ..., audience str = ... } — Options for validate-claims. Zero/empty values skip the corresponding check.

Exported Functions

SymbolSignatureDescription
decode-unverifieddecode-unverified = fn [token str] JwtTokenDecodes a compact JWS string (header.payload.signature) without verifying the signature.
sign-hs256sign-hs256 = fn [key bytes, claims map] strSigns claims using HS256 (HMAC-SHA256).
verify-hs256verify-hs256 = fn [token str, key bytes] JwtTokenVerifies an HS256 JWT using constant-time MAC comparison.
sign-eddsasign-eddsa = fn [seed32 bytes, claims map] strSigns claims using EdDSA (RFC 8032 Ed25519) with a 32-byte seed.
verify-eddsaverify-eddsa = fn [token str, pubkey32 bytes] JwtTokenVerifies an EdDSA (Ed25519) JWT against a 32-byte public key.
sign-mldsa65sign-mldsa65 = fn [sk bytes, claims map] strSigns claims using post-quantum ML-DSA-65 (FIPS 204).
verify-mldsa65verify-mldsa65 = fn [token str, pk bytes] JwtTokenVerifies a post-quantum ML-DSA-65 JWT against an ML-DSA-65 public key.
validate-claimsvalidate-claims = fn [claims map, opts ClaimOpts] enumValidates standard JWT claims (exp, nbf, iss, aud). If opts.now_sec <= 0, queries live UTC wall-clock time via time/unix.
parse-bearerparse-bearer = fn [auth_header str] strExtracts 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

SymbolSignatureDescription
pkce-challengepkce-challenge = fn [verifier str] strComputes the RFC 7636 S256 code challenge (BASE64URL(SHA256(verifier))).
generate-pkcegenerate-pkce = fn [] PkcePairGenerates a fresh cryptographic PKCE S256 verifier/challenge pair using CSPRNG entropy.
verify-pkceverify-pkce = fn [verifier str, challenge str] boolVerifies a PKCE verifier against an S256 challenge in constant time.
generate-stategenerate-state = fn [] strGenerates a 24-byte random base64url CSRF state token.
authorize-urlauthorize-url = fn [cfg OAuthConfig, state str, challenge str] strBuilds an OAuth 2.0 authorization URL with PKCE S256 parameters.
token-exchange-bodytoken-exchange-body = fn [cfg OAuthConfig, code str, verifier str] strEncodes an application/x-www-form-urlencoded body for the authorization-code + PKCE token exchange.
refresh-token-bodyrefresh-token-body = fn [cfg OAuthConfig, refresh_token str] strEncodes an application/x-www-form-urlencoded body for a refresh-token grant.
bearer-headerbearer-header = fn [access_token str] strFormats 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

SymbolSignatureDescription
b32-encodeb32-encode = fn [data bytes] strEncodes data into RFC 4648 Base32 (without '=' padding).
b32-decodeb32-decode = fn [s str] bytesDecodes RFC 4648 Base32 (case-insensitive, ignores spaces/-/=).
hotphotp = fn [secret bytes, counter i64, alg enum, digits i64] strComputes an RFC 4226 HOTP code (alg = .sha1 or .sha256, digits typically 6 or 8).
totp-attotp-at = fn [secret bytes, unix_sec i64, period i64, alg enum, digits i64] strComputes an RFC 6238 TOTP code at Unix timestamp unix_sec with period (typically 30).
totp-nowtotp-now = fn [secret bytes] strComputes the current 6-digit SHA-1 TOTP code (30s period) using live time/unix.
verify-atverify-at = fn [secret bytes, code str, unix_sec i64, period i64, alg enum, digits i64, skew_steps i64] boolVerifies a TOTP code at unix_sec within +/- skew_steps periods using constant-time comparison.
verify-nowverify-now = fn [secret bytes, code str] boolVerifies a 6-digit SHA-1 TOTP code against current UTC time allowing +/- 1 time step (30s).
otpauth-uriotpauth-uri = fn [issuer str, account str, secret bytes, alg enum, digits i64, period i64] strBuilds 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

SymbolSignatureDescription
encrypt-blockencrypt-block = fn [key bytes, blk bytes] bytesEncrypts a single 16-byte block using AES-128 (16-byte key) or AES-256 (32-byte key).
gcm-encryptgcm-encrypt = fn [key bytes, nonce bytes, plaintext bytes, aad bytes] bytesEncrypts 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-decryptgcm-decrypt = fn [key bytes, nonce bytes, ct_and_tag bytes, aad bytes] bytesAuthenticates 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

SymbolSignatureDescription
blake2b-keyedblake2b-keyed = fn [msg bytes, key bytes, out_len i64] bytesComputes an RFC 7693 BLAKE2b digest of out_len (1..64) bytes with optional key (0..64 bytes).
blake2bblake2b = fn [msg bytes, out_len i64] bytesComputes an unkeyed BLAKE2b digest of out_len (1..64) bytes.
blake2b-256blake2b-256 = fn [msg bytes] bytesComputes a 32-byte (256-bit) BLAKE2b digest.
blake2b-512blake2b-512 = fn [msg bytes] bytesComputes 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

SymbolSignatureDescription
chacha20-blockchacha20-block = fn [key bytes, counter i64, nonce bytes] anyProduces one 64-byte ChaCha20 keystream block for key (32 bytes), counter, nonce (12 bytes).
chacha20-xorchacha20-xor = fn [key bytes, counter i64, nonce bytes, data bytes] anyEncrypts/decrypts data with ChaCha20 starting at counter.
poly1305-macpoly1305-mac = fn [otk bytes, msg bytes] anyRFC 8439 Poly1305 130-bit MAC using 5 x 26-bit positive limbs (< 2^56 max intermediate).
aead-encryptaead-encrypt = fn [key bytes, nonce bytes, aad bytes, plaintext bytes] anyRFC 8439 ChaCha20-Poly1305 AEAD encryption returning ciphertext || tag(16).
aead-decryptaead-decrypt = fn [key bytes, nonce bytes, aad bytes, ct_and_tag bytes] anyRFC 8439 ChaCha20-Poly1305 AEAD decryption verifying 16-byte trailing tag in constant time.
hchacha20hchacha20 = fn [key bytes, nonce16 bytes] bytesComputes the 32-byte HChaCha20 subkey from key (32 bytes) and nonce16 (16 bytes).
xchacha20-poly1305-encryptxchacha20-poly1305-encrypt = fn [key bytes, nonce24 bytes, aad bytes, plaintext bytes] anyXChaCha20-Poly1305 AEAD encryption with 32-byte key and 24-byte nonce24, returning ciphertext || tag(16).
xchacha20-poly1305-decryptxchacha20-poly1305-decrypt = fn [key bytes, nonce24 bytes, aad bytes, ct_and_tag bytes] anyXChaCha20-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

SymbolSignatureDescription
pbkdf2-sha256pbkdf2-sha256 = fn [password bytes, salt bytes, iters i64, dk_len i64] bytesDerives dk_len bytes using PBKDF2-HMAC-SHA256 (iters >= 1).
argon2idargon2id = fn [password bytes, salt bytes, mem_kib i64, iters i64, tag_len i64] bytesDerives tag_len bytes using RFC 9106 Argon2id (p=1 lane, mem_kib >= 8 KiB, iters >= 1).
verify-tagverify-tag = fn [a bytes, b bytes] boolConstant-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 by mldsa/keygen or mldsa/keygen-deterministic.

Exported Functions

SymbolSignatureDescription
keygen-deterministickeygen-deterministic = fn [param enum, xi bytes] KeyPairDeterministic FIPS 204 ML-DSA key generation from a 32-byte seed xi.
keygenkeygen = fn [param enum] KeyPairGenerates a fresh ML-DSA key pair using the OS/hardware CSPRNG.
sign-deterministicsign-deterministic = fn [param enum, sk bytes, msg bytes, rnd32 bytes] bytesDeterministic FIPS 204 ML-DSA signing with explicit 32-byte randomness rnd32 (all-zero for pure deterministic mode).
signsign = fn [param enum, sk bytes, msg bytes] bytesSigns msg with ML-DSA using fresh hedged CSPRNG randomness.
verifyverify = fn [param enum, pk bytes, msg bytes, sig bytes] boolVerifies 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 by mlkem/keygen or mlkem/keygen-deterministic.
  • EncapsResult: EncapsResult = struct { ciphertext bytes, shared_secret bytes } — Encapsulation output produced by mlkem/encaps or mlkem/encaps-deterministic.

Exported Functions

SymbolSignatureDescription
keygen-deterministickeygen-deterministic = fn [param enum, d_seed bytes, z_seed bytes] KeyPairDeterministic FIPS 203 ML-KEM key generation from 32-byte d_seed and 32-byte z_seed.
keygenkeygen = fn [param enum] KeyPairGenerates a fresh ML-KEM key pair using the OS/hardware CSPRNG (random/bytes).
encaps-deterministicencaps-deterministic = fn [param enum, ek bytes, m32 bytes] EncapsResultDeterministic FIPS 203 ML-KEM encapsulation using 32-byte message seed m32.
encapsencaps = fn [param enum, ek bytes] EncapsResultEncapsulates a fresh 32-byte shared secret to ek using the OS/hardware CSPRNG.
decapsdecaps = fn [param enum, dk bytes, ct bytes] bytesFIPS 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 outside crypto/seal).

Exported Functions

SymbolSignatureDescription
encryptencrypt = fn [key bytes, plaintext bytes, aad bytes] SealedSeals plaintext under a 32-byte AES-256-GCM key and associated data aad using a fresh 12-byte CSPRNG nonce.
encrypt-with-nonceencrypt-with-nonce = fn [key bytes, nonce bytes, plaintext bytes, aad bytes] SealedDeterministic sealing with an explicit 12-byte nonce (for reproducible test vectors; never reuse a nonce!).
with-openwith-open = fn [env Sealed, key bytes, use_fn fn[bytes->any]] anyUnseals 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-bytesto-bytes = fn [env Sealed] bytesSerializes a Sealed envelope into portable wire bytes ('VKSL' || ver(u8) || nonce_len(u8) || aad_len(u16_be) || nonce || aad || ct).
from-bytesfrom-bytes = fn [wire bytes] SealedParses 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

SymbolSignatureDescription
u32u32 = fn [x i64] i64Exported crypto/sha256/u32 operation.
sha256sha256 = fn [msg bytes] bytesComputes the 32-byte SHA-256 digest of msg.
sha256-initsha256-init = fn [] Sha256StateExported crypto/sha256/sha256-init operation.
sha256-updatesha256-update = fn [mut st Sha256State, data bytes]Exported crypto/sha256/sha256-update operation.
sha256-digestsha256-digest = fn [st Sha256State] bytesExported crypto/sha256/sha256-digest operation.
sha512sha512 = fn [msg bytes] bytesComputes the 64-byte SHA-512 digest of msg (used by Ed25519).
hmac-sha256hmac-sha256 = fn [key bytes, data bytes] bytesExported crypto/sha256/hmac-sha256 operation.
hkdf-extracthkdf-extract = fn [salt bytes, ikm bytes] bytesExported crypto/sha256/hkdf-extract operation.
hkdf-expandhkdf-expand = fn [prk bytes, info bytes, out_len i64] bytesExported crypto/sha256/hkdf-expand operation.
hkdf-expand-labelhkdf-expand-label = fn [secret bytes, label str, context bytes, out_len i64] bytesExported crypto/sha256/hkdf-expand-label operation.
derive-secretderive-secret = fn [secret bytes, label str, transcript_hash bytes] bytesExported crypto/sha256/derive-secret operation.
ct-eqct-eq = fn [a bytes, b bytes] boolExported crypto/sha256/ct-eq operation.
to-hexto-hex = fn [data bytes] strExported crypto/sha256/to-hex operation.
sha384sha384 = fn [msg bytes] bytesComputes the 48-byte FIPS 180-4 SHA-384 digest of msg.
hmac-sha384hmac-sha384 = fn [key bytes, data bytes] bytesComputes RFC 2104 HMAC-SHA384 (48-byte MAC).
hmac-sha512hmac-sha512 = fn [key bytes, data bytes] bytesComputes RFC 2104 HMAC-SHA512 (64-byte MAC).
hkdf-sha384-extracthkdf-sha384-extract = fn [salt bytes, ikm bytes] bytesRFC 5869 HKDF-Extract using HMAC-SHA384.
hkdf-sha384-expandhkdf-sha384-expand = fn [prk bytes, info bytes, out_len i64] bytesRFC 5869 HKDF-Expand using HMAC-SHA384.
hkdf-sha384-expand-labelhkdf-sha384-expand-label = fn [secret bytes, label str, context bytes, out_len i64] bytesTLS 1.3 RFC 8446 §7.1 HKDF-Expand-Label using HMAC-SHA384 (for TLS_AES_256_GCM_SHA384 0x1302).
derive-secret-sha384derive-secret-sha384 = fn [secret bytes, label str, transcript_hash bytes] bytesTLS 1.3 RFC 8446 §7.1 Derive-Secret using SHA-384 (48-byte output).
hkdf-sha512-extracthkdf-sha512-extract = fn [salt bytes, ikm bytes] bytesRFC 5869 HKDF-Extract using HMAC-SHA512.
hkdf-sha512-expandhkdf-sha512-expand = fn [prk bytes, info bytes, out_len i64] bytesRFC 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

SymbolSignatureDescription
keccak-f1600keccak-f1600 = fn [mut a block[i64]]Applies the 24-round Keccak-f[1600] permutation in-place to a 25-lane block[i64].
xof-squeezexof-squeeze = fn [mut sp Sponge, out_len i64] bytesSqueezes out_len bytes from an absorbed Sponge (can be called repeatedly for XOF streaming).
shake128-initshake128-init = fn [msg bytes] SpongeCreates a streaming SHAKE128 XOF sponge absorbed with msg.
shake256-initshake256-init = fn [msg bytes] SpongeCreates a streaming SHAKE256 XOF sponge absorbed with msg.
sha3-256sha3-256 = fn [msg bytes] bytesComputes the 32-byte FIPS 202 SHA3-256 digest of msg.
sha3-512sha3-512 = fn [msg bytes] bytesComputes the 64-byte FIPS 202 SHA3-512 digest of msg.
shake128shake128 = fn [msg bytes, out_len i64] bytesComputes out_len bytes of FIPS 202 SHAKE128 extendable output from msg.
shake256shake256 = fn [msg bytes, out_len i64] bytesComputes 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

SymbolSignatureDescription
bn-from-bebn-from-be = fn [b bytes] blockExported crypto/sig/bn-from-be operation.
bn-to-bebn-to-be = fn [a block, out_len i64] bytesExported crypto/sig/bn-to-be operation.
bn-cmpbn-cmp = fn [a block, b block] i64Exported crypto/sig/bn-cmp operation.
bn-addbn-add = fn [a block, b block] blockExported crypto/sig/bn-add operation.
bn-subbn-sub = fn [a block, b block] blockComputes a - b assuming a >= b.
bn-mulbn-mul = fn [a block, b block] blockFull multiplication a * b via Comba column accumulation (zero random-access writes).
bn-modbn-mod = fn [a block, m block] blockComputes a mod m via bit-by-bit shift-subtract (exact for any modulus size).
bn-mod-addbn-mod-add = fn [a block, b block, m block] blockExported crypto/sig/bn-mod-add operation.
bn-mod-subbn-mod-sub = fn [a block, b block, m block] blockExported crypto/sig/bn-mod-sub operation.
bn-mod-powbn-mod-pow = fn [base_in block, exp block, m_in block] anyComputes base^exp mod m (m odd) via Montgomery binary exponentiation.
rsa-pkcs1-sha256-verifyrsa-pkcs1-sha256-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] boolExported crypto/sig/rsa-pkcs1-sha256-verify operation.
rsa-pkcs1-sha384-verifyrsa-pkcs1-sha384-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] boolExported crypto/sig/rsa-pkcs1-sha384-verify operation.
rsa-pkcs1-sha512-verifyrsa-pkcs1-sha512-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] boolExported crypto/sig/rsa-pkcs1-sha512-verify operation.
rsa-pss-sha256-verifyrsa-pss-sha256-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] boolExported crypto/sig/rsa-pss-sha256-verify operation.
rsa-pss-sha384-verifyrsa-pss-sha384-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] boolVerifies an RSA-PSS + SHA-384 (0x0805 rsa_pss_rsae_sha384, 48-byte salt) signature.
rsa-pss-sha512-verifyrsa-pss-sha512-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] boolVerifies an RSA-PSS + SHA-512 (0x0806 rsa_pss_rsae_sha512, 64-byte salt) signature.
ecdsa-p256-verifyecdsa-p256-verify = fn [pk_point bytes, msg bytes, sig_der bytes] boolExported crypto/sig/ecdsa-p256-verify operation.
ecdsa-p384-verifyecdsa-p384-verify = fn [pk_point bytes, msg bytes, sig_der bytes] boolExported crypto/sig/ecdsa-p384-verify operation.
ecdsa-p256-pubkeyecdsa-p256-pubkey = fn [priv32 bytes] bytesDerives the 65-byte uncompressed SEC1 public key (0x04 || X(32) || Y(32)) from a 32-byte P-256 private scalar.
ecdhe-p256ecdhe-p256 = fn [priv32 bytes, peer_pub65 bytes] bytesComputes RFC 8446 Section 7.4.2 ECDHE P-256 (secp256r1, 0x0017) 32-byte shared secret X-coordinate.
ecdsa-p256-signecdsa-p256-sign = fn [priv32 bytes, msg bytes] bytesSigns msg with ECDSA P-256 / SHA-256 using RFC 6979 deterministic nonces, returning ASN.1 DER (r, s).
rsa-pss-sha256-signrsa-pss-sha256-sign = fn [mod_be bytes, priv_exp_be bytes, msg bytes, salt bytes] bytesSigns msg using RSA-PSS + SHA-256 (0x0804) with a 32-byte salt, returning a k-byte signature.
pkcs8-extract-private-keypkcs8-extract-private-key = fn [pkcs8_der bytes] bytesExtracts the inner private-key OCTET STRING from a PKCS#8 PrivateKeyInfo DER blob.
parse-private-key-derparse-private-key-der = fn [key_der bytes, label_hint str] anyParses 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 by slhdsa/keygen or slhdsa/keygen-deterministic.

Exported Functions

SymbolSignatureDescription
keygen-deterministickeygen-deterministic = fn [param enum, sk_seed bytes, sk_prf bytes, pk_seed bytes] KeyPairDeterministic FIPS 205 SLH-DSA key generation from three n-byte seeds (sk_seed, sk_prf, pk_seed).
keygenkeygen = fn [param enum] KeyPairGenerates a fresh SLH-DSA key pair using the OS/hardware CSPRNG.
sign-deterministicsign-deterministic = fn [param enum, sk bytes, msg bytes, opt_rand bytes] bytesDeterministic FIPS 205 SLH-DSA signing (empty pure-mode context) with explicit 16-byte opt_rand.
signsign = fn [param enum, sk bytes, msg bytes] bytesSigns msg with SLH-DSA using fresh hedged CSPRNG randomness.
verifyverify = fn [param enum, pk bytes, msg bytes, sig bytes] boolVerifies 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

SymbolSignatureDescription
x25519x25519 = fn [scalar bytes, u_bytes bytes] anyRFC 7748 X25519(k, u) -> 32-byte shared secret or public point.
x25519-basex25519-base = fn [scalar bytes] anyComputes X25519(scalar, 9) public key (32 bytes).
ed25519-pubkeyed25519-pubkey = fn [seed bytes] anyDerives the 32-byte RFC 8032 Ed25519 public key from a 32-byte seed.
ed25519-signed25519-sign = fn [seed bytes, msg bytes] anyProduces a 64-byte RFC 8032 Ed25519 signature over msg using 32-byte seed.
ed25519-sign-with-pked25519-sign-with-pk = fn [seed bytes, pk bytes, msg bytes] anyProduces a 64-byte RFC 8032 Ed25519 signature reusing a precomputed 32-byte pk.
ed25519-verifyed25519-verify = fn [pk bytes, msg bytes, sig bytes] boolVerifies an RFC 8032 Ed25519 signature (sig: 64B) on msg under pk (32B).

Module crypto/x509

Exported Functions

SymbolSignatureDescription
parse-certparse-cert = fn [cert_der bytes] anyParses one DER-encoded X.509 certificate into a structured validation record.
verify-sig-with-certverify-sig-with-cert = fn [signer map, sig_oid str, msg bytes, signature bytes] boolVerifies an arbitrary message+signature against a parsed certificate's public key.
verify-cert-issued-byverify-cert-issued-by = fn [child map, parent map] boolVerifies that parent issued and cryptographically signed child.
match-hostnamematch-hostname = fn [cert map, expected_host str] boolVerifies SAN DNS/IP or fallback CN identity against expected_host.
load-pem-rootsload-pem-roots = fn [pem_text str] anyParses a PEM trust bundle string containing one or more CERTIFICATE blocks.
builtin-roots-pembuiltin-roots-pem = fn [] strReturns 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-chainverify-chain = fn [chain_ders block, expected_host str, opts map] anyVerifies an X.509 certificate chain (leaf-first DER list) against hostname + validity window + PEM roots and/or SPKI SHA-256 pins.
mint-ed25519-certmint-ed25519-cert = fn [cfg map] anyMints 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-derencode-p256-pkcs8-der = fn [priv32 bytes] anyEncodes a 32-byte ECDSA P-256 private scalar as a standard PKCS#8 PrivateKeyInfo DER blob.
mint-p256-certmint-p256-cert = fn [cfg map] anyMints 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 }