shithub: mc

ref: bd96cb6a0a361a62871f70c07fc350bc2264b087
dir: /lib/crypto/test/md5.myr/

View raw version
use std
use crypto

const main = {
	hasheq(crypto.md5("")[:], \
		"d41d8cd98f00b204e9800998ecf8427e")
	hasheq(crypto.md5("h")[:], \
		"2510c39011c5be704182423e3a695e91")
	/* 64 byte block */
	hasheq(crypto.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
		"014842d480b571495a4a0363793f7367")
	/* tail spanning */
	hasheq(crypto.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
		"3b0bb4c5ece4a6568caa7266e740a140")
}

const hasheq = {got, expected
	var sb, str

	sb = std.mksb()
	for x : got
		std.sbfmt(sb, "{p=0,w=2,x}", x)
	;;
	str = std.sbfin(sb)
	if (!std.sleq(str, expected))
		std.fatal("mismatched hashes:\n\tgot:\t{}\n\texpected:\t{}\n", str, expected)
	;;
	std.slfree(str)
}