Fix UBsan finding in HKDF
This was introduced when HKDF was reworked for the new KeyDerivationFunction interfacepull/640/head
parent
71e9fece87
commit
9a991ac1eb
13
hkdf.h
13
hkdf.h
|
|
@ -15,8 +15,10 @@ NAMESPACE_BEGIN(CryptoPP)
|
|||
|
||||
/// \brief Extract-and-Expand Key Derivation Function (HKDF)
|
||||
/// \tparam T HashTransformation class
|
||||
/// \sa <A HREF="http://eprint.iacr.org/2010/264">Cryptographic Extraction and Key Derivation: The HKDF Scheme</A>
|
||||
/// and <A HREF="http://tools.ietf.org/html/rfc5869">HMAC-based Extract-and-Expand Key Derivation Function (HKDF)</A>
|
||||
/// \sa <A HREF="http://eprint.iacr.org/2010/264">Cryptographic Extraction and Key
|
||||
/// Derivation: The HKDF Scheme</A> and
|
||||
/// <A HREF="http://tools.ietf.org/html/rfc5869">HMAC-based Extract-and-Expand Key
|
||||
/// Derivation Function (HKDF)</A>
|
||||
/// \since Crypto++ 5.6.3
|
||||
template <class T>
|
||||
class HKDF : public KeyDerivationFunction
|
||||
|
|
@ -128,6 +130,13 @@ size_t HKDF<T>::DeriveKey(byte *derived, size_t derivedLen, const byte *secret,
|
|||
|
||||
ThrowIfInvalidDerivedLength(derivedLen);
|
||||
|
||||
// HKDF business logic. NULL is different than empty.
|
||||
if (salt == NULLPTR)
|
||||
{
|
||||
salt = GetNullVector();
|
||||
saltLen = T::DIGESTSIZE;
|
||||
}
|
||||
|
||||
// key is PRK from the RFC, salt is IKM from the RFC
|
||||
HMAC<T> hmac;
|
||||
SecByteBlock key(T::DIGESTSIZE), buffer(T::DIGESTSIZE);
|
||||
|
|
|
|||
Loading…
Reference in New Issue