WIP on implementing entropy generation

This commit is contained in:
UnknownShadow200 2024-12-17 19:50:39 +11:00
parent 84118251fb
commit 9467c8951a
4 changed files with 17 additions and 15 deletions

View File

@ -459,4 +459,9 @@ static cc_result GetMachineID(cc_uint32* key) {
Mem_Copy(key, MACHINE_KEY, sizeof(MACHINE_KEY) - 1);
return 0;
}
cc_result Platform_GetEntropy(void* data, int len) {
return PS_GenerateRandomBytes(data, len);
// NOTE: PS_GenerateRandomBytes isn't implemented in Citra
}
#endif

View File

@ -1605,7 +1605,13 @@ cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) {
}
cc_result Platform_GetEntropy(void* data, int len) {
return ERR_NOT_SUPPORTED;
int fd = open("/dev/urandom", O_RDONLY);
if (fd < 0) return ERR_NOT_SUPPORTED;
// TODO: check return code? and partial reads?
read(fd, data, len);
close(fd);
return 0;
}

View File

@ -446,24 +446,13 @@ cc_bool SSLBackend_DescribeError(cc_result res, cc_string* dst) {
return false; // TODO: error codes
}
#if defined CC_BUILD_3DS
#include <3ds.h>
static void InjectEntropy(SSLContext* ctx) {
char buf[32];
PS_GenerateRandomBytes(buf, 32);
// NOTE: PS_GenerateRandomBytes isn't implemented in Citra
cc_result res = Platform_GetEntropy(buf, 32);
if (res) Platform_LogConst("SSL: Using insecure uninitialised stack data for entropy");
br_ssl_engine_inject_entropy(&ctx->sc.eng, buf, 32);
}
#else
#warning "Using uninitialised stack data for entropy. This should be replaced with actual cryptographic RNG data"
static void InjectEntropy(SSLContext* ctx) {
char buf[32];
// TODO: Use actual APIs to retrieve random data
br_ssl_engine_inject_entropy(&ctx->sc.eng, buf, 32);
}
#endif
static void SetCurrentTime(SSLContext* ctx) {
cc_uint64 cur = DateTime_CurrentUTC();

View File

@ -196,6 +196,8 @@ cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) {
return 0;
}
#ifndef CC_BUILD_3DS
cc_result Platform_GetEntropy(void* data, int len) {
return ERR_NOT_SUPPORTED;
}
#endif