From 31839703005edcd23f4fa4e15563b84e1201f0f4 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 24 Feb 2019 15:45:00 -0500 Subject: [PATCH] Add missing BLAKE2 constructors BLAKE2b and BLAKE2s are both missing a constructor that takes only the digest size. Also see https://groups.google.com/d/msg/cryptopp-users/QCFGYw8q3Yo/vpBCqz-vBgAJ --- blake2.cpp | 20 ++++++++++++++++++++ blake2.h | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/blake2.cpp b/blake2.cpp index 7646eaa9..733082d7 100644 --- a/blake2.cpp +++ b/blake2.cpp @@ -343,6 +343,26 @@ BLAKE2b::BLAKE2b(bool treeMode, unsigned int digestSize) (Name::TreeMode(), treeMode)); } +BLAKE2s::BLAKE2s(unsigned int digestSize) + : m_digestSize(digestSize), m_keyLength(0), m_treeMode(false) +{ + CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE); + + UncheckedSetKey(NULLPTR, 0, MakeParameters + (Name::DigestSize(), (int)digestSize) + (Name::TreeMode(), false)); +} + +BLAKE2b::BLAKE2b(unsigned int digestSize) + : m_digestSize(digestSize), m_keyLength(0), m_treeMode(false) +{ + CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE); + + UncheckedSetKey(NULLPTR, 0, MakeParameters + (Name::DigestSize(), (int)digestSize) + (Name::TreeMode(), false)); +} + BLAKE2s::BLAKE2s(const byte *key, size_t keyLength, const byte* salt, size_t saltLength, const byte* personalization, size_t personalizationLength, bool treeMode, unsigned int digestSize) : m_digestSize(digestSize), m_keyLength(static_cast(keyLength)), m_treeMode(treeMode) diff --git a/blake2.h b/blake2.h index 7b27ed73..28a6a60a 100644 --- a/blake2.h +++ b/blake2.h @@ -256,8 +256,15 @@ public: /// \brief Construct a BLAKE2s hash /// \param digestSize the digest size, in bytes /// \param treeMode flag indicating tree mode + /// \since Crypto++ 5.6.4 BLAKE2s(bool treeMode=false, unsigned int digestSize = DIGESTSIZE); + /// \brief Construct a BLAKE2s hash + /// \param digestSize the digest size, in bytes + /// \details treeMode flag is set to false + /// \since Crypto++ 8.2 + BLAKE2s(unsigned int digestSize); + /// \brief Construct a BLAKE2s hash /// \param key a byte array used to key the cipher /// \param keyLength the size of the byte array @@ -267,6 +274,7 @@ public: /// \param personalizationLength the size of the byte array /// \param treeMode flag indicating tree mode /// \param digestSize the digest size, in bytes + /// \since Crypto++ 5.6.4 BLAKE2s(const byte *key, size_t keyLength, const byte* salt = NULLPTR, size_t saltLength = 0, const byte* personalization = NULLPTR, size_t personalizationLength = 0, bool treeMode=false, unsigned int digestSize = DIGESTSIZE); @@ -355,8 +363,15 @@ public: /// \brief Construct a BLAKE2b hash /// \param digestSize the digest size, in bytes /// \param treeMode flag indicating tree mode + /// \since Crypto++ 5.6.4 BLAKE2b(bool treeMode=false, unsigned int digestSize = DIGESTSIZE); + /// \brief Construct a BLAKE2s hash + /// \param digestSize the digest size, in bytes + /// \details treeMode flag is set to false + /// \since Crypto++ 8.2 + BLAKE2b(unsigned int digestSize); + /// \brief Construct a BLAKE2b hash /// \param key a byte array used to key the cipher /// \param keyLength the size of the byte array @@ -366,6 +381,7 @@ public: /// \param personalizationLength the size of the byte array /// \param treeMode flag indicating tree mode /// \param digestSize the digest size, in bytes + /// \since Crypto++ 5.6.4 BLAKE2b(const byte *key, size_t keyLength, const byte* salt = NULLPTR, size_t saltLength = 0, const byte* personalization = NULLPTR, size_t personalizationLength = 0, bool treeMode=false, unsigned int digestSize = DIGESTSIZE);