Module crypto/md5
MD5 hash function (RFC 1321), pure Yo implementation. MD5 is considered cryptographically broken — use SHA-256 for security.
Example
{ md5_hex } :: import("std/crypto/md5");
digest := md5_hex(data); // "5d41402abc4b2a76b9719d911017c592"
Stability
unstable, with a concrete structural blocker: the one-shot md5 is a
SECOND, open-coded implementation of the algorithm, where sha1,
sha256 and sha512's one-shots all delegate to their streaming type.
Two code paths compute MD5 in this file and they agree only because
tests/crypto/digest.test.yo asserts that they do. Collapsing md5
onto Md5.new().update(data).finish() is the obvious fix and it
changes nothing observable, so it should happen before anything here is
frozen. Beyond that, the same open question as std/crypto/sha1: MD5
is broken and the API gives a new caller no signal that it is the
legacy option.
Types
MD5 streaming state (the Sha256 skeleton; little-endian length + little-endian digest extraction).
Fields
| Name | Type | Description |
|---|---|---|
_h | Array(u32, 4) | |
_buf | Array(u8, 64) | |
_buflen | usize | |
_total | u64 |
Trait Implementations
impl(Md5, ...)
new : (Md5) fn() -> Md5A hasher seeded with the RFC 1321 initial state.
Returns: Md5
update : (Md5) fn(self : Md5, data : ArrayList(u8)) -> Md5finish : (Md5) fn(self : Md5) -> Array(u8, 16)Append the padding and the little-endian bit length, fold the last block in, and return the 16-byte digest.
Single use — the padding is written into the hasher's own buffer,
so a second finish digests the padded state rather than the
message.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Md5 |
Returns: Array(u8, 16)
impl(Md5, Digest(...))
new : (Md5) fn() -> Md5A hasher seeded with the RFC 1321 initial state.
Returns: Md5
update : (Md5) fn(self : Md5, data : ArrayList(u8)) -> Md5digest_size : (Md5) fn() -> usizeThe digest length in bytes (32/64/20/16).
Returns: usize
block_size : (Md5) fn() -> usizeThe compression block size in bytes (64, or 128 for SHA-512) — what HMAC pads keys to.
Returns: usize
Functions
MD5 of data in one call — the 16-byte digest.
Broken. Collisions are minutes of laptop time (RFC 6151), so this
answers "did this file change by accident" and never "is this the file
I was promised". Use sha256 for anything an attacker can influence.
It stays for legacy interop: S3 ETags, old package manifests,
HMAC-MD5 in pre-2010 protocols.
Computed by an open-coded loop rather than by driving Md5 — the two
paths in this file agree, and tests/crypto/digest.test.yo is what
keeps them agreeing.
Parameters
| Name | Type | Notes |
|---|---|---|
data | ArrayList(u8) |
Returns: Array(u8, usize(16))