mirror of
https://github.com/espressif/openthread.git
synced 2026-08-29 21:39:54 +00:00
[random] use crypto RNG in places were non-trival random is required (#4840)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -202,7 +202,7 @@ bool Dhcp6Client::ProcessNextIdentityAssociation()
|
||||
}
|
||||
|
||||
// new transaction id
|
||||
Random::NonCrypto::FillBuffer(mTransactionId, kTransactionIdSize);
|
||||
Random::Crypto::FillBuffer(mTransactionId, kTransactionIdSize);
|
||||
|
||||
mIdentityAssociationCurrent = &mIdentityAssociations[i];
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user