Skip to content
heff

std.md5

MD5, the hash of RFC 1321: any bytes to 16 bytes. It is broken (bytes of the same MD5 are made at will): it is here for what still names or checks things by it, not to tell bytes that may have been made to collide apart — that is std.sha256’s. Written in heff, a block of 64 bytes at a time.

import bytes as Bytes
import std.md5 as MD5
-- | whether a download is what its published MD5 says
intact : Bytes -> Bytes -> Bool
intact content published = MD5.digest content == published

digest

digest : Bytes -> Bytes

The MD5 hash of the bytes, 16 bytes.

>>> digest Bytes.empty == b[0xd41d8cd98f00b204::64, 0xe9800998ecf8427e::64]
True
>>> digest (Bytes.fromString "a") == b[0x0cc175b9c0f1b6a8::64, 0x31c399e269772661::64]
True
>>> digest (Bytes.fromString "abc") == b[0x900150983cd24fb0::64, 0xd6963f7d28e17f72::64]
True
>>> digest (Bytes.fromString "message digest") == b[0xf96b697d7cb7938d::64, 0x525a2f31aaf161d0::64]
True
>>> digest (Bytes.fromString "abcdefghijklmnopqrstuvwxyz") == b[0xc3fcd3d76192e400::64, 0x7dfb496cca67e13b::64]
True
>>> digest (Bytes.fromString "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") == b[0xd174ab98d277d9f5::64, 0xa5611c2c9f419d9f::64]
True
>>> digest (Bytes.fromString "12345678901234567890123456789012345678901234567890123456789012345678901234567890") == b[0x57edf4a22be3c955::64, 0xac49da2e2107b67a::64]
True