From f8b9034a2857a5dbe92b958f02c440a1fa0d0669 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Tue, 26 Jul 2022 22:29:40 -0700 Subject: [PATCH] Crypto/SHA1: add unittests --- Source/UnitTests/Common/CMakeLists.txt | 1 + Source/UnitTests/Common/Crypto/SHA1Test.cpp | 30 +++++++++++++++++++++ Source/UnitTests/UnitTests.vcxproj | 1 + 3 files changed, 32 insertions(+) create mode 100644 Source/UnitTests/Common/Crypto/SHA1Test.cpp diff --git a/Source/UnitTests/Common/CMakeLists.txt b/Source/UnitTests/Common/CMakeLists.txt index 2d30517614..bbea892fdf 100644 --- a/Source/UnitTests/Common/CMakeLists.txt +++ b/Source/UnitTests/Common/CMakeLists.txt @@ -5,6 +5,7 @@ add_dolphin_test(BlockingLoopTest BlockingLoopTest.cpp) add_dolphin_test(BusyLoopTest BusyLoopTest.cpp) add_dolphin_test(CommonFuncsTest CommonFuncsTest.cpp) add_dolphin_test(CryptoEcTest Crypto/EcTest.cpp) +add_dolphin_test(CryptoSHA1Test Crypto/SHA1Test.cpp) add_dolphin_test(EnumFormatterTest EnumFormatterTest.cpp) add_dolphin_test(EventTest EventTest.cpp) add_dolphin_test(FileUtilTest FileUtilTest.cpp) diff --git a/Source/UnitTests/Common/Crypto/SHA1Test.cpp b/Source/UnitTests/Common/Crypto/SHA1Test.cpp new file mode 100644 index 0000000000..463240ed84 --- /dev/null +++ b/Source/UnitTests/Common/Crypto/SHA1Test.cpp @@ -0,0 +1,30 @@ +#include + +#include "Common/Crypto/SHA1.h" + +// Just a few quick sanity checks +TEST(SHA1, Vectors) +{ + struct + { + const char* msg; + const Common::SHA1::Digest expected; + } const vectors[]{ + {"", {0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, + 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09}}, + {"abc", {0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a, 0xba, 0x3e, + 0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c, 0x9c, 0xd0, 0xd8, 0x9d}}, + {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + {0x84, 0x98, 0x3e, 0x44, 0x1c, 0x3b, 0xd2, 0x6e, 0xba, 0xae, + 0x4a, 0xa1, 0xf9, 0x51, 0x29, 0xe5, 0xe5, 0x46, 0x70, 0xf1}}, + {"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmn" + "opqklmnopqrlmnopqrsmnopqrstnopqrstu", + {0xa4, 0x9b, 0x24, 0x46, 0xa0, 0x2c, 0x64, 0x5b, 0xf4, 0x19, + 0xf9, 0x95, 0xb6, 0x70, 0x91, 0x25, 0x3a, 0x04, 0xa2, 0x59}}, + }; + for (auto& test : vectors) + { + auto actual = Common::SHA1::CalculateDigest(test.msg); + EXPECT_EQ(test.expected, actual); + } +} diff --git a/Source/UnitTests/UnitTests.vcxproj b/Source/UnitTests/UnitTests.vcxproj index da461087e9..e0295fba9c 100644 --- a/Source/UnitTests/UnitTests.vcxproj +++ b/Source/UnitTests/UnitTests.vcxproj @@ -44,6 +44,7 @@ +