From 4b4f883aef8fbc4f8a8b6c842df61eb0d5253f45 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sun, 11 Nov 2018 22:33:31 -0500 Subject: csrng: Use std::mt19937 engine for random number generation --- src/core/hle/service/spl/module.cpp | 9 +++++++-- src/core/hle/service/spl/module.h | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/hle/service/spl/module.cpp b/src/core/hle/service/spl/module.cpp index 44a6717d0..69c260408 100644 --- a/src/core/hle/service/spl/module.cpp +++ b/src/core/hle/service/spl/module.cpp @@ -3,18 +3,23 @@ // Refer to the license.txt file included. #include +#include #include +#include +#include #include #include "common/logging/log.h" #include "core/hle/ipc_helpers.h" #include "core/hle/service/spl/csrng.h" #include "core/hle/service/spl/module.h" #include "core/hle/service/spl/spl.h" +#include "core/settings.h" namespace Service::SPL { Module::Interface::Interface(std::shared_ptr module, const char* name) - : ServiceFramework(name), module(std::move(module)) {} + : ServiceFramework(name), module(std::move(module)), + rng(Settings::values.rng_seed.value_or(std::time(nullptr))) {} Module::Interface::~Interface() = default; @@ -24,7 +29,7 @@ void Module::Interface::GetRandomBytes(Kernel::HLERequestContext& ctx) { std::size_t size = ctx.GetWriteBufferSize(); std::vector data(size); - std::generate(data.begin(), data.end(), std::rand); + std::generate(data.begin(), data.end(), rng); ctx.WriteBuffer(data); diff --git a/src/core/hle/service/spl/module.h b/src/core/hle/service/spl/module.h index 48fda6099..afa1f0295 100644 --- a/src/core/hle/service/spl/module.h +++ b/src/core/hle/service/spl/module.h @@ -4,6 +4,7 @@ #pragma once +#include #include "core/hle/service/service.h" namespace Service::SPL { @@ -19,6 +20,9 @@ public: protected: std::shared_ptr module; + + private: + std::mt19937 rng; }; }; -- cgit v1.2.3 From 2a16fd7ffc1ec4e2dc90480c04f9867fdeec6a98 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sun, 11 Nov 2018 22:34:23 -0500 Subject: settings: Add config option to set RNG seed --- src/core/settings.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core') diff --git a/src/core/settings.h b/src/core/settings.h index a8954647f..83a1a7069 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -6,6 +6,7 @@ #include #include +#include #include #include "common/common_types.h" @@ -114,6 +115,7 @@ struct Values { // System bool use_docked_mode; bool enable_nfc; + std::optional rng_seed; s32 current_user; s32 language_index; -- cgit v1.2.3 From cb1e63ef09a5cd775e916f6f4482cde3ea256f44 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Mon, 12 Nov 2018 21:46:21 -0500 Subject: svc: Return random seed for svcGetInfo RandomEntropy --- src/core/hle/kernel/svc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 7e8e87c33..0bfe1e3be 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -34,6 +34,7 @@ #include "core/hle/lock.h" #include "core/hle/result.h" #include "core/hle/service/service.h" +#include "core/settings.h" namespace Kernel { namespace { @@ -558,7 +559,7 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) *result = 0; break; case GetInfoType::RandomEntropy: - *result = 0; + *result = Settings::values.rng_seed.value_or(0); break; case GetInfoType::ASLRRegionBaseAddr: *result = vm_manager.GetASLRRegionBaseAddress(); -- cgit v1.2.3