1 /* 2 * Chocobo1/Hash 3 * 4 * Copyright 2017-2018 by Mike Tzou (Chocobo1) 5 * https://github.com/Chocobo1/Hash 6 * 7 * Licensed under GNU General Public License 3 or later. 8 * 9 * @license GPL3 <https://www.gnu.org/licenses/gpl-3.0-standalone.html> 10 */ 11 12 #include "../src/tiger.h" 13 14 #include "catch2/single_include/catch2/catch.hpp" 15 16 #include <cstring> 17 18 19 TEST_CASE("tiger1-192") 20 { 21 using Hash = Chocobo1::Tiger1_192; 22 23 // official test suite from tiger website 24 const char s1[] = ""; 25 REQUIRE("3293ac630c13f0245f92bbb1766e16167a4e58492dde73f3" == Hash().addData(s1, strlen(s1)).finalize().toString()); 26 27 const char s2[] = "a"; 28 REQUIRE("77befbef2e7ef8ab2ec8f93bf587a7fc613e247f5f247809" == Hash().addData(s2, strlen(s2)).finalize().toString()); 29 30 const char s3[] = "abc"; 31 REQUIRE("2aab1484e8c158f2bfb8c5ff41b57a525129131c957b5f93" == Hash().addData(s3, strlen(s3)).finalize().toString()); 32 33 const char s4[] = "message digest"; 34 REQUIRE("d981f8cb78201a950dcf3048751e441c517fca1aa55a29f6" == Hash().addData(s4, strlen(s4)).finalize().toString()); 35 36 const char s5[] = "abcdefghijklmnopqrstuvwxyz"; 37 REQUIRE("1714a472eee57d30040412bfcc55032a0b11602ff37beee9" == Hash().addData(s5, strlen(s5)).finalize().toString()); 38 39 const char s6[] = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; 40 REQUIRE("0f7bf9a19b9c58f2b7610df7e84f0ac3a71c631e7b53f78e" == Hash().addData(s6, strlen(s6)).finalize().toString()); 41 42 const char s7[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 43 REQUIRE("8dcea680a17583ee502ba38a3c368651890ffbccdc49a8cc" == Hash().addData(s7, strlen(s7)).finalize().toString()); 44 45 const char s8[] = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"; 46 REQUIRE("1c14795529fd9f207a958f84c52f11e887fa0cabdfd91bfd" == Hash().addData(s8, strlen(s8)).finalize().toString()); 47 48 const char s9[] = "a"; 49 Hash test9; 50 for (long int i = 0 ; i < 1000000; ++i) 51 test9.addData(s9, strlen(s9)); 52 REQUIRE("6db0e2729cbead93d715c6a7d36302e9b3cee0d2bc314b41" == test9.finalize().toString()); 53 54 55 // my own tests 56 REQUIRE("3293ac630c13f0245f92bbb1766e16167a4e58492dde73f3" == Hash().finalize().toString()); 57 58 const char s11[] = "The quick brown fox jumps over the lazy dog"; 59 REQUIRE("6d12a41e72e644f017b6f0e2f7b44c6285f06dd5d2c5b075" == Hash().addData(s11, strlen(s11)).finalize().toString()); 60 61 const char s12[] = "The quick brown fox jumps over the lazy dog."; 62 REQUIRE("0bf46f237681b35301d46aa08d43c449643408521a263929" == Hash().addData(s12, strlen(s12)).finalize().toString()); 63 64 const char s13[] = "The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy dog"; 65 REQUIRE("b68a2822f8f79df4dd12cd7261bce1a022297af27958d304" == Hash().addData(s13, strlen(s13)).finalize().toString()); 66 67 const std::vector<char> s14(1000001, 'a'); 68 REQUIRE("6db0e2729cbead93d715c6a7d36302e9b3cee0d2bc314b41" 69 == Hash().addData(s14.data() + 1, s14.size() - 1).finalize().toString()); 70 71 const int s15[2] = {0}; 72 const char s15_2[8] = {0}; 73 REQUIRE(Hash().addData(Hash::Span<const int>(s15)).finalize().toString() 74 == Hash().addData(s15_2).finalize().toString()); 75 76 const unsigned char s16[] = {0x00, 0x0A}; 77 const auto s16_1 = Hash().addData(s16, 2).finalize().toArray(); 78 const auto s16_2 = Hash().addData(s16).finalize().toArray(); 79 REQUIRE(s16_1 == s16_2); 80 } 81 82 83 TEST_CASE("tiger2-192") 84 { 85 using Hash = Chocobo1::Tiger2_192; 86 87 // official test suite from tiger website 88 const char s1[] = ""; 89 REQUIRE("4441be75f6018773c206c22745374b924aa8313fef919f41" == Hash().addData(s1, strlen(s1)).finalize().toString()); 90 91 const char s2[] = "a"; 92 REQUIRE("67e6ae8e9e968999f70a23e72aeaa9251cbc7c78a7916636" == Hash().addData(s2, strlen(s2)).finalize().toString()); 93 94 const char s3[] = "abc"; 95 REQUIRE("f68d7bc5af4b43a06e048d7829560d4a9415658bb0b1f3bf" == Hash().addData(s3, strlen(s3)).finalize().toString()); 96 97 const char s4[] = "message digest"; 98 REQUIRE("e29419a1b5fa259de8005e7de75078ea81a542ef2552462d" == Hash().addData(s4, strlen(s4)).finalize().toString()); 99 100 const char s5[] = "abcdefghijklmnopqrstuvwxyz"; 101 REQUIRE("f5b6b6a78c405c8547e91cd8624cb8be83fc804a474488fd" == Hash().addData(s5, strlen(s5)).finalize().toString()); 102 103 const char s6[] = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; 104 REQUIRE("a6737f3997e8fbb63d20d2df88f86376b5fe2d5ce36646a9" == Hash().addData(s6, strlen(s6)).finalize().toString()); 105 106 const char s7[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 107 REQUIRE("ea9ab6228cee7b51b77544fca6066c8cbb5bbae6319505cd" == Hash().addData(s7, strlen(s7)).finalize().toString()); 108 109 const char s8[] = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"; 110 REQUIRE("d85278115329ebaa0eec85ecdc5396fda8aa3a5820942fff" == Hash().addData(s8, strlen(s8)).finalize().toString()); 111 112 const char s9[] = "a"; 113 Hash test9; 114 for (long int i = 0 ; i < 1000000; ++i) 115 test9.addData(s9, strlen(s9)); 116 REQUIRE("e068281f060f551628cc5715b9d0226796914d45f7717cf4" == test9.finalize().toString()); 117 118 119 // my own tests 120 REQUIRE("4441be75f6018773c206c22745374b924aa8313fef919f41" == Hash().finalize().toString()); 121 122 const char s11[] = "The quick brown fox jumps over the lazy dog"; 123 REQUIRE("976abff8062a2e9dcea3a1ace966ed9c19cb85558b4976d8" == Hash().addData(s11, strlen(s11)).finalize().toString()); 124 125 const char s12[] = "The quick brown fox jumps over the lazy dog."; 126 REQUIRE("7c19bd4093a3106de04cc99f125ee6ac8d52ade31ae85fc5" == Hash().addData(s12, strlen(s12)).finalize().toString()); 127 128 const char s13[] = "The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy dog"; 129 REQUIRE("2ba7384e75cb63b58a52964208fdefc692b932a00c04bcfb" == Hash().addData(s13, strlen(s13)).finalize().toString()); 130 131 const std::vector<char> s14(1000001, 'a'); 132 REQUIRE("e068281f060f551628cc5715b9d0226796914d45f7717cf4" 133 == Hash().addData(s14.data() + 1, s14.size() - 1).finalize().toString()); 134 135 const int s15[2] = {0}; 136 const char s15_2[8] = {0}; 137 REQUIRE(Hash().addData(Hash::Span<const int>(s15)).finalize().toString() 138 == Hash().addData(s15_2).finalize().toString()); 139 140 const unsigned char s16[] = {0x00, 0x0A}; 141 const auto s16_1 = Hash().addData(s16, 2).finalize().toArray(); 142 const auto s16_2 = Hash().addData(s16).finalize().toArray(); 143 REQUIRE(s16_1 == s16_2); 144 } 145