summaryrefslogtreecommitdiff
path: root/lib/cryptohash/test
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cryptohash/test')
-rw-r--r--lib/cryptohash/test/md5.myr18
-rw-r--r--lib/cryptohash/test/sha1.myr18
-rw-r--r--lib/cryptohash/test/sha256.myr29
-rw-r--r--lib/cryptohash/test/sha512.myr29
-rw-r--r--lib/cryptohash/test/util.myr19
5 files changed, 113 insertions, 0 deletions
diff --git a/lib/cryptohash/test/md5.myr b/lib/cryptohash/test/md5.myr
new file mode 100644
index 0000000..42d1089
--- /dev/null
+++ b/lib/cryptohash/test/md5.myr
@@ -0,0 +1,18 @@
+use std
+use cryptohash
+
+use "test/util.use"
+
+const main = {
+ hasheq(cryptohash.md5("")[:], \
+ "d41d8cd98f00b204e9800998ecf8427e")
+ hasheq(cryptohash.md5("h")[:], \
+ "2510c39011c5be704182423e3a695e91")
+ /* 64 byte block */
+ hasheq(cryptohash.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
+ "014842d480b571495a4a0363793f7367")
+ /* tail spanning */
+ hasheq(cryptohash.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
+ "3b0bb4c5ece4a6568caa7266e740a140")
+}
+
diff --git a/lib/cryptohash/test/sha1.myr b/lib/cryptohash/test/sha1.myr
new file mode 100644
index 0000000..d2ccfb8
--- /dev/null
+++ b/lib/cryptohash/test/sha1.myr
@@ -0,0 +1,18 @@
+use std
+use cryptohash
+
+use "test/util.use"
+
+const main = {
+ hasheq(cryptohash.sha1("")[:], \
+ "da39a3ee5e6b4b0d3255bfef60951890d8af0709")
+ hasheq(cryptohash.sha1("h")[:], \
+ "27d5482eebd075de44389774e2fc8c695cf48a75")
+ /* 64 byte block */
+ hasheq(cryptohash.sha1("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
+ "0098ba824b5c16427bd7a1125a2a442aec25644d")
+ /* tail spanning */
+ hasheq(cryptohash.sha1("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
+ "4eb17e52bb55910b037869438f69d9c87643d75a")
+}
+
diff --git a/lib/cryptohash/test/sha256.myr b/lib/cryptohash/test/sha256.myr
new file mode 100644
index 0000000..e3981b4
--- /dev/null
+++ b/lib/cryptohash/test/sha256.myr
@@ -0,0 +1,29 @@
+use std
+use cryptohash
+
+use "test/util.use"
+
+const main = {
+ hasheq(cryptohash.sha224("")[:], \
+ "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f")
+ hasheq(cryptohash.sha224("h")[:], \
+ "e0ccaeadfef916630c35576679e4cd4b438e7fc95a60b7361705f708")
+ /* 64 byte block */
+ hasheq(cryptohash.sha224("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
+ "a88cd5cde6d6fe9136a4e58b49167461ea95d388ca2bdb7afdc3cbf4")
+ /* tail spanning */
+ hasheq(cryptohash.sha224("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
+ "4a5859b7efa22c3b25710520fc97b0a901f5cdba3e4f0becfeea725e")
+
+ hasheq(cryptohash.sha256("")[:], \
+ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
+ hasheq(cryptohash.sha256("h")[:], \
+ "aaa9402664f1a41f40ebbc52c9993eb66aeb366602958fdfaa283b71e64db123")
+ /* 64 byte block */
+ hasheq(cryptohash.sha256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
+ "ffe054fe7ae0cb6dc65c3af9b61d5209f439851db43d0ba5997337df154668eb")
+ /* tail spanning */
+ hasheq(cryptohash.sha256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
+ "bac8bf0f9794a520a5bf0ec64d3206edd1b9f2ef5ea118c9cad5365d84578de4")
+}
+
diff --git a/lib/cryptohash/test/sha512.myr b/lib/cryptohash/test/sha512.myr
new file mode 100644
index 0000000..f58f96e
--- /dev/null
+++ b/lib/cryptohash/test/sha512.myr
@@ -0,0 +1,29 @@
+use std
+use cryptohash
+
+use "test/util.use"
+
+const main = {
+ hasheq(cryptohash.sha384("")[:], \
+ "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b")
+ hasheq(cryptohash.sha384("h")[:], \
+ "a4eb0778c79fce94c02126543cba398d645b2fd4c6ff6a02eecc026bbe0cc0dd666279722b7615bc15b4c9126b941c04")
+ /* 64 byte block */
+ hasheq(cryptohash.sha384("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
+ "2e404b9339da795776e510d96930b3be2904c500395b8cb7413334b82d4dec413b4b8113045a05bbbcff846f027423f6")
+ /* tail spanning */
+ hasheq(cryptohash.sha384("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
+ "f8f4b55a0fb1ac8506d2e5195c714a1ad16c3bf61ad8b2d544344b105a49a77ff3b8eb61e8f970a71864e9dad87042b1")
+
+ hasheq(cryptohash.sha512("")[:], \
+ "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e")
+ hasheq(cryptohash.sha512("h")[:], \
+ "2241bc8fc70705b42efead371fd4982c5ba69917e5b4b895810002644f0386da9c3131793458c2bf47608480d64a07278133c99912e0ba2daf23098f3520eb97")
+ /* 64 byte block */
+ hasheq(cryptohash.sha512("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
+ "01d35c10c6c38c2dcf48f7eebb3235fb5ad74a65ec4cd016e2354c637a8fb49b695ef3c1d6f7ae4cd74d78cc9c9bcac9d4f23a73019998a7f73038a5c9b2dbde")
+ /* tail spanning */
+ hasheq(cryptohash.sha512("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
+ "d5c989d2e41299b6bfd57562b4b09cd2efa56f13c8fa109e0ce5ddbd6bfb5b34f8563608d6162104bef750023732581f22704d5df43feecbb05742be1d7c34fa")
+}
+
diff --git a/lib/cryptohash/test/util.myr b/lib/cryptohash/test/util.myr
new file mode 100644
index 0000000..ceb411c
--- /dev/null
+++ b/lib/cryptohash/test/util.myr
@@ -0,0 +1,19 @@
+use std
+
+pkg =
+ const hasheq : (got : byte[:], expected : byte[:] -> void)
+;;
+
+const hasheq = {got, expected
+ var sb, str
+
+ sb = std.mksb()
+ for x in 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)
+}