summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-11-13 12:25:43 -0500
committerGravatar Zach Hilman2018-11-13 12:26:03 -0500
commitab552e4a252b66ca02c04724a1773edbefec6837 (patch)
tree544702301230e785639d7ff4cfbaa2e99294a4b9 /src/core/hle/kernel
parentMerge pull request #1628 from greggameplayer/Texture2DArray (diff)
downloadyuzu-ab552e4a252b66ca02c04724a1773edbefec6837.tar.gz
yuzu-ab552e4a252b66ca02c04724a1773edbefec6837.tar.xz
yuzu-ab552e4a252b66ca02c04724a1773edbefec6837.zip
svc: Use proper random entropy generation algorithm
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/process.cpp6
-rw-r--r--src/core/hle/kernel/process.h11
-rw-r--r--src/core/hle/kernel/svc.cpp11
3 files changed, 27 insertions, 1 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index 420218d59..6e5b36d6f 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -17,6 +17,7 @@
17#include "core/hle/kernel/thread.h" 17#include "core/hle/kernel/thread.h"
18#include "core/hle/kernel/vm_manager.h" 18#include "core/hle/kernel/vm_manager.h"
19#include "core/memory.h" 19#include "core/memory.h"
20#include "core/settings.h"
20 21
21namespace Kernel { 22namespace Kernel {
22 23
@@ -35,6 +36,11 @@ SharedPtr<Process> Process::Create(KernelCore& kernel, std::string&& name) {
35 process->process_id = kernel.CreateNewProcessID(); 36 process->process_id = kernel.CreateNewProcessID();
36 process->svc_access_mask.set(); 37 process->svc_access_mask.set();
37 38
39 std::mt19937 rng(Settings::values.rng_seed.value_or(0));
40 std::uniform_int_distribution<u64> distribution;
41 std::generate(process->random_entropy.begin(), process->random_entropy.end(),
42 [&] { return distribution(rng); });
43
38 kernel.AppendNewProcess(process); 44 kernel.AppendNewProcess(process);
39 return process; 45 return process;
40} 46}
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index 8d2616c79..95aa63ea1 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -8,6 +8,7 @@
8#include <bitset> 8#include <bitset>
9#include <cstddef> 9#include <cstddef>
10#include <memory> 10#include <memory>
11#include <random>
11#include <string> 12#include <string>
12#include <vector> 13#include <vector>
13#include <boost/container/static_vector.hpp> 14#include <boost/container/static_vector.hpp>
@@ -119,6 +120,8 @@ struct CodeSet final {
119 120
120class Process final : public Object { 121class Process final : public Object {
121public: 122public:
123 static constexpr std::size_t RANDOM_ENTROPY_SIZE = 4;
124
122 static SharedPtr<Process> Create(KernelCore& kernel, std::string&& name); 125 static SharedPtr<Process> Create(KernelCore& kernel, std::string&& name);
123 126
124 std::string GetTypeName() const override { 127 std::string GetTypeName() const override {
@@ -212,6 +215,11 @@ public:
212 total_process_running_time_ticks += ticks; 215 total_process_running_time_ticks += ticks;
213 } 216 }
214 217
218 /// Gets 8 bytes of random data for svcGetInfo RandomEntropy
219 u64 GetRandomEntropy(std::size_t index) const {
220 return random_entropy.at(index);
221 }
222
215 /** 223 /**
216 * Loads process-specifics configuration info with metadata provided 224 * Loads process-specifics configuration info with metadata provided
217 * by an executable. 225 * by an executable.
@@ -321,6 +329,9 @@ private:
321 /// Per-process handle table for storing created object handles in. 329 /// Per-process handle table for storing created object handles in.
322 HandleTable handle_table; 330 HandleTable handle_table;
323 331
332 /// Random values for svcGetInfo RandomEntropy
333 std::array<u64, RANDOM_ENTROPY_SIZE> random_entropy;
334
324 std::string name; 335 std::string name;
325}; 336};
326 337
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 0bfe1e3be..b0b6508d9 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -559,7 +559,16 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id)
559 *result = 0; 559 *result = 0;
560 break; 560 break;
561 case GetInfoType::RandomEntropy: 561 case GetInfoType::RandomEntropy:
562 *result = Settings::values.rng_seed.value_or(0); 562 if (handle != 0) {
563 return ERR_INVALID_HANDLE;
564 }
565
566 if (info_sub_id >= Process::RANDOM_ENTROPY_SIZE) {
567 return ERR_INVALID_COMBINATION_KERNEL;
568 }
569
570 *result = current_process->GetRandomEntropy(info_sub_id);
571 return RESULT_SUCCESS;
563 break; 572 break;
564 case GetInfoType::ASLRRegionBaseAddr: 573 case GetInfoType::ASLRRegionBaseAddr:
565 *result = vm_manager.GetASLRRegionBaseAddress(); 574 *result = vm_manager.GetASLRRegionBaseAddress();