From 1f87766b8673756973d02c90e05bd29fde77e466 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Thu, 22 Feb 2018 22:31:58 -0700 Subject: [PATCH] Change to use CryptoPP random and address review comments --- src/core/hle/service/nwm/nwm.cpp | 12 +++++------- src/core/hle/service/nwm/nwm_uds.cpp | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/core/hle/service/nwm/nwm.cpp b/src/core/hle/service/nwm/nwm.cpp index 9fc0537c04..f3f906d3a4 100644 --- a/src/core/hle/service/nwm/nwm.cpp +++ b/src/core/hle/service/nwm/nwm.cpp @@ -2,7 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include +#include #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::max()); + CryptoPP::AutoSeededRandomPool rng; auto mac = SharedPage::DefaultMac; - for (int i = 3; i < sizeof(SharedPage::MacAddress); ++i) { - mac[i] = static_cast(dis(gen)); - } + // Keep the Nintendo 3DS MAC header and randomly generate the last 3 bytes + rng.GenerateBlock(static_cast(mac.data() + 3), 3); + if (auto room_member = Network::GetRoomMember().lock()) { if (room_member->IsConnected()) { mac = static_cast(room_member->GetMacAddress()); diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index d120260d42..ecc2ed966d 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -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); }