Cleanup HKDF salt and info
parent
616741d4ea
commit
05fe384d82
20
hkdf.h
20
hkdf.h
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue