hash

Content-addressable hashing — fixed-length digests of arbitrary byte payloads. Four algorithms: SHA-256 (the content-addressing default), SHA-384, SHA-512, and BLAKE3 (with arbitrary-length XOF output). Covers integrity and content addressing, not password hashing or keyed operations — those belong to `cx-stdlib/crypto`. Digests convert to lowercase hex, URL-safe base64, or base32, and carry SRI helpers for module-lockfile integrity.

hash:sha256

[$hash:sha256] -> bytes — Compute the SHA-256 digest (32 bytes) of the input — the CX content-addressing default.

            [?lib 'cx-stdlib/hash']
[$hash:format-hex [$hash:sha256 "abc"]]
          
            'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
          

hash:sha384

[$hash:sha384] -> bytes — Compute the SHA-384 digest (48 bytes) of the input.

            [?lib 'cx-stdlib/hash']
[$hash:sri-format [$hash:sha384 "hi"] "sha384"]
          
            'sha384-B5EAbfgShHckT1PQ/c4hDbgfVXV1EOJqzuNcGKa86qKNzbv9bcBBubTcextU439S'
          

hash:sha512

[$hash:sha512] -> bytes — Compute the SHA-512 digest (64 bytes) of the input.

            [?lib 'cx-stdlib/hash']
[$hash:format-hex [$hash:sha512 "abc"]]
          
            'ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f'
          

hash:blake3

[$hash:blake3] -> bytes — Compute the BLAKE3 digest (32-byte default) of the input.

            [?lib 'cx-stdlib/hash']
[$hash:equals [$hash:blake3-string "abc"] [$hash:blake3 "abc"]]
          
            true
          

hash:blake3-xof

[$hash:blake3-xof] -> bytes — Compute a BLAKE3 digest of arbitrary length (XOF mode), producing `out-length` bytes.

            [?lib 'cx-stdlib/hash']
[$hash:format-hex [$hash:blake3-xof "abc" 1]]
          
            '64'
          

hash:sha256-hex

[$hash:sha256-hex] -> string — Compute the SHA-256 digest and return it directly as a lowercase hex string.

            [?lib 'cx-stdlib/hash']
[$hash:sha256-hex ""]
          
            'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
          

hash:sha384-hex

[$hash:sha384-hex] -> string — Compute the SHA-384 digest and return it directly as a lowercase hex string.

            [?lib 'cx-stdlib/hash']
[$hash:sha384-hex ""]
          
            '38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b'
          

hash:sha512-hex

[$hash:sha512-hex] -> string — Compute the SHA-512 digest and return it directly as a lowercase hex string.

            [?lib 'cx-stdlib/hash']
[$hash:sha512-hex ""]
          
            'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e'
          

hash:blake3-hex

[$hash:blake3-hex] -> string — Compute the BLAKE3 digest and return it directly as a lowercase hex string.

            [?lib 'cx-stdlib/hash']
[$hash:blake3-hex ""]
          
            'af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262'
          

hash:sha256-string

[$hash:sha256-string] -> bytes — Compute the SHA-256 digest of UTF-8 string input.

            [?lib 'cx-stdlib/hash']
[$hash:equals [$hash:sha256-string "abc"] [$hash:sha256 "abc"]]
          
            true
          

hash:blake3-string

[$hash:blake3-string] -> bytes — Compute the BLAKE3 digest of UTF-8 string input.

            [?lib 'cx-stdlib/hash']
[$hash:equals [$hash:blake3-string "abc"] [$hash:blake3 "abc"]]
          
            true
          

hash:hasher-new

[$hash:hasher-new] -> element — Create a streaming hasher for the named algorithm (sha256/sha384/sha512/blake3).

            [?lib 'cx-stdlib/hash']
[$hash:format-hex [$hash:hasher-finalize [$hash:hasher-update [$hash:hasher-update [$hash:hasher-new "sha256"] "ab"] "c"]]]
          
            'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
          

hash:hasher-update

[$hash:hasher-update] -> element — Feed a chunk into a streaming hasher, returning a new hasher with the chunk absorbed.

            [?lib 'cx-stdlib/hash']
[$hash:format-hex [$hash:hasher-finalize [$hash:hasher-update [$hash:hasher-update [$hash:hasher-new "sha256"] "ab"] "c"]]]
          
            'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
          

hash:hasher-finalize

[$hash:hasher-finalize] -> bytes — Finish a streaming hasher and return the digest of all absorbed chunks.

            [?lib 'cx-stdlib/hash']
[$hash:format-hex [$hash:hasher-finalize [$hash:hasher-update [$hash:hasher-update [$hash:hasher-new "sha256"] "ab"] "c"]]]
          
            'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
          

hash:format-hex

[$hash:format-hex] -> string — Encode a digest as a lowercase hex string.

            [?lib 'cx-stdlib/hash']
[$hash:format-hex [$hash:sha256 "abc"]]
          
            'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
          

hash:format-base64-url

[$hash:format-base64-url] -> string — Encode a digest as URL-safe base64 with no padding.

            [?lib 'cx-stdlib/hash']
[$hash:format-base64-url [$hash:parse-hex "deadbeef"]]
          
            '3q2-7w'
          

hash:format-base32

[$hash:format-base32] -> string — Encode a digest as RFC 4648 uppercase base32.

            [?lib 'cx-stdlib/hash']
[$hash:format-base32 [$hash:parse-hex "deadbeef"]]
          
            '32W353Y='
          

hash:parse-hex

[$hash:parse-hex] -> bytes — Decode a hex string to bytes, accepting either case.

            [?lib 'cx-stdlib/hash']
[$hash:equals [$hash:blake3-xof "abc" 1] [$hash:parse-hex "64"]]
          
            true
          

hash:parse-base64-url

[$hash:parse-base64-url] -> bytes — Decode a URL-safe base64 string to bytes.

            [?lib 'cx-stdlib/hash']
[?let [= $d [$hash:sha256 "payload"]] [$hash:equals [$hash:parse-base64-url [$hash:format-base64-url $d]] $d]]
          
            true
          

hash:equals

[$hash:equals] -> bool — Compare two byte sequences for equality in constant time, resisting timing attacks.

            [?lib 'cx-stdlib/hash']
[$hash:equals [$hash:sha256-string "abc"] [$hash:sha256 "abc"]]
          
            true
          

hash:sri-format

[$hash:sri-format] -> string — Format a digest as a W3C Subresource Integrity string (`-`).

            [?lib 'cx-stdlib/hash']
[$hash:sri-format [$hash:sha384 "hi"] "sha384"]
          
            'sha384-B5EAbfgShHckT1PQ/c4hDbgfVXV1EOJqzuNcGKa86qKNzbv9bcBBubTcextU439S'
          

hash:sri-parse

[$hash:sri-parse] -> element — Parse a W3C SRI string into an `[sri algo=… digest=…]` element.

            [?lib 'cx-stdlib/hash']
[?let [= $p [$hash:sri-parse [$hash:sri-format [$hash:sha384 "hi"] "sha384"]]] $p@algo]
          
            'sha384'