Cleanup HKDF salt and info

pull/614/head
Jeffrey Walton 2018-03-30 00:34:12 -04:00
parent 616741d4ea
commit 05fe384d82
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 10 additions and 10 deletions

20
hkdf.h
View File

@ -101,18 +101,18 @@ size_t HKDF<T>::DeriveKey(byte *derived, size_t derivedLen,
ThrowIfInvalidDerivedLength(derivedLen); ThrowIfInvalidDerivedLength(derivedLen);
// Copy-out Salt to a temporary
ConstByteArrayParameter p; ConstByteArrayParameter p;
if (!params.GetValue("Salt", p)) SecByteBlock salt, info;
p = ConstByteArrayParameter(GetNullVector(), T::DIGESTSIZE);
SecByteBlock salt(p.begin(), p.size());
// Warning: the 'params.GetValue' for Info blows away the data if (params.GetValue("Salt", p))
// from the previous call to 'params.GetValue' for Salt. salt.Assign(p.begin(), p.size());
// It is the reason we copy-out the data after Salt. else
if (!params.GetValue("Info", p)) salt.Assign(GetNullVector(), T::DIGESTSIZE);
p = ConstByteArrayParameter(GetNullVector(), 0);
SecByteBlock info(p.begin(), p.size()); if (params.GetValue("Info", p))
info.Assign(p.begin(), p.size());
else
info.Assign(GetNullVector(), 0);
return DeriveKey(derived, derivedLen, secret, secretLen, salt.begin(), salt.size(), info.begin(), info.size()); return DeriveKey(derived, derivedLen, secret, secretLen, salt.begin(), salt.size(), info.begin(), info.size());
} }