crypto
Hashing & digest functions (SHA-256, MD5).
MVP scope : SHA-256 and MD5, for content fingerprinting and integrity
checking. SHA-256 is a real cryptographic hash and reproduces
shasum -a 256 ; MD5 is kept for legacy interop only: it is
collision-broken, so never rely on it where collision resistance matters.
Neither is a password hash : for credentials use a dedicated KDF
(bcrypt / scrypt / argon2 when those land).
Pure Vader at runtime, zero runtime host imports: WASM-ready as-is. (The MD5
round constants are computed at compile time via std/math; that builder is
dead-code-eliminated from the runtime image after baking.) Operates on
the UTF-8 byte view (bytes()) of the input ; output is the
lowercase hex digest, matching the convention of every other tool (openssl,
shasum, md5sum, GitHub commit hashes…).
Both algorithms run in O(n) over the input length and use only
fixed-size scratch ; safe for streaming-sized inputs once a
chunked API lands (Sha256.update(bytes) / .finalize():
post-MVP).
Functions
sha256 :: fn(input: string | u8[]) -> string SHA-256 hash of input, returned as a 64-char lowercase hex string.
Operates on the UTF-8 bytes of the source string ; non-ASCII content
hashes consistently with shasum -a 256 provided the caller hasn't
re-encoded the input upstream.
Parameters
| input | string | u8[] | No description. |
Returns
string sha256_bytes :: fn(input: string | u8[]) -> u8[] SHA-256 digest as the raw 32-byte hash: the byte-level core that sha256
hex-encodes and hmac_sha256 chains. Use this when a downstream primitive
(HMAC, a key-derivation step, a binary protocol field) needs the bytes
rather than the hex rendering. Accepts a string (hashed as its UTF-8
bytes) or raw bytes (u8[], s.bytes()).
Parameters
| input | string | u8[] | the message : a string or a u8[] (e.g. s.bytes()). |
Returns
u8[] the 32-byte big-endian digest.hex_of_bytes :: fn(bytes: u8[]) -> string Lowercase hex rendering of a byte sequence: two hex digits per byte.
The inverse-free companion to the raw-digest APIs (sha256_bytes,
hmac_sha256).
Parameters
| bytes | u8[] | the bytes to render. |
Returns
string a 2 * bytes.len()-char lowercase hex string.hmac_sha256 :: fn(key: string | u8[], msg: string | u8[]) -> u8[] HMAC-SHA256 (RFC 2104) of msg under key, as the raw 32-byte MAC.
A key longer than the 64-byte block is first hashed down; a shorter key is
zero-padded to the block. Key and message each accept a string or raw
bytes ; hex-render the result with hex_of_bytes when a string is wanted.
Parameters
| key | string | u8[] | the secret key : a string or raw bytes (u8[]). |
| msg | string | u8[] | the message : a string or raw bytes. |
Returns
u8[] the 32-byte HMAC.md5 :: fn(input: string) -> string MD5 hash of input, returned as a 32-char lowercase hex string.
MD5 is cryptographically broken: do NOT use for digital signatures
or password storage. Still ubiquitous for file integrity checks and
content addressing where collision resistance against an adversary
isn't required.
Parameters
| input | string | No description. |
Returns
string