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

crypto/sha256

lib/crypto/sha256.vk

lib/crypto/sha256.vk Pure-Veko RFC 6234 SHA-256 / SHA-512, RFC 2104 HMAC-SHA256, and RFC 5869/8446 HKDF.

u32 fn
signature
u32 = fn [x i64] i64
signature
sha256 = fn [msg bytes] bytes

Computes the 32-byte SHA-256 digest of msg.

Executable Example
veko
use [s2 = crypto/sha256]
if (s2/to-hex (s2/sha256 (bytes/from-str 'abc'))) != 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' [
  err 'sha256 vector mismatch'
] else [ .ok ]
signature
Sha256State = struct { h block[i64], buf bytes, total i64 = ... }

Streaming SHA-256 hash state.

signature
sha256-init = fn [] Sha256State
signature
sha256-update = fn [mut st Sha256State, data bytes]
signature
sha256-digest = fn [st Sha256State] bytes
signature
sha512 = fn [msg bytes] bytes

Computes the 64-byte SHA-512 digest of msg (used by Ed25519).

signature
hmac-sha256 = fn [key bytes, data bytes] bytes
signature
hkdf-extract = fn [salt bytes, ikm bytes] bytes
signature
hkdf-expand = fn [prk bytes, info bytes, out_len i64] bytes
signature
hkdf-expand-label = fn [secret bytes, label str, context bytes, out_len i64] bytes
signature
derive-secret = fn [secret bytes, label str, transcript_hash bytes] bytes
signature
ct-eq = fn [a bytes, b bytes] bool
signature
to-hex = fn [data bytes] str
signature
sha384 = fn [msg bytes] bytes

Computes the 48-byte FIPS 180-4 SHA-384 digest of msg.

Executable Example
veko
use [s2 = crypto/sha256]
h = s2/to-hex (s2/sha384 (bytes/from-str 'abc'))
if h != 'cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7' [
  err 'sha384 vector mismatch'
] else [ .ok ]
signature
hmac-sha384 = fn [key bytes, data bytes] bytes

Computes RFC 2104 HMAC-SHA384 (48-byte MAC).

signature
hmac-sha512 = fn [key bytes, data bytes] bytes

Computes RFC 2104 HMAC-SHA512 (64-byte MAC).

signature
hkdf-sha384-extract = fn [salt bytes, ikm bytes] bytes

RFC 5869 HKDF-Extract using HMAC-SHA384.

signature
hkdf-sha384-expand = fn [prk bytes, info bytes, out_len i64] bytes

RFC 5869 HKDF-Expand using HMAC-SHA384.

signature
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).

signature
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).

signature
hkdf-sha512-extract = fn [salt bytes, ikm bytes] bytes

RFC 5869 HKDF-Extract using HMAC-SHA512.

signature
hkdf-sha512-expand = fn [prk bytes, info bytes, out_len i64] bytes

RFC 5869 HKDF-Expand using HMAC-SHA512.