shithub: mc

ref: 3665783a1d1fe03db70cca452c615b439310a329
dir: /lib/crypto/test/sha256.myr/

View raw version
use std
use crypto

const main = {
	hasheq(crypto.sha224("")[:], \
		"d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f")
	hasheq(crypto.sha224("h")[:], \
		"e0ccaeadfef916630c35576679e4cd4b438e7fc95a60b7361705f708")
	/* 64 byte block */
	hasheq(crypto.sha224("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
		"a88cd5cde6d6fe9136a4e58b49167461ea95d388ca2bdb7afdc3cbf4")
	/* tail spanning */
	hasheq(crypto.sha224("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
		"4a5859b7efa22c3b25710520fc97b0a901f5cdba3e4f0becfeea725e")

	hasheq(crypto.sha256("")[:], \
		"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
	hasheq(crypto.sha256("h")[:], \
		"aaa9402664f1a41f40ebbc52c9993eb66aeb366602958fdfaa283b71e64db123")
	/* 64 byte block */
	hasheq(crypto.sha256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
		"ffe054fe7ae0cb6dc65c3af9b61d5209f439851db43d0ba5997337df154668eb")
	/* tail spanning */
	hasheq(crypto.sha256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
		"bac8bf0f9794a520a5bf0ec64d3206edd1b9f2ef5ea118c9cad5365d84578de4")
}

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.eq(str, expected))
		std.fatal("mismatched hashes:\n\tgot:\t{}\n\texpected:\t{}\n", str, expected)
	;;
	std.slfree(str)
}