summaryrefslogtreecommitdiff
path: root/validat5.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2020-01-10 00:04:32 -0500
committerJeffrey Walton <noloader@gmail.com>2020-01-10 00:04:32 -0500
commit5bedc2a182ac5e150b05655e668a6d2b1d31f82c (patch)
treeb44d29c1c44dcb3cc3130894b9ffa043e9c2fbc5 /validat5.cpp
parent46d61353560bed79a7df3589b2480c087f17e7b1 (diff)
downloadcryptopp-git-5bedc2a182ac5e150b05655e668a6d2b1d31f82c.tar.gz
Add additional BLAKE2 test vectors (GH #921)
Diffstat (limited to 'validat5.cpp')
-rw-r--r--validat5.cpp44
1 files changed, 42 insertions, 2 deletions
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;
}