Skip to main content

Module hash

Module hash 

Source
Expand description

Cryptographic hash primitives — MD5 (RFC 1321) and SHA-1 (RFC 3174), rolled in pure Rust.

The REFERENCE ORACLE. MD5 and SHA-1 (the hashes RFC 9562 defines UUID v3/v5 on) are written in the LOGOS language (crates/logicaffeine_compile/assets/std/uuid.lg: md5Digest/sha1Digest, which the md5/sha1/uuid_v3/uuid_v5 stdlib functions call) and compile to native through the Futamura pipeline — that is the language’s implementation. These pure-Rust versions are the independent oracle the Logos ones are proven byte-exact against (here and cross-tier), NOT on any language path. (SHA-3/Keccak is the modern hash and lives in logicaffeine_system.)

Both are block functions over 64-byte chunks with the standard Merkle–Damgård padding. They are NOT for security (MD5 and SHA-1 are both broken against collision attacks). Validated bit-exact against the md-5/sha1 reference crates (known RFC vectors + differential fuzz) in the tests.

Functions§

md5
MD5 digest of data (RFC 1321) — 16 bytes.
md5_x4
MD5 of FOUR equal-length messages at once — 4-way SSE2 multi-buffer, the high-throughput path for hashing many same-size records (bulk name-based ids, dedup keys, content addresses). All four ABCD states advance in one __m128i (lane j = message j), so ~4× a scalar MD5 per message. The four inputs MUST share a length; returns the four 16-byte digests, byte-identical to md5 per lane.
md5_x8
MD5 of EIGHT equal-length messages at once — AVX2 8-way multi-buffer, twice the width of md5_x4. All eight ABCD states advance in one __m256i (lane j = message j). Falls back to two md5_x4 passes without AVX2. Byte-identical to md5 per lane; the high-throughput path for hashing many same-size records (bulk name-based ids, dedup/content keys).
sha1
SHA-1 digest of data (RFC 3174) — 20 bytes.
to_hex
Lowercase hex of a digest — handy for tests and debugging.