mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-27 23:08:47 +00:00
Common: Add Random utilities
This makes it easier to generate random numbers or fill a buffer with random data in a cryptographically secure way. This also replaces existing usages of RNG functions in the codebase: * <random> is pretty hard to use correctly, and std::random_device does not give enough guarantees about its results (it's implementation-defined, non cryptographically secure and could be deterministic on some platforms). Doing things correctly is error prone and verbose. * rand() is terrible and should not be used especially in crypto code.
This commit is contained in:
parent
dd77ace56a
commit
fff1db9730
10 changed files with 91 additions and 71 deletions
|
@ -5,11 +5,10 @@
|
|||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <random>
|
||||
|
||||
#include "Common/Network.h"
|
||||
#include "Common/Random.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Common/Timer.h"
|
||||
|
||||
namespace Common
|
||||
{
|
||||
|
@ -31,11 +30,7 @@ void GenerateMacAddress(const MACConsumer type, u8* mac)
|
|||
}
|
||||
|
||||
// Generate the 24-bit NIC-specific portion of the MAC address.
|
||||
std::default_random_engine generator(Common::Timer::GetTimeMs());
|
||||
std::uniform_int_distribution<int> distribution(0x00, 0xFF);
|
||||
mac[3] = static_cast<u8>(distribution(generator));
|
||||
mac[4] = static_cast<u8>(distribution(generator));
|
||||
mac[5] = static_cast<u8>(distribution(generator));
|
||||
Common::Random::Generate(&mac[3], 3);
|
||||
}
|
||||
|
||||
std::string MacAddressToString(const u8* mac)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue