From 03eb08162b656bc49799bc0fb986f2235e0b53b3 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Sat, 23 Jul 2022 12:00:31 -0400 Subject: [PATCH] Add a new set of Lua Md5 tests --- test/tool/net/base64_test.lua | 1 + test/tool/net/lfuncs_test.lua | 1 - test/tool/net/md5_test.lua | 26 ++++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/tool/net/md5_test.lua diff --git a/test/tool/net/base64_test.lua b/test/tool/net/base64_test.lua index 8cd43f7e4..90330b41d 100644 --- a/test/tool/net/base64_test.lua +++ b/test/tool/net/base64_test.lua @@ -22,6 +22,7 @@ end test("\x69\xb7\x1d\x79\xf8\x00\x04\x20\xc4", "abcdefgABCDE") -- 🦞 padding tests +-- https://datatracker.ietf.org/doc/html/rfc4648#section-10 test("", "") test("r", "cg==") test("re", "cmU=") diff --git a/test/tool/net/lfuncs_test.lua b/test/tool/net/lfuncs_test.lua index eb192532d..72be532d0 100644 --- a/test/tool/net/lfuncs_test.lua +++ b/test/tool/net/lfuncs_test.lua @@ -108,7 +108,6 @@ assert(math.floor(10 * MeasureEntropy("abcabcabcabc") + .5) == 16) assert(Crc32(0, "123456789") == 0xcbf43926) assert(Crc32c(0, "123456789") == 0xe3069283) -assert(Md5("hello") == "\x5d\x41\x40\x2a\xbc\x4b\x2a\x76\xb9\x71\x9d\x91\x10\x17\xc5\x92") assert(Sha1("hello") == "\xaa\xf4\xc6\x1d\xdc\xc5\xe8\xa2\xda\xbe\xde\x0f\x3b\x48\x2c\xd9\xae\xa9\x43\x4d") assert(Sha224("hello") == "\xea\x09\xae\x9c\xc6\x76\x8c\x50\xfc\xee\x90\x3e\xd0\x54\x55\x6e\x5b\xfc\x83\x47\x90\x7f\x12\x59\x8a\xa2\x41\x93") assert(Sha256("hello") == "\x2c\xf2\x4d\xba\x5f\xb0\xa3\x0e\x26\xe8\x3b\x2a\xc5\xb9\xe2\x9e\x1b\x16\x1e\x5c\x1f\xa7\x42\x5e\x73\x04\x33\x62\x93\x8b\x98\x24") diff --git a/test/tool/net/md5_test.lua b/test/tool/net/md5_test.lua new file mode 100644 index 000000000..f6ecf567b --- /dev/null +++ b/test/tool/net/md5_test.lua @@ -0,0 +1,26 @@ +-- Copyright 2022 Justine Alexandra Roberts Tunney +-- +-- Permission to use, copy, modify, and/or distribute this software for +-- any purpose with or without fee is hereby granted, provided that the +-- above copyright notice and this permission notice appear in all copies. +-- +-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +-- WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +-- WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +-- AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL +-- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR +-- PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +-- TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +-- PERFORMANCE OF THIS SOFTWARE. + +-- https://datatracker.ietf.org/doc/html/rfc1321#appendix-A.5 +assert(Md5("hello") == "\x5d\x41\x40\x2a\xbc\x4b\x2a\x76\xb9\x71\x9d\x91\x10\x17\xc5\x92") +assert(Md5("") == "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e") +assert(Md5("a") == "\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8\x31\xc3\x99\xe2\x69\x77\x26\x61") +assert(Md5("abc") == "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f\x72") +assert(Md5("message digest") == "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61\xd0") +assert(Md5("abcdefghijklmnopqrstuvwxyz") == "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b") +assert(Md5("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") == + "\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f") +assert(Md5("12345678901234567890123456789012345678901234567890123456789012345678901234567890") == + "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6\x7a")