crypto/sha256
lib/crypto/sha256.vklib/crypto/sha256.vk Pure-Veko RFC 6234 SHA-256 / SHA-512, RFC 2104 HMAC-SHA256, and RFC 5869/8446 HKDF.
u32 = fn [x i64] i64
sha256 = fn [msg bytes] bytes
Computes the 32-byte SHA-256 digest of msg.
Executable Example
use [s2 = crypto/sha256]
if (s2/to-hex (s2/sha256 (bytes/from-str 'abc'))) != 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' [
err 'sha256 vector mismatch'
] else [ .ok ]
Sha256State = struct { h block[i64], buf bytes, total i64 = ... }
Streaming SHA-256 hash state.
sha256-init = fn [] Sha256State
sha256-update = fn [mut st Sha256State, data bytes]
sha256-digest = fn [st Sha256State] bytes
hmac-sha256 = fn [key bytes, data bytes] bytes
hkdf-extract = fn [salt bytes, ikm bytes] bytes
hkdf-expand = fn [prk bytes, info bytes, out_len i64] bytes
hkdf-expand-label = fn [secret bytes, label str, context bytes, out_len i64] bytes
derive-secret = fn [secret bytes, label str, transcript_hash bytes] bytes
ct-eq = fn [a bytes, b bytes] bool
to-hex = fn [data bytes] str
sha384 = fn [msg bytes] bytes
Computes the 48-byte FIPS 180-4 SHA-384 digest of msg.
Executable Example
use [s2 = crypto/sha256]
h = s2/to-hex (s2/sha384 (bytes/from-str 'abc'))
if h != 'cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7' [
err 'sha384 vector mismatch'
] else [ .ok ]
hmac-sha384 = fn [key bytes, data bytes] bytes
Computes RFC 2104 HMAC-SHA384 (48-byte MAC).
hmac-sha512 = fn [key bytes, data bytes] bytes
Computes RFC 2104 HMAC-SHA512 (64-byte MAC).
hkdf-sha384-extract = fn [salt bytes, ikm bytes] bytes
RFC 5869 HKDF-Extract using HMAC-SHA384.
hkdf-sha384-expand = fn [prk bytes, info bytes, out_len i64] bytes
RFC 5869 HKDF-Expand using HMAC-SHA384.
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 = 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 = fn [salt bytes, ikm bytes] bytes
RFC 5869 HKDF-Extract using HMAC-SHA512.
hkdf-sha512-expand = fn [prk bytes, info bytes, out_len i64] bytes
RFC 5869 HKDF-Expand using HMAC-SHA512.