7 #ifndef CRYPTOPP_HKDF_H 8 #define CRYPTOPP_HKDF_H 29 static std::string StaticAlgorithmName () {
30 const std::string name(std::string(
"HKDF(") +
31 std::string(T::StaticAlgorithmName()) + std::string(
")"));
37 return StaticAlgorithmName();
42 return static_cast<size_t>(T::DIGESTSIZE) * 255;
49 size_t DeriveKey(byte *derived,
size_t derivedLen,
const byte *secret,
size_t secretLen,
72 size_t DeriveKey(byte *derived,
size_t derivedLen,
const byte *secret,
size_t secretLen,
73 const byte *salt,
size_t saltLen,
const byte* info,
size_t infoLen)
const;
84 typedef byte NullVectorType[T::DIGESTSIZE];
85 static const NullVectorType& GetNullVector() {
86 static const NullVectorType s_NullVector = {0};
101 const byte *secret,
size_t secretLen,
const NameValuePairs& params)
const 113 salt.
Assign(GetNullVector(), T::DIGESTSIZE);
118 info.
Assign(GetNullVector(), 0);
125 const byte *salt,
size_t saltLen,
const byte* info,
size_t infoLen)
const 131 ThrowIfInvalidDerivedLength(derivedLen);
136 salt = GetNullVector();
137 saltLen = T::DIGESTSIZE;
145 hmac.
SetKey(salt, saltLen);
149 hmac.
SetKey(key.begin(), key.size());
153 while (derivedLen > 0)
155 if (block++) {hmac.
Update(buffer, buffer.
size());}
156 if (infoLen) {hmac.
Update(info, infoLen);}
159 #if CRYPTOPP_MSC_VERSION 160 const size_t digestSize =
static_cast<size_t>(T::DIGESTSIZE);
161 const size_t segmentLen =
STDMIN(derivedLen, digestSize);
162 memcpy_s(derived, segmentLen, buffer, segmentLen);
164 const size_t digestSize =
static_cast<size_t>(T::DIGESTSIZE);
165 const size_t segmentLen =
STDMIN(derivedLen, digestSize);
166 std::memcpy(derived, buffer, segmentLen);
169 derived += segmentLen;
170 derivedLen -= segmentLen;
178 #endif // CRYPTOPP_HKDF_H Used to pass byte array input as part of a NameValuePairs object.
virtual void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms=g_nullNameValuePairs)
Sets or reset the key of this object.
size_t size() const
Length of the memory block.
size_t MaxDerivedLength() const
Determine maximum number of bytes.
Extract-and-Expand Key Derivation Function (HKDF)
Abstract base classes that provide a uniform interface to this library.
void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for memcpy()
size_t DeriveKey(byte *derived, size_t derivedLen, const byte *secret, size_t secretLen, const NameValuePairs ¶ms) const
Derive a key from a seed.
Classes and functions for secure memory allocations.
Classes for HMAC message authentication codes.
const byte * begin() const
Pointer to the first byte in the memory block.
size_t GetValidDerivedLength(size_t keylength) const
Returns a valid key length for the derivation function.
void Assign(const T *ptr, size_type len)
Set contents and size from an array.
void Update(const byte *input, size_t length)
Updates a hash with additional input.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
iterator begin()
Provides an iterator pointing to the first element in the memory block.
Interface for all crypto algorithms.
Crypto++ library namespace.
bool GetValue(const char *name, T &value) const
Get a named value.
std::string AlgorithmName() const
Provides the name of this algorithm.
size_type size() const
Provides the count of elements in the SecBlock.
Interface for key derivation functions.
Interface for retrieving values given their names.