mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-10 07:49:57 -04:00
WIP on implementing entropy generation
This commit is contained in:
parent
84118251fb
commit
9467c8951a
@ -459,4 +459,9 @@ static cc_result GetMachineID(cc_uint32* key) {
|
|||||||
Mem_Copy(key, MACHINE_KEY, sizeof(MACHINE_KEY) - 1);
|
Mem_Copy(key, MACHINE_KEY, sizeof(MACHINE_KEY) - 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cc_result Platform_GetEntropy(void* data, int len) {
|
||||||
|
return PS_GenerateRandomBytes(data, len);
|
||||||
|
// NOTE: PS_GenerateRandomBytes isn't implemented in Citra
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1605,7 +1605,13 @@ cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cc_result Platform_GetEntropy(void* data, int len) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
15
src/SSL.c
15
src/SSL.c
@ -446,24 +446,13 @@ cc_bool SSLBackend_DescribeError(cc_result res, cc_string* dst) {
|
|||||||
return false; // TODO: error codes
|
return false; // TODO: error codes
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined CC_BUILD_3DS
|
|
||||||
#include <3ds.h>
|
|
||||||
static void InjectEntropy(SSLContext* ctx) {
|
static void InjectEntropy(SSLContext* ctx) {
|
||||||
char buf[32];
|
char buf[32];
|
||||||
PS_GenerateRandomBytes(buf, 32);
|
cc_result res = Platform_GetEntropy(buf, 32);
|
||||||
// NOTE: PS_GenerateRandomBytes isn't implemented in Citra
|
if (res) Platform_LogConst("SSL: Using insecure uninitialised stack data for entropy");
|
||||||
|
|
||||||
br_ssl_engine_inject_entropy(&ctx->sc.eng, buf, 32);
|
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) {
|
static void SetCurrentTime(SSLContext* ctx) {
|
||||||
cc_uint64 cur = DateTime_CurrentUTC();
|
cc_uint64 cur = DateTime_CurrentUTC();
|
||||||
|
@ -196,6 +196,8 @@ cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef CC_BUILD_3DS
|
||||||
cc_result Platform_GetEntropy(void* data, int len) {
|
cc_result Platform_GetEntropy(void* data, int len) {
|
||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user