Change to use CryptoPP random and address review comments

This commit is contained in:
James Rowe 2018-02-22 22:31:58 -07:00
parent 752cfcaaae
commit 1f87766b86
2 changed files with 8 additions and 10 deletions

View file

@ -2,7 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <random>
#include <cryptopp/osrng.h>
#include "core/hle/service/nwm/nwm.h"
#include "core/hle/service/nwm/nwm_cec.h"
#include "core/hle/service/nwm/nwm_ext.h"
@ -25,13 +25,11 @@ void Init() {
AddService(new NWM_SOC);
AddService(new NWM_TST);
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, std::numeric_limits<u8>::max());
CryptoPP::AutoSeededRandomPool rng;
auto mac = SharedPage::DefaultMac;
for (int i = 3; i < sizeof(SharedPage::MacAddress); ++i) {
mac[i] = static_cast<u8>(dis(gen));
}
// Keep the Nintendo 3DS MAC header and randomly generate the last 3 bytes
rng.GenerateBlock(static_cast<CryptoPP::byte*>(mac.data() + 3), 3);
if (auto room_member = Network::GetRoomMember().lock()) {
if (room_member->IsConnected()) {
mac = static_cast<SharedPage::MacAddress>(room_member->GetMacAddress());

View file

@ -23,7 +23,6 @@
#include "core/hle/service/nwm/uds_beacon.h"
#include "core/hle/service/nwm/uds_connection.h"
#include "core/hle/service/nwm/uds_data.h"
#include "core/hle/shared_page.h"
#include "core/memory.h"
#include "network/network.h"
@ -555,8 +554,9 @@ void NWM_UDS::RecvBeaconBroadcastData(Kernel::HLERequestContext& ctx) {
rb.Push(RESULT_SUCCESS);
rb.PushMappedBuffer(out_buffer);
LOG_DEBUG(Service_NWM, "called out_buffer_size=0x%08X, wlan_comm_id=0x%08X, id=0x%08X,"
"unk1=0x%08X, unk2=0x%08X, offset=%zu",
LOG_DEBUG(Service_NWM,
"called out_buffer_size=0x%08X, wlan_comm_id=0x%08X, id=0x%08X,"
"unk1=0x%08X, unk2=0x%08X, offset=%zu",
out_buffer_size, wlan_comm_id, id, unk1, unk2, cur_buffer_size);
}