From e8e0b1c3f2e945e1468ef29aff45b3ff77bc86f5 Mon Sep 17 00:00:00 2001 From: "Dmitry S. Baikov" Date: Thu, 11 May 2017 06:46:56 +0300 Subject: [PATCH] blake2: Fixed initialization when using non-keyed constructor with non-standard digest size. Added test vectors. https://github.com/weidai11/cryptopp/issues/415 Test vectors generated with pyblake2 which uses 'BLAKE2 reference source code package' by Samuel Neves --- blake2.cpp | 2 +- validat3.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 81 insertions(+), 9 deletions(-) diff --git a/blake2.cpp b/blake2.cpp index 5d3154fb..d3af047a 100644 --- a/blake2.cpp +++ b/blake2.cpp @@ -351,7 +351,7 @@ BLAKE2_Base::BLAKE2_Base(bool treeMode, unsigned int digestSize) : m { CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE); - UncheckedSetKey(NULLPTR, 0, g_nullNameValuePairs); + UncheckedSetKey(NULL, 0, MakeParameters(Name::DigestSize(), (int)digestSize)(Name::TreeMode(), treeMode, false)); Restart(); } diff --git a/validat3.cpp b/validat3.cpp index 2ff56541..e8ad4ff7 100644 --- a/validat3.cpp +++ b/validat3.cpp @@ -1085,6 +1085,30 @@ bool ValidateBLAKE2s() } static const BLAKE2_TestTuples tests[] = { + { + NULLPTR, + NULLPTR, + "\x8F\x38", + 0, 0, 2 + }, + { + NULLPTR, + NULLPTR, + "\x36\xE9\xD2\x46", + 0, 0, 4 + }, + { + NULLPTR, + NULLPTR, + "\xEF\x2A\x8B\x78\xDD\x80\xDA\x9C", + 0, 0, 8 + }, + { + NULLPTR, + NULLPTR, + "\x64\x55\x0D\x6F\xFE\x2C\x0A\x01\xA1\x4A\xBA\x1E\xAD\xE0\x20\x0C", + 0, 0, 16 + }, { NULLPTR, NULLPTR, @@ -1450,11 +1474,23 @@ bool ValidateBLAKE2s() byte digest[BLAKE2s::DIGESTSIZE]; for (unsigned int i=0; i