Skip to content
Snippets Groups Projects
Commit 4b4f883a authored by Zach Hilman's avatar Zach Hilman
Browse files

csrng: Use std::mt19937 engine for random number generation

parent 2c6efda2
No related branches found
No related tags found
No related merge requests found
...@@ -3,18 +3,23 @@ ...@@ -3,18 +3,23 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <algorithm> #include <algorithm>
#include <chrono>
#include <cstdlib> #include <cstdlib>
#include <ctime>
#include <functional>
#include <vector> #include <vector>
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/hle/ipc_helpers.h" #include "core/hle/ipc_helpers.h"
#include "core/hle/service/spl/csrng.h" #include "core/hle/service/spl/csrng.h"
#include "core/hle/service/spl/module.h" #include "core/hle/service/spl/module.h"
#include "core/hle/service/spl/spl.h" #include "core/hle/service/spl/spl.h"
#include "core/settings.h"
namespace Service::SPL { namespace Service::SPL {
Module::Interface::Interface(std::shared_ptr<Module> module, const char* name) Module::Interface::Interface(std::shared_ptr<Module> 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; Module::Interface::~Interface() = default;
...@@ -24,7 +29,7 @@ void Module::Interface::GetRandomBytes(Kernel::HLERequestContext& ctx) { ...@@ -24,7 +29,7 @@ void Module::Interface::GetRandomBytes(Kernel::HLERequestContext& ctx) {
std::size_t size = ctx.GetWriteBufferSize(); std::size_t size = ctx.GetWriteBufferSize();
std::vector<u8> data(size); std::vector<u8> data(size);
std::generate(data.begin(), data.end(), std::rand); std::generate(data.begin(), data.end(), rng);
ctx.WriteBuffer(data); ctx.WriteBuffer(data);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#pragma once #pragma once
#include <random>
#include "core/hle/service/service.h" #include "core/hle/service/service.h"
namespace Service::SPL { namespace Service::SPL {
...@@ -19,6 +20,9 @@ public: ...@@ -19,6 +20,9 @@ public:
protected: protected:
std::shared_ptr<Module> module; std::shared_ptr<Module> module;
private:
std::mt19937 rng;
}; };
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment