std/digest/md5
std/digest/src/md5.trb
Md5, the MD5 of RFC 1321. Legacy: never for security. Collisions are cheap to produce (2004) and a chosen-
prefix collision is practical (2008) - nothing here signs with it, and nothing new should either. It survives only
where a protocol demands its exact bytes: Postgres's md5 authentication, S3's Content-MD5 header.
Ordinary TorbScript with no native, the same shape as Sha256 but little endian throughout: the words a block reads
and the length the padding ends with are least significant byte first, and so is the digest.
type Md5
type Md5 with Hasher
MD5, fed in pieces: Md5.add takes the next bytes and Md5.finished answers the digest of everything added so far
without changing the hasher, so a hasher can be read, fed more, and read again.
Examples
print Md5.of("abc".bytes()).hex()
// prints 900150983cd24fb0d6963f7d28e17f72
fn empty
static fn empty(): Self
A hasher with nothing fed yet, the same as Self().
fn of
static fn of(bytes: Bytes): Digest
The digest of bytes in one call.
fn blockSize
static fn blockSize(): Int
64: MD5 works in blocks of sixteen 32-bit words.
fn digestLength
static fn digestLength(): Int
16: an MD5 digest is 128 bits.
fn add
var fn add(bytes: Bytes)
Feeds the next bytes.
fn finished
fn finished(): Digest
The digest of everything added so far. The hasher itself is unchanged and may be fed more.