7 #ifndef CRYPTOPP_HASH_KEY_DERIVATION_FUNCTION_H 8 #define CRYPTOPP_HASH_KEY_DERIVATION_FUNCTION_H 22 virtual size_t MaxDerivedKeyLength()
const =0;
23 virtual bool Usesinfo()
const =0;
25 virtual unsigned int DeriveKey(
byte *derived,
size_t derivedLen,
const byte *secret,
size_t secretLen,
const byte *salt,
size_t saltLen,
const byte* info=NULL,
size_t infoLen=0)
const =0;
42 static const std::string
name(std::string(
"HKDF(") + std::string(T::StaticAlgorithmName()) + std::string(
")"));
47 unsigned int DeriveKey(
byte *derived,
size_t derivedLen,
const byte *secret,
size_t secretLen,
const byte *salt,
size_t saltLen,
const byte* info,
size_t infoLen)
const;
60 unsigned int HKDF<T>::DeriveKey(
byte *derived,
size_t derivedLen,
const byte *secret,
size_t secretLen,
const byte *salt,
size_t saltLen,
const byte* info,
size_t infoLen)
const 62 static const size_t DIGEST_SIZE =
static_cast<size_t>(T::DIGESTSIZE);
63 const unsigned int req =
static_cast<unsigned int>(derivedLen);
70 throw InvalidArgument(
"HKDF: derivedLen must be less than or equal to MaxDerivedKeyLength");
86 while (derivedLen > 0)
88 if (block++) {hmac.
Update(buffer, buffer.
size());}
89 if (info && infoLen) {hmac.
Update(info, infoLen);}
92 #if CRYPTOPP_MSC_VERSION 93 const size_t segmentLen =
STDMIN(derivedLen, DIGEST_SIZE);
94 memcpy_s(derived, segmentLen, buffer, segmentLen);
96 const size_t segmentLen =
STDMIN(derivedLen, DIGEST_SIZE);
100 derived += segmentLen;
101 derivedLen -= segmentLen;
109 #endif // CRYPTOPP_HASH_KEY_DERIVATION_FUNCTION_H An invalid argument was detected.
virtual void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms=g_nullNameValuePairs)
Sets or reset the key of this object.
#define NAMESPACE_BEGIN(x)
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_type size() const
Provides the count of elements in the SecBlock.
Classes and functions for secure memory allocations.
Classes for HMAC message authentication codes.
byte NullVectorType[SALTSIZE]
A::pointer data()
Provides a pointer to the first element in the memory block.
size_t MaxDerivedKeyLength() const
maximum number of bytes which can be produced under a secuirty context
void Update(const byte *input, size_t length)
Updates a hash with additional input.
#define CRYPTOPP_CONSTANT(x)
Fixed size stack-based SecBlock.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define CRYPTOPP_ASSERT(exp)
void * memcpy(void *a, const void *b, size_t c)
virtual ~KeyDerivationFunction()
unsigned int DeriveKey(byte *derived, size_t derivedLen, const byte *secret, size_t secretLen, const byte *salt, size_t saltLen, const byte *info, size_t infoLen) const
derive a key from secret
static const char * StaticAlgorithmName()
static const NullVectorType & GetNullVector()
abstract base class for key derivation function