diff options
| author | 2015-11-24 16:15:21 -0500 | |
|---|---|---|
| committer | 2015-11-24 16:15:21 -0500 | |
| commit | c642dc459bf1ea5b98ee21213ec841b415e90cb1 (patch) | |
| tree | 8926428e5be3f16f7488df899a3134a275f3186a | |
| parent | Merge pull request #1246 from polaris-/patch-1 (diff) | |
| parent | Add stub functions for Initialize and GenerateRandomData in ssl:C (diff) | |
| download | yuzu-c642dc459bf1ea5b98ee21213ec841b415e90cb1.tar.gz yuzu-c642dc459bf1ea5b98ee21213ec841b415e90cb1.tar.xz yuzu-c642dc459bf1ea5b98ee21213ec841b415e90cb1.zip | |
Merge pull request #1248 from polaris-/add-ssl-stubs
Add stub functions for Initialize and GenerateRandomData in ssl:C
| -rw-r--r-- | src/core/hle/service/ssl_c.cpp | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/src/core/hle/service/ssl_c.cpp b/src/core/hle/service/ssl_c.cpp index 04ab194e6..cabd18c80 100644 --- a/src/core/hle/service/ssl_c.cpp +++ b/src/core/hle/service/ssl_c.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <random> | ||
| 6 | |||
| 5 | #include "core/hle/hle.h" | 7 | #include "core/hle/hle.h" |
| 6 | #include "core/hle/service/ssl_c.h" | 8 | #include "core/hle/service/ssl_c.h" |
| 7 | 9 | ||
| @@ -10,11 +12,58 @@ | |||
| 10 | 12 | ||
| 11 | namespace SSL_C { | 13 | namespace SSL_C { |
| 12 | 14 | ||
| 15 | // TODO: Implement a proper CSPRNG in the future when actual security is needed | ||
| 16 | static std::mt19937 rand_gen; | ||
| 17 | |||
| 18 | static void Initialize(Service::Interface* self) { | ||
| 19 | u32* cmd_buff = Kernel::GetCommandBuffer(); | ||
| 20 | |||
| 21 | // Seed random number generator when the SSL service is initialized | ||
| 22 | std::random_device rand_device; | ||
| 23 | rand_gen.seed(rand_device()); | ||
| 24 | |||
| 25 | // Stub, return success | ||
| 26 | cmd_buff[1] = RESULT_SUCCESS.raw; | ||
| 27 | } | ||
| 28 | |||
| 29 | static void GenerateRandomData(Service::Interface* self) { | ||
| 30 | u32* cmd_buff = Kernel::GetCommandBuffer(); | ||
| 31 | |||
| 32 | u32 size = cmd_buff[1]; | ||
| 33 | VAddr address = cmd_buff[3]; | ||
| 34 | u8* output_buff = Memory::GetPointer(address); | ||
| 35 | |||
| 36 | // Fill the output buffer with random data. | ||
| 37 | u32 data = 0; | ||
| 38 | u32 i = 0; | ||
| 39 | while (i < size) { | ||
| 40 | if ((i % 4) == 0) { | ||
| 41 | // The random number generator returns 4 bytes worth of data, so generate new random data when i == 0 and when i is divisible by 4 | ||
| 42 | data = rand_gen(); | ||
| 43 | } | ||
| 44 | |||
| 45 | if (size > 4) { | ||
| 46 | // Use up the entire 4 bytes of the random data for as long as possible | ||
| 47 | *(u32*)(output_buff + i) = data; | ||
| 48 | i += 4; | ||
| 49 | } else if (size == 2) { | ||
| 50 | *(u16*)(output_buff + i) = (u16)(data & 0xffff); | ||
| 51 | i += 2; | ||
| 52 | } else { | ||
| 53 | *(u8*)(output_buff + i) = (u8)(data & 0xff); | ||
| 54 | i++; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | // Stub, return success | ||
| 59 | cmd_buff[1] = RESULT_SUCCESS.raw; | ||
| 60 | } | ||
| 61 | |||
| 13 | const Interface::FunctionInfo FunctionTable[] = { | 62 | const Interface::FunctionInfo FunctionTable[] = { |
| 14 | {0x00010002, nullptr, "Initialize"}, | 63 | {0x00010002, Initialize, "Initialize"}, |
| 15 | {0x000200C2, nullptr, "CreateContext"}, | 64 | {0x000200C2, nullptr, "CreateContext"}, |
| 16 | {0x00050082, nullptr, "AddTrustedRootCA"}, | 65 | {0x00050082, nullptr, "AddTrustedRootCA"}, |
| 17 | {0x00110042, nullptr, "GenerateRandomData"}, | 66 | {0x00110042, GenerateRandomData, "GenerateRandomData"}, |
| 18 | {0x00150082, nullptr, "Read"}, | 67 | {0x00150082, nullptr, "Read"}, |
| 19 | {0x00170082, nullptr, "Write"}, | 68 | {0x00170082, nullptr, "Write"}, |
| 20 | }; | 69 | }; |