[random] use crypto RNG in places were non-trival random is required (#4840)
diff --git a/src/core/coap/coap_message.cpp b/src/core/coap/coap_message.cpp
index 838a060..b5ea2a1 100644
--- a/src/core/coap/coap_message.cpp
+++ b/src/core/coap/coap_message.cpp
@@ -286,7 +286,7 @@
OT_ASSERT(aTokenLength <= sizeof(token));
- Random::NonCrypto::FillBuffer(token, aTokenLength);
+ Random::Crypto::FillBuffer(token, aTokenLength);
return SetToken(token, aTokenLength);
}
diff --git a/src/core/mac/mac_types.cpp b/src/core/mac/mac_types.cpp
index 65703fa..c06c9c8 100644
--- a/src/core/mac/mac_types.cpp
+++ b/src/core/mac/mac_types.cpp
@@ -54,12 +54,14 @@
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
{
diff --git a/src/core/mac/mac_types.hpp b/src/core/mac/mac_types.hpp
index f38828e..2d3e6a0 100644
--- a/src/core/mac/mac_types.hpp
+++ b/src/core/mac/mac_types.hpp
@@ -73,6 +73,8 @@
*/
typedef otShortAddress ShortAddress;
+#if !OPENTHREAD_RADIO
+
/**
* This function generates a random IEEE 802.15.4 PAN ID.
*
@@ -81,6 +83,8 @@
*/
PanId GenerateRandomPanId(void);
+#endif
+
/**
* This structure represents an IEEE 802.15.4 Extended Address.
*
diff --git a/src/core/net/dhcp6_client.cpp b/src/core/net/dhcp6_client.cpp
index d4e7e8e..e84df5e 100644
--- a/src/core/net/dhcp6_client.cpp
+++ b/src/core/net/dhcp6_client.cpp
@@ -202,7 +202,7 @@
}
// new transaction id
- Random::NonCrypto::FillBuffer(mTransactionId, kTransactionIdSize);
+ Random::Crypto::FillBuffer(mTransactionId, kTransactionIdSize);
mIdentityAssociationCurrent = &mIdentityAssociations[i];
diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp
index f8cbd7d..fb29fab 100644
--- a/src/core/thread/mle.cpp
+++ b/src/core/thread/mle.cpp
@@ -190,8 +190,8 @@
// 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 @@
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);
diff --git a/src/core/utils/slaac_address.cpp b/src/core/utils/slaac_address.cpp
index b31c4df..b60b004 100644
--- a/src/core/utils/slaac_address.cpp
+++ b/src/core/utils/slaac_address.cpp
@@ -298,7 +298,7 @@
}
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 @@
if (error != OT_ERROR_NONE)
{
- Random::NonCrypto::FillBuffer(aKey.m8, sizeof(IidSecretKey));
+ Random::Crypto::FillBuffer(aKey.m8, sizeof(IidSecretKey));
}
Get<Settings>().SaveSlaacIidSecretKey(aKey);