mirror of https://github.com/dnomd343/md5sum.git
Dnomd343
2 months ago
2 changed files with 105 additions and 200 deletions
@ -1,200 +0,0 @@ |
|||
#include "md5.h" |
|||
|
|||
using md5::value::K; |
|||
using md5::value::S; |
|||
using md5::value::T; |
|||
|
|||
static_assert(K(0x00) == 0); |
|||
static_assert(K(0x01) == 1); |
|||
static_assert(K(0x02) == 2); |
|||
static_assert(K(0x03) == 3); |
|||
static_assert(K(0x04) == 4); |
|||
static_assert(K(0x05) == 5); |
|||
static_assert(K(0x06) == 6); |
|||
static_assert(K(0x07) == 7); |
|||
static_assert(K(0x08) == 8); |
|||
static_assert(K(0x09) == 9); |
|||
static_assert(K(0x0a) == 10); |
|||
static_assert(K(0x0b) == 11); |
|||
static_assert(K(0x0c) == 12); |
|||
static_assert(K(0x0d) == 13); |
|||
static_assert(K(0x0e) == 14); |
|||
static_assert(K(0x0f) == 15); |
|||
static_assert(K(0x10) == 1); |
|||
static_assert(K(0x11) == 6); |
|||
static_assert(K(0x12) == 11); |
|||
static_assert(K(0x13) == 0); |
|||
static_assert(K(0x14) == 5); |
|||
static_assert(K(0x15) == 10); |
|||
static_assert(K(0x16) == 15); |
|||
static_assert(K(0x17) == 4); |
|||
static_assert(K(0x18) == 9); |
|||
static_assert(K(0x19) == 14); |
|||
static_assert(K(0x1a) == 3); |
|||
static_assert(K(0x1b) == 8); |
|||
static_assert(K(0x1c) == 13); |
|||
static_assert(K(0x1d) == 2); |
|||
static_assert(K(0x1e) == 7); |
|||
static_assert(K(0x1f) == 12); |
|||
static_assert(K(0x20) == 5); |
|||
static_assert(K(0x21) == 8); |
|||
static_assert(K(0x22) == 11); |
|||
static_assert(K(0x23) == 14); |
|||
static_assert(K(0x24) == 1); |
|||
static_assert(K(0x25) == 4); |
|||
static_assert(K(0x26) == 7); |
|||
static_assert(K(0x27) == 10); |
|||
static_assert(K(0x28) == 13); |
|||
static_assert(K(0x29) == 0); |
|||
static_assert(K(0x2a) == 3); |
|||
static_assert(K(0x2b) == 6); |
|||
static_assert(K(0x2c) == 9); |
|||
static_assert(K(0x2d) == 12); |
|||
static_assert(K(0x2e) == 15); |
|||
static_assert(K(0x2f) == 2); |
|||
static_assert(K(0x30) == 0); |
|||
static_assert(K(0x31) == 7); |
|||
static_assert(K(0x32) == 14); |
|||
static_assert(K(0x33) == 5); |
|||
static_assert(K(0x34) == 12); |
|||
static_assert(K(0x35) == 3); |
|||
static_assert(K(0x36) == 10); |
|||
static_assert(K(0x37) == 1); |
|||
static_assert(K(0x38) == 8); |
|||
static_assert(K(0x39) == 15); |
|||
static_assert(K(0x3a) == 6); |
|||
static_assert(K(0x3b) == 13); |
|||
static_assert(K(0x3c) == 4); |
|||
static_assert(K(0x3d) == 11); |
|||
static_assert(K(0x3e) == 2); |
|||
static_assert(K(0x3f) == 9); |
|||
|
|||
static_assert(S(0x00) == 7); |
|||
static_assert(S(0x01) == 12); |
|||
static_assert(S(0x02) == 17); |
|||
static_assert(S(0x03) == 22); |
|||
static_assert(S(0x04) == 7); |
|||
static_assert(S(0x05) == 12); |
|||
static_assert(S(0x06) == 17); |
|||
static_assert(S(0x07) == 22); |
|||
static_assert(S(0x08) == 7); |
|||
static_assert(S(0x09) == 12); |
|||
static_assert(S(0x0a) == 17); |
|||
static_assert(S(0x0b) == 22); |
|||
static_assert(S(0x0c) == 7); |
|||
static_assert(S(0x0d) == 12); |
|||
static_assert(S(0x0e) == 17); |
|||
static_assert(S(0x0f) == 22); |
|||
static_assert(S(0x10) == 5); |
|||
static_assert(S(0x11) == 9); |
|||
static_assert(S(0x12) == 14); |
|||
static_assert(S(0x13) == 20); |
|||
static_assert(S(0x14) == 5); |
|||
static_assert(S(0x15) == 9); |
|||
static_assert(S(0x16) == 14); |
|||
static_assert(S(0x17) == 20); |
|||
static_assert(S(0x18) == 5); |
|||
static_assert(S(0x19) == 9); |
|||
static_assert(S(0x1a) == 14); |
|||
static_assert(S(0x1b) == 20); |
|||
static_assert(S(0x1c) == 5); |
|||
static_assert(S(0x1d) == 9); |
|||
static_assert(S(0x1e) == 14); |
|||
static_assert(S(0x1f) == 20); |
|||
static_assert(S(0x20) == 4); |
|||
static_assert(S(0x21) == 11); |
|||
static_assert(S(0x22) == 16); |
|||
static_assert(S(0x23) == 23); |
|||
static_assert(S(0x24) == 4); |
|||
static_assert(S(0x25) == 11); |
|||
static_assert(S(0x26) == 16); |
|||
static_assert(S(0x27) == 23); |
|||
static_assert(S(0x28) == 4); |
|||
static_assert(S(0x29) == 11); |
|||
static_assert(S(0x2a) == 16); |
|||
static_assert(S(0x2b) == 23); |
|||
static_assert(S(0x2c) == 4); |
|||
static_assert(S(0x2d) == 11); |
|||
static_assert(S(0x2e) == 16); |
|||
static_assert(S(0x2f) == 23); |
|||
static_assert(S(0x30) == 6); |
|||
static_assert(S(0x31) == 10); |
|||
static_assert(S(0x32) == 15); |
|||
static_assert(S(0x33) == 21); |
|||
static_assert(S(0x34) == 6); |
|||
static_assert(S(0x35) == 10); |
|||
static_assert(S(0x36) == 15); |
|||
static_assert(S(0x37) == 21); |
|||
static_assert(S(0x38) == 6); |
|||
static_assert(S(0x39) == 10); |
|||
static_assert(S(0x3a) == 15); |
|||
static_assert(S(0x3b) == 21); |
|||
static_assert(S(0x3c) == 6); |
|||
static_assert(S(0x3d) == 10); |
|||
static_assert(S(0x3e) == 15); |
|||
static_assert(S(0x3f) == 21); |
|||
|
|||
static_assert(T(0x00) == 0xd76aa478); |
|||
static_assert(T(0x01) == 0xe8c7b756); |
|||
static_assert(T(0x02) == 0x242070db); |
|||
static_assert(T(0x03) == 0xc1bdceee); |
|||
static_assert(T(0x04) == 0xf57c0faf); |
|||
static_assert(T(0x05) == 0x4787c62a); |
|||
static_assert(T(0x06) == 0xa8304613); |
|||
static_assert(T(0x07) == 0xfd469501); |
|||
static_assert(T(0x08) == 0x698098d8); |
|||
static_assert(T(0x09) == 0x8b44f7af); |
|||
static_assert(T(0x0a) == 0xffff5bb1); |
|||
static_assert(T(0x0b) == 0x895cd7be); |
|||
static_assert(T(0x0c) == 0x6b901122); |
|||
static_assert(T(0x0d) == 0xfd987193); |
|||
static_assert(T(0x0e) == 0xa679438e); |
|||
static_assert(T(0x0f) == 0x49b40821); |
|||
static_assert(T(0x10) == 0xf61e2562); |
|||
static_assert(T(0x11) == 0xc040b340); |
|||
static_assert(T(0x12) == 0x265e5a51); |
|||
static_assert(T(0x13) == 0xe9b6c7aa); |
|||
static_assert(T(0x14) == 0xd62f105d); |
|||
static_assert(T(0x15) == 0x02441453); |
|||
static_assert(T(0x16) == 0xd8a1e681); |
|||
static_assert(T(0x17) == 0xe7d3fbc8); |
|||
static_assert(T(0x18) == 0x21e1cde6); |
|||
static_assert(T(0x19) == 0xc33707d6); |
|||
static_assert(T(0x1a) == 0xf4d50d87); |
|||
static_assert(T(0x1b) == 0x455a14ed); |
|||
static_assert(T(0x1c) == 0xa9e3e905); |
|||
static_assert(T(0x1d) == 0xfcefa3f8); |
|||
static_assert(T(0x1e) == 0x676f02d9); |
|||
static_assert(T(0x1f) == 0x8d2a4c8a); |
|||
static_assert(T(0x20) == 0xfffa3942); |
|||
static_assert(T(0x21) == 0x8771f681); |
|||
static_assert(T(0x22) == 0x6d9d6122); |
|||
static_assert(T(0x23) == 0xfde5380c); |
|||
static_assert(T(0x24) == 0xa4beea44); |
|||
static_assert(T(0x25) == 0x4bdecfa9); |
|||
static_assert(T(0x26) == 0xf6bb4b60); |
|||
static_assert(T(0x27) == 0xbebfbc70); |
|||
static_assert(T(0x28) == 0x289b7ec6); |
|||
static_assert(T(0x29) == 0xeaa127fa); |
|||
static_assert(T(0x2a) == 0xd4ef3085); |
|||
static_assert(T(0x2b) == 0x04881d05); |
|||
static_assert(T(0x2c) == 0xd9d4d039); |
|||
static_assert(T(0x2d) == 0xe6db99e5); |
|||
static_assert(T(0x2e) == 0x1fa27cf8); |
|||
static_assert(T(0x2f) == 0xc4ac5665); |
|||
static_assert(T(0x30) == 0xf4292244); |
|||
static_assert(T(0x31) == 0x432aff97); |
|||
static_assert(T(0x32) == 0xab9423a7); |
|||
static_assert(T(0x33) == 0xfc93a039); |
|||
static_assert(T(0x34) == 0x655b59c3); |
|||
static_assert(T(0x35) == 0x8f0ccc92); |
|||
static_assert(T(0x36) == 0xffeff47d); |
|||
static_assert(T(0x37) == 0x85845dd1); |
|||
static_assert(T(0x38) == 0x6fa87e4f); |
|||
static_assert(T(0x39) == 0xfe2ce6e0); |
|||
static_assert(T(0x3a) == 0xa3014314); |
|||
static_assert(T(0x3b) == 0x4e0811a1); |
|||
static_assert(T(0x3c) == 0xf7537e82); |
|||
static_assert(T(0x3d) == 0xbd3af235); |
|||
static_assert(T(0x3e) == 0x2ad7d2bb); |
|||
static_assert(T(0x3f) == 0xeb86d391); |
@ -0,0 +1,105 @@ |
|||
#include "md5.h" |
|||
#include "gtest/gtest.h" |
|||
|
|||
constexpr auto KTable = std::to_array<int>({ |
|||
0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , |
|||
8 , 9 , 10, 11, 12, 13, 14, 15, |
|||
1 , 6 , 11, 0 , 5 , 10, 15, 4 , |
|||
9 , 14, 3 , 8 , 13, 2 , 7 , 12, |
|||
5 , 8 , 11, 14, 1 , 4 , 7 , 10, |
|||
13, 0 , 3 , 6 , 9 , 12, 15, 2 , |
|||
0 , 7 , 14, 5 , 12, 3 , 10, 1 , |
|||
8 , 15, 6 , 13, 4 , 11, 2 , 9 , |
|||
}); |
|||
|
|||
constexpr auto STable = std::to_array<int>({ |
|||
7 , 12, 17, 22, 7 , 12, 17, 22, |
|||
7 , 12, 17, 22, 7 , 12, 17, 22, |
|||
5 , 9 , 14, 20, 5 , 9 , 14, 20, |
|||
5 , 9 , 14, 20, 5 , 9 , 14, 20, |
|||
4 , 11, 16, 23, 4 , 11, 16, 23, |
|||
4 , 11, 16, 23, 4 , 11, 16, 23, |
|||
6 , 10, 15, 21, 6 , 10, 15, 21, |
|||
6 , 10, 15, 21, 6 , 10, 15, 21, |
|||
}); |
|||
|
|||
constexpr auto TTable = std::to_array<uint32_t>({ |
|||
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, |
|||
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, |
|||
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, |
|||
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, |
|||
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, |
|||
0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, |
|||
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, |
|||
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, |
|||
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, |
|||
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, |
|||
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, |
|||
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, |
|||
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, |
|||
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, |
|||
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, |
|||
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, |
|||
}); |
|||
|
|||
#define TEST_KVAL(val) EXPECT_EQ(md5::value::K(val), KTable[val]) |
|||
#define TEST_SVAL(val) EXPECT_EQ(md5::value::S(val), STable[val]) |
|||
#define TEST_TVAL(val) EXPECT_EQ(md5::value::T(val), TTable[val]) |
|||
|
|||
TEST(md5sum, constant) { |
|||
EXPECT_EQ(md5::value::kA, 0x67452301); |
|||
EXPECT_EQ(md5::value::kB, 0xefcdab89); |
|||
EXPECT_EQ(md5::value::kC, 0x98badcfe); |
|||
EXPECT_EQ(md5::value::kD, 0x10325476); |
|||
|
|||
TEST_KVAL(0x00); TEST_KVAL(0x01); TEST_KVAL(0x02); TEST_KVAL(0x03); |
|||
TEST_KVAL(0x04); TEST_KVAL(0x05); TEST_KVAL(0x06); TEST_KVAL(0x07); |
|||
TEST_KVAL(0x08); TEST_KVAL(0x09); TEST_KVAL(0x0a); TEST_KVAL(0x0b); |
|||
TEST_KVAL(0x0c); TEST_KVAL(0x0d); TEST_KVAL(0x0e); TEST_KVAL(0x0f); |
|||
TEST_KVAL(0x10); TEST_KVAL(0x11); TEST_KVAL(0x12); TEST_KVAL(0x13); |
|||
TEST_KVAL(0x14); TEST_KVAL(0x15); TEST_KVAL(0x16); TEST_KVAL(0x17); |
|||
TEST_KVAL(0x18); TEST_KVAL(0x19); TEST_KVAL(0x1a); TEST_KVAL(0x1b); |
|||
TEST_KVAL(0x1c); TEST_KVAL(0x1d); TEST_KVAL(0x1e); TEST_KVAL(0x1f); |
|||
TEST_KVAL(0x20); TEST_KVAL(0x21); TEST_KVAL(0x22); TEST_KVAL(0x23); |
|||
TEST_KVAL(0x24); TEST_KVAL(0x25); TEST_KVAL(0x26); TEST_KVAL(0x27); |
|||
TEST_KVAL(0x28); TEST_KVAL(0x29); TEST_KVAL(0x2a); TEST_KVAL(0x2b); |
|||
TEST_KVAL(0x2c); TEST_KVAL(0x2d); TEST_KVAL(0x2e); TEST_KVAL(0x2f); |
|||
TEST_KVAL(0x30); TEST_KVAL(0x31); TEST_KVAL(0x32); TEST_KVAL(0x33); |
|||
TEST_KVAL(0x34); TEST_KVAL(0x35); TEST_KVAL(0x36); TEST_KVAL(0x37); |
|||
TEST_KVAL(0x38); TEST_KVAL(0x39); TEST_KVAL(0x3a); TEST_KVAL(0x3b); |
|||
TEST_KVAL(0x3c); TEST_KVAL(0x3d); TEST_KVAL(0x3e); TEST_KVAL(0x3f); |
|||
|
|||
TEST_SVAL(0x00); TEST_SVAL(0x01); TEST_SVAL(0x02); TEST_SVAL(0x03); |
|||
TEST_SVAL(0x04); TEST_SVAL(0x05); TEST_SVAL(0x06); TEST_SVAL(0x07); |
|||
TEST_SVAL(0x08); TEST_SVAL(0x09); TEST_SVAL(0x0a); TEST_SVAL(0x0b); |
|||
TEST_SVAL(0x0c); TEST_SVAL(0x0d); TEST_SVAL(0x0e); TEST_SVAL(0x0f); |
|||
TEST_SVAL(0x10); TEST_SVAL(0x11); TEST_SVAL(0x12); TEST_SVAL(0x13); |
|||
TEST_SVAL(0x14); TEST_SVAL(0x15); TEST_SVAL(0x16); TEST_SVAL(0x17); |
|||
TEST_SVAL(0x18); TEST_SVAL(0x19); TEST_SVAL(0x1a); TEST_SVAL(0x1b); |
|||
TEST_SVAL(0x1c); TEST_SVAL(0x1d); TEST_SVAL(0x1e); TEST_SVAL(0x1f); |
|||
TEST_SVAL(0x20); TEST_SVAL(0x21); TEST_SVAL(0x22); TEST_SVAL(0x23); |
|||
TEST_SVAL(0x24); TEST_SVAL(0x25); TEST_SVAL(0x26); TEST_SVAL(0x27); |
|||
TEST_SVAL(0x28); TEST_SVAL(0x29); TEST_SVAL(0x2a); TEST_SVAL(0x2b); |
|||
TEST_SVAL(0x2c); TEST_SVAL(0x2d); TEST_SVAL(0x2e); TEST_SVAL(0x2f); |
|||
TEST_SVAL(0x30); TEST_SVAL(0x31); TEST_SVAL(0x32); TEST_SVAL(0x33); |
|||
TEST_SVAL(0x34); TEST_SVAL(0x35); TEST_SVAL(0x36); TEST_SVAL(0x37); |
|||
TEST_SVAL(0x38); TEST_SVAL(0x39); TEST_SVAL(0x3a); TEST_SVAL(0x3b); |
|||
TEST_SVAL(0x3c); TEST_SVAL(0x3d); TEST_SVAL(0x3e); TEST_SVAL(0x3f); |
|||
|
|||
TEST_TVAL(0x00); TEST_TVAL(0x01); TEST_TVAL(0x02); TEST_TVAL(0x03); |
|||
TEST_TVAL(0x04); TEST_TVAL(0x05); TEST_TVAL(0x06); TEST_TVAL(0x07); |
|||
TEST_TVAL(0x08); TEST_TVAL(0x09); TEST_TVAL(0x0a); TEST_TVAL(0x0b); |
|||
TEST_TVAL(0x0c); TEST_TVAL(0x0d); TEST_TVAL(0x0e); TEST_TVAL(0x0f); |
|||
TEST_TVAL(0x10); TEST_TVAL(0x11); TEST_TVAL(0x12); TEST_TVAL(0x13); |
|||
TEST_TVAL(0x14); TEST_TVAL(0x15); TEST_TVAL(0x16); TEST_TVAL(0x17); |
|||
TEST_TVAL(0x18); TEST_TVAL(0x19); TEST_TVAL(0x1a); TEST_TVAL(0x1b); |
|||
TEST_TVAL(0x1c); TEST_TVAL(0x1d); TEST_TVAL(0x1e); TEST_TVAL(0x1f); |
|||
TEST_TVAL(0x20); TEST_TVAL(0x21); TEST_TVAL(0x22); TEST_TVAL(0x23); |
|||
TEST_TVAL(0x24); TEST_TVAL(0x25); TEST_TVAL(0x26); TEST_TVAL(0x27); |
|||
TEST_TVAL(0x28); TEST_TVAL(0x29); TEST_TVAL(0x2a); TEST_TVAL(0x2b); |
|||
TEST_TVAL(0x2c); TEST_TVAL(0x2d); TEST_TVAL(0x2e); TEST_TVAL(0x2f); |
|||
TEST_TVAL(0x30); TEST_TVAL(0x31); TEST_TVAL(0x32); TEST_TVAL(0x33); |
|||
TEST_TVAL(0x34); TEST_TVAL(0x35); TEST_TVAL(0x36); TEST_TVAL(0x37); |
|||
TEST_TVAL(0x38); TEST_TVAL(0x39); TEST_TVAL(0x3a); TEST_TVAL(0x3b); |
|||
TEST_TVAL(0x3c); TEST_TVAL(0x3d); TEST_TVAL(0x3e); TEST_TVAL(0x3f); |
|||
} |
Loading…
Reference in new issue