mirror of
https://github.com/espressif/openthread.git
synced 2026-09-09 18:50:07 +00:00
[random] add Fill<ObjectType>() function (#9097)
This commit adds template `Fill<ObjectType>(ObjectType &aObject)` functions for both `Crypto` and `NonCrypto` random number generation modules. These functions fill a given object with random byes.
This commit is contained in:
@@ -190,7 +190,7 @@ void TestUdpMessageChecksum(void)
|
||||
|
||||
// Write UDP header with a random payload.
|
||||
|
||||
Random::NonCrypto::FillBuffer(reinterpret_cast<uint8_t *>(&udpHeader), sizeof(udpHeader));
|
||||
Random::NonCrypto::Fill(udpHeader);
|
||||
udpHeader.SetChecksum(0);
|
||||
message->Write(0, udpHeader);
|
||||
|
||||
@@ -258,7 +258,7 @@ void TestIcmp6MessageChecksum(void)
|
||||
|
||||
// Write ICMP6 header with a random payload.
|
||||
|
||||
Random::NonCrypto::FillBuffer(reinterpret_cast<uint8_t *>(&icmp6Header), sizeof(icmp6Header));
|
||||
Random::NonCrypto::Fill(icmp6Header);
|
||||
icmp6Header.SetChecksum(0);
|
||||
message->Write(0, icmp6Header);
|
||||
|
||||
@@ -332,7 +332,7 @@ void TestTcp4MessageChecksum(void)
|
||||
|
||||
// Write TCP header with a random payload.
|
||||
|
||||
Random::NonCrypto::FillBuffer(reinterpret_cast<uint8_t *>(&tcpHeader), sizeof(tcpHeader));
|
||||
Random::NonCrypto::Fill(tcpHeader);
|
||||
message->Write(0, tcpHeader);
|
||||
|
||||
if (size > sizeof(tcpHeader))
|
||||
@@ -387,7 +387,7 @@ void TestUdp4MessageChecksum(void)
|
||||
|
||||
// Write UDP header with a random payload.
|
||||
|
||||
Random::NonCrypto::FillBuffer(reinterpret_cast<uint8_t *>(&udpHeader), sizeof(udpHeader));
|
||||
Random::NonCrypto::Fill(udpHeader);
|
||||
udpHeader.SetChecksum(0);
|
||||
message->Write(0, udpHeader);
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ Ip6::InterfaceIdentifier generateRandomIid(uint16_t aIndex)
|
||||
{
|
||||
Ip6::InterfaceIdentifier iid;
|
||||
|
||||
Random::NonCrypto::FillBuffer(iid.mFields.m8, sizeof(iid));
|
||||
Random::NonCrypto::Fill(iid);
|
||||
iid.mFields.m16[3] = aIndex;
|
||||
|
||||
return iid;
|
||||
|
||||
@@ -891,7 +891,7 @@ uint32_t GetRandom(uint32_t max)
|
||||
|
||||
if (kUseTrueRandomNumberGenerator)
|
||||
{
|
||||
SuccessOrQuit(Random::Crypto::FillBuffer(reinterpret_cast<uint8_t *>(&value), sizeof(value)));
|
||||
SuccessOrQuit(Random::Crypto::Fill(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user