diff --git a/TestVectors/blake2b.txt b/TestVectors/blake2b.txt index ec5167c7..68ed80b7 100644 --- a/TestVectors/blake2b.txt +++ b/TestVectors/blake2b.txt @@ -436,4 +436,3 @@ Test: Verify Message: "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789" Digest: FFD4A61F80D55FFA83BA8D2BD62DCFC33148ADE507A8F7F85A5AF2C619E126FF11E9284F12BF3EE6A2B5CBC711FA84C37DA343AB7D29BCDF722DF0171E41297A Test: Verify - diff --git a/validat5.cpp b/validat5.cpp index b7b6d7e6..aa516756 100644 --- a/validat5.cpp +++ b/validat5.cpp @@ -1725,7 +1725,27 @@ bool ValidateBLAKE2s() pass = pass && !fail; } - std::cout << (!pass ? "FAILED " : "passed ") << COUNTOF(tests) << " hashes and keyed hashes" << std::endl; + { + // One test with salt and personalization for GH #921 + // Test vector generate with modified BLAKE2 implementation + const std::string key = "\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x41\x42\x43\x44\x45\x46"; + const std::string salt = "\x41\x42\x43\x44"; + const std::string personalization = "\x41\x42\x43\x44"; + const std::string message = "\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50"; + const std::string digest = "\x0b\x62\x56\x59\xb0\x0a\xb7\x43\x72\x53\xa2\x6a\x6c\x97\x91\xa4\x83\x74\x95\x27\x55\xc5\xa2\x6d\x89\xcc\x9d\x46\xba\x9a\xff\x57"; + std::string calculated; + + BLAKE2s blake2s(ConstBytePtr(key), BytePtrSize(key), ConstBytePtr(salt), BytePtrSize(salt), + ConstBytePtr(personalization), BytePtrSize(personalization)); + blake2s.Update(ConstBytePtr(message), BytePtrSize(message)); + + calculated.resize(32); + blake2s.TruncatedFinal(BytePtr(calculated), BytePtrSize(calculated)); + + pass = pass && (digest == calculated); + } + + std::cout << (!pass ? "FAILED " : "passed ") << COUNTOF(tests)+1 << " hashes and keyed hashes" << std::endl; return pass; } @@ -2156,7 +2176,27 @@ bool ValidateBLAKE2b() pass = pass && !fail; } - std::cout << (!pass ? "FAILED " : "passed ") << COUNTOF(tests) << " hashes and keyed hashes" << std::endl; + { + // One test with salt and personalization for GH #921 + // Test vector generate with modified BLAKE2 implementation + const std::string key = "\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c"; + const std::string salt = "\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c"; + const std::string personalization = "\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c"; + const std::string message = "\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x41\x42"; + const std::string digest = "\x0c\xab\x0f\x22\x5d\xbe\xce\x14\xab\xcb\x70\xc9\x90\x69\xc3\xdf\xf5\x08\x18\x51\x90\xa3\x5d\x14\x41\xf2\xac\xb9\x2d\xf0\x5b\x9e\x7c\x2c\x18\x08\xe8\x01\x06\xcf\xb2\x8f\xf3\xe5\x38\xff\xd0\x72\xd8\xa6\xd3\x70\x24\x5b\x86\x61\x7d\x86\xaa\x8d\x64\xb6\xcc\xc6"; + std::string calculated; + + BLAKE2b blake2b(ConstBytePtr(key), BytePtrSize(key), ConstBytePtr(salt), BytePtrSize(salt), + ConstBytePtr(personalization), BytePtrSize(personalization)); + blake2b.Update(ConstBytePtr(message), BytePtrSize(message)); + + calculated.resize(64); + blake2b.TruncatedFinal(BytePtr(calculated), BytePtrSize(calculated)); + + pass = pass && (digest == calculated); + } + + std::cout << (!pass ? "FAILED " : "passed ") << COUNTOF(tests)+1 << " hashes and keyed hashes" << std::endl; return pass; }