Add Nintendo Switch chiaki-lib support (#233)

This commit is contained in:
H0neyBadger 2020-05-15 11:06:54 +02:00 committed by GitHub
commit f35311bf61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 771 additions and 20 deletions

View file

@ -27,12 +27,28 @@
extern "C" {
#endif
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
#include "mbedtls/ecdh.h"
#include "mbedtls/ctr_drbg.h"
#endif
#define CHIAKI_ECDH_SECRET_SIZE 32
typedef struct chiaki_ecdh_t
{
// the following lines may lead to memory corruption
// __SWITCH__ or CHIAKI_LIB_ENABLE_MBEDTLS must be defined
// globally (whole project)
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
// mbedtls ecdh context
mbedtls_ecdh_context ctx;
// deterministic random bit generator
mbedtls_ctr_drbg_context drbg;
#else
struct ec_group_st *group;
struct ec_key_st *key_local;
#endif
} ChiakiECDH;
CHIAKI_EXPORT ChiakiErrorCode chiaki_ecdh_init(ChiakiECDH *ecdh);

View file

@ -26,6 +26,8 @@
#ifdef _WIN32
#include <winsock2.h>
#else
#include <arpa/inet.h>
#endif
#ifdef __cplusplus
@ -36,6 +38,15 @@ typedef struct chiaki_stop_pipe_t
{
#ifdef _WIN32
WSAEVENT event;
#elif defined(__SWITCH__) || defined(CHIAKI_ENABLE_SWITCH_LINUX)
// due to a lack pipe/event/socketpair
// on switch env, we use a physical socket
// to send/trigger the cancel signal
struct sockaddr_in addr;
// local stop socket file descriptor
// this fd is audited by 'select' as
// fd_set *readfds
int fd;
#else
int fds[2];
#endif