veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

crypto/kdf

lib/crypto/kdf.vk

lib/crypto/kdf.vk Pure-Veko key & password derivation functions: RFC 2898 PBKDF2-HMAC-SHA256 and RFC 9106 Argon2id. Zero capabilities required.

signature
pbkdf2-sha256 = fn [password bytes, salt bytes, iters i64, dk_len i64] bytes

Derives dk_len bytes using PBKDF2-HMAC-SHA256 (iters >= 1).

Executable Example
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 ]
signature
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).

Executable Example
veko
use [kdf = crypto/kdf]
d1 = kdf/argon2id (bytes/from-str 'correct horse') (bytes/from-str '0123456789abcdef') 8 1 32
d2 = kdf/argon2id (bytes/from-str 'correct horse') (bytes/from-str '0123456789abcdef') 8 1 32
if (len d1) != 32 or (not (kdf/verify-tag d1 d2)) [ err 'argon2id mismatch' ] else [ .ok ]
signature
verify-tag = fn [a bytes, b bytes] bool

Constant-time comparison for derived tags/hashes.