[random] use crypto RNG in places were non-trival random is required (#4840)

This commit is contained in:
Jonathan Hui
2020-04-16 13:50:38 -07:00
committed by GitHub
parent 69c3e2eed6
commit 32e308833c
6 changed files with 15 additions and 9 deletions
+1 -1
View File
@@ -286,7 +286,7 @@ otError Message::SetToken(uint8_t aTokenLength)
OT_ASSERT(aTokenLength <= sizeof(token));
Random::NonCrypto::FillBuffer(token, aTokenLength);
Random::Crypto::FillBuffer(token, aTokenLength);
return SetToken(token, aTokenLength);
}
+3 -1
View File
@@ -54,12 +54,14 @@ PanId GenerateRandomPanId(void)
return panId;
}
#if !OPENTHREAD_RADIO
void ExtAddress::GenerateRandom(void)
{
Random::NonCrypto::FillBuffer(m8, sizeof(ExtAddress));
Random::Crypto::FillBuffer(m8, sizeof(ExtAddress));
SetGroup(false);
SetLocal(true);
}
#endif
bool ExtAddress::operator==(const ExtAddress &aOther) const
{
+4
View File
@@ -73,6 +73,8 @@ typedef otPanId PanId;
*/
typedef otShortAddress ShortAddress;
#if !OPENTHREAD_RADIO
/**
* This function generates a random IEEE 802.15.4 PAN ID.
*
@@ -81,6 +83,8 @@ typedef otShortAddress ShortAddress;
*/
PanId GenerateRandomPanId(void);
#endif
/**
* This structure represents an IEEE 802.15.4 Extended Address.
*
+1 -1
View File
@@ -202,7 +202,7 @@ bool Dhcp6Client::ProcessNextIdentityAssociation()
}
// new transaction id
Random::NonCrypto::FillBuffer(mTransactionId, kTransactionIdSize);
Random::Crypto::FillBuffer(mTransactionId, kTransactionIdSize);
mIdentityAssociationCurrent = &mIdentityAssociations[i];
+4 -4
View File
@@ -190,8 +190,8 @@ Mle::Mle(Instance &aInstance)
// mesh-local 64
mMeshLocal64.Clear();
Random::NonCrypto::FillBuffer(mMeshLocal64.GetAddress().mFields.m8 + OT_IP6_PREFIX_SIZE,
OT_IP6_ADDRESS_SIZE - OT_IP6_PREFIX_SIZE);
Random::Crypto::FillBuffer(mMeshLocal64.GetAddress().mFields.m8 + OT_IP6_PREFIX_SIZE,
OT_IP6_ADDRESS_SIZE - OT_IP6_PREFIX_SIZE);
mMeshLocal64.mPrefixLength = MeshLocalPrefix::kLength;
mMeshLocal64.mPreferred = true;
@@ -1555,8 +1555,8 @@ void Mle::HandleStateChanged(otChangedFlags aFlags)
if (!Get<ThreadNetif>().IsUnicastAddress(mMeshLocal64.GetAddress()))
{
// Mesh Local EID was removed, choose a new one and add it back
Random::NonCrypto::FillBuffer(mMeshLocal64.GetAddress().mFields.m8 + OT_IP6_PREFIX_SIZE,
OT_IP6_ADDRESS_SIZE - OT_IP6_PREFIX_SIZE);
Random::Crypto::FillBuffer(mMeshLocal64.GetAddress().mFields.m8 + OT_IP6_PREFIX_SIZE,
OT_IP6_ADDRESS_SIZE - OT_IP6_PREFIX_SIZE);
Get<ThreadNetif>().AddUnicastAddress(mMeshLocal64);
Get<Notifier>().Signal(OT_CHANGED_THREAD_ML_ADDR);
+2 -2
View File
@@ -298,7 +298,7 @@ void Slaac::GenerateIid(Ip6::NetifUnicastAddress &aAddress) const
}
otLogWarnUtil("SLAAC: Failed to generate a non-reserved IID after %d attempts", dadCounter);
Random::NonCrypto::FillBuffer(hash, Ip6::Address::kInterfaceIdentifierSize);
Random::Crypto::FillBuffer(hash, Ip6::Address::kInterfaceIdentifierSize);
aAddress.GetAddress().SetIid(&hash[0]);
exit:
@@ -319,7 +319,7 @@ void Slaac::GetIidSecretKey(IidSecretKey &aKey) const
if (error != OT_ERROR_NONE)
{
Random::NonCrypto::FillBuffer(aKey.m8, sizeof(IidSecretKey));
Random::Crypto::FillBuffer(aKey.m8, sizeof(IidSecretKey));
}
Get<Settings>().SaveSlaacIidSecretKey(aKey);