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

crypto/sha3

lib/crypto/sha3.vk

lib/crypto/sha3.vk Pure-Veko FIPS 202 Keccak-f[1600], SHA3-256, SHA3-512, SHAKE128, and SHAKE256 XOF. Zero capabilities required.

Sponge struct
signature
Sponge = struct { state block[i64], rate i64, pos i64 }

Streaming Keccak-1600 sponge state (used by SHA3 and SHAKE128/256 XOFs, including NIST PQC).

signature
keccak-f1600 = fn [mut a block[i64]]

Applies the 24-round Keccak-f[1600] permutation in-place to a 25-lane block[i64].

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

signature
shake128-init = fn [msg bytes] Sponge

Creates a streaming SHAKE128 XOF sponge absorbed with msg.

signature
shake256-init = fn [msg bytes] Sponge

Creates a streaming SHAKE256 XOF sponge absorbed with msg.

signature
sha3-256 = fn [msg bytes] bytes

Computes the 32-byte FIPS 202 SHA3-256 digest of msg.

Executable Example
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 ]
signature
sha3-512 = fn [msg bytes] bytes

Computes the 64-byte FIPS 202 SHA3-512 digest of msg.

Executable Example
veko
use [s3 = crypto/sha3, hex = codec/hex]
h = hex/encode (s3/sha3-512 (bytes/with-cap 0))
if h[0..16] != 'a69f73cca23a9ac5' [ err 'sha3-512 vector mismatch' ] else [ .ok ]
signature
shake128 = fn [msg bytes, out_len i64] bytes

Computes out_len bytes of FIPS 202 SHAKE128 extendable output from msg.

Executable Example
veko
use [s3 = crypto/sha3, hex = codec/hex]
h = hex/encode (s3/shake128 (bytes/with-cap 0) 32)
if h != '7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26' [
  err 'shake128 vector mismatch'
] else [ .ok ]
signature
shake256 = fn [msg bytes, out_len i64] bytes

Computes out_len bytes of FIPS 202 SHAKE256 extendable output from msg.

Executable Example
veko
use [s3 = crypto/sha3, hex = codec/hex]
h = hex/encode (s3/shake256 (bytes/with-cap 0) 32)
if h != '46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762f' [
  err 'shake256 vector mismatch'
] else [ .ok ]