Manuscript Documentation
v2026.12.0

@std/crypto/hash.ms#

Import each required symbol with import Name from "@std/crypto/hash.ms".

Crc64 Type#

A 64-bit CRC built from ordered chunks, retaining no input bytes. Initial register and final XOR are all ones. var sum = Crc64(Crc64Polynomial.Ecma) then sum.update("123456789".to_bytes()) gives sum.value() = 11051210869376104954. Reading the value does not reset it. It detects accidental corruption; it does not authenticate data.

Manuscript
type Crc64 {
    polynomial Crc64Polynomial
    state Int = 0
}

Crc64.polynomial#

The polynomial this checksum uses.

Manuscript
polynomial Crc64Polynomial

Crc64.state#

Register state, stored complemented so the empty checksum is zero.

Manuscript
state Int = 0

Crc64.update#

Appends these bytes to the checksum; an empty chunk leaves it unchanged.

Manuscript
var fn update(data Bytes) Void

Crc64.value#

Returns the current checksum without resetting or otherwise changing it.

Manuscript
fn value() UInt64

Crc64Polynomial Enum#

Selects the polynomial of a 64-bit cyclic redundancy check.

Manuscript
enum Crc64Polynomial {
    Ecma
    Iso
}

Crc64Polynomial.Ecma#

CRC-64/XZ (ECMA-182, reflected 0xC96C5795D7870F42), as used by xz and Go’s crc64.ECMA.

Manuscript
Ecma

Crc64Polynomial.Iso#

CRC-64/GO-ISO (reflected 0xD800000000000000), Go’s crc64.ISO.

Manuscript
Iso

Crc64Polynomial.reflected#

The reflected polynomial as an Int bit pattern.

Manuscript
fn reflected() Int

MapHash Type#

A seeded, non-cryptographic 64-bit hash for hash tables and sharding. Equal seeds hash equal bytes to equal values on every platform; random_seed() draws a fresh seed per call, so hash values are not stable across runs. Do not use it to authenticate data or defend against chosen input. table_hash := MapHash(seed: random_seed()) then table_hash.hash("key".to_bytes()) buckets keys unpredictably.

Manuscript
type MapHash {
    seed Int
}

MapHash.seed#

The seed mixed into every hash.

Manuscript
seed Int

MapHash.hash#

Hashes the bytes with this seed. A final 64-bit avalanche step makes every output bit depend on all input bits.

Manuscript
fn hash(data Bytes) UInt64

MapHash.hash_string#

Hashes a string’s UTF-8 bytes with this seed.

Manuscript
fn hash_string(text String) UInt64

crc64 Function#

Computes the CRC-64 of data for polynomial. crc64(Crc64Polynomial.Ecma, "123456789".to_bytes()) returns 11051210869376104954 (0x995DC9BBDF1939FA).

Manuscript
fn crc64(polynomial Crc64Polynomial, data Bytes) UInt64 { ... }

crc64_of Function#

Reads input to the end and returns the CRC-64 of all its bytes with the given polynomial, as crc64 does for bytes in hand. Retains no input bytes, and consumes and closes the stream. A failed read returns its error.

Manuscript
fn crc64_of(move input ReadStream[Bytes], polynomial Crc64Polynomial) Result[UInt64, Error] { ... }

fnv1_32 Function#

Hashes data with 32-bit FNV-1, which multiplies before it XORs in each byte. fnv1_32("a".to_bytes()) returns 84696446 (0x050C5D7E).

Manuscript
fn fnv1_32(data Bytes) UInt32 { ... }

fnv1_64 Function#

Hashes data with 64-bit FNV-1, which multiplies before it XORs in each byte. fnv1_64("a".to_bytes()) returns 12638153115695167422 (0xAF63BD4C8601B7BE).

Manuscript
fn fnv1_64(data Bytes) UInt64 { ... }

fnv1a32 Function#

Hashes data with 32-bit FNV-1a (offset 2166136261, prime 16777619). These hashes spread keys over buckets; they detect nothing adversarial and authenticate nothing. fnv1a32("a".to_bytes()) returns 3826002220 (0xE40C292C).

Manuscript
fn fnv1a32(data Bytes) UInt32 { ... }

fnv1a64 Function#

Hashes data with 64-bit FNV-1a (offset 14695981039346656037, prime 1099511628211). fnv1a64("a".to_bytes()) returns 12638187200555641996 (0xAF63DC4C8601EC8C).

Manuscript
fn fnv1a64(data Bytes) UInt64 { ... }

random_seed Function#

Returns an unpredictable seed from the operating system.

Manuscript
fn random_seed() Int { ... }