diff --git a/Makefile.ctr b/Makefile.ctr index 2926ce1947..dfe5506844 100644 --- a/Makefile.ctr +++ b/Makefile.ctr @@ -100,7 +100,7 @@ else #HAVE_SOCKET_LEGACY = 1 HAVE_THREADS = 1 #HAVE_SSL = 1 - #HAVE_BUILTINMBEDTLS = 1 + HAVE_BUILTINMBEDTLS = 1 HAVE_CORE_INFO_CACHE = 1 include Makefile.common diff --git a/deps/mbedtls/mbedtls/config.h b/deps/mbedtls/mbedtls/config.h index fa1a83897f..8c566e2a81 100644 --- a/deps/mbedtls/mbedtls/config.h +++ b/deps/mbedtls/mbedtls/config.h @@ -28,6 +28,14 @@ #ifndef MBEDTLS_CONFIG_H #define MBEDTLS_CONFIG_H +#ifdef _3DS +#define unix +#define MBEDTLS_NO_IPV6 +#ifndef _SOCKLEN_T_DECLARED +#define _SOCKLEN_T_DECLARED +#endif +#endif + #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) #define _CRT_SECURE_NO_DEPRECATE 1 #endif @@ -2020,7 +2028,9 @@ * * This module is used by the HAVEGE random number generator. */ +#ifndef _3DS #define MBEDTLS_TIMING_C +#endif /** * \def MBEDTLS_VERSION_C diff --git a/deps/mbedtls/net_sockets.c b/deps/mbedtls/net_sockets.c index fc1aaa6ef4..a05b0c26df 100644 --- a/deps/mbedtls/net_sockets.c +++ b/deps/mbedtls/net_sockets.c @@ -400,6 +400,7 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx, memcpy( client_ip, &addr4->sin_addr.s_addr, *ip_len ); } +#ifndef MBEDTLS_NO_IPV6 else { struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) &client_addr; @@ -410,6 +411,7 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx, memcpy( client_ip, &addr6->sin6_addr.s6_addr, *ip_len); } +#endif } return( 0 ); diff --git a/deps/rcheevos/src/rc_compat.c b/deps/rcheevos/src/rc_compat.c index e3e6371605..9477c79cf7 100644 --- a/deps/rcheevos/src/rc_compat.c +++ b/deps/rcheevos/src/rc_compat.c @@ -3,6 +3,10 @@ #include #include +#if defined(_3DS) && !defined(_POSIX_THREADS) +#include <../rthreads/ctr_pthread.h> +#endif + #ifdef RC_C89_HELPERS int rc_strncasecmp(const char* left, const char* right, size_t length) diff --git a/libretro-common/net/net_socket_ssl_mbed.c b/libretro-common/net/net_socket_ssl_mbed.c index 41abada776..ce3ec2a1ef 100644 --- a/libretro-common/net/net_socket_ssl_mbed.c +++ b/libretro-common/net/net_socket_ssl_mbed.c @@ -25,6 +25,11 @@ #include #include +#ifdef _3DS +#include <3ds/types.h> +#include <3ds/services/ps.h> +#endif + #if defined(HAVE_BUILTINMBEDTLS) #include "../../deps/mbedtls/mbedtls/config.h" #include "../../deps/mbedtls/mbedtls/certs.h" @@ -76,6 +81,15 @@ static void ssl_debug(void *ctx, int level, fflush((FILE*)ctx); } +#ifdef _3DS +int ctr_entropy_func(void *data, unsigned char *buffer, size_t size) +{ + (void)data; + PS_GenerateRandomBytes(buffer, size); + return 0; +} +#endif + void* ssl_socket_init(int fd, const char *domain) { static const char *pers = "libretro"; @@ -98,7 +112,13 @@ void* ssl_socket_init(int fd, const char *domain) state->net_ctx.fd = fd; - if (mbedtls_ctr_drbg_seed(&state->ctr_drbg, mbedtls_entropy_func, &state->entropy, (const unsigned char*)pers, strlen(pers)) != 0) + if (mbedtls_ctr_drbg_seed(&state->ctr_drbg, +#ifdef _3DS + ctr_entropy_func, +#else + mbedtls_entropy_func, +#endif + &state->entropy, (const unsigned char*)pers, strlen(pers)) != 0) goto error; #if defined(MBEDTLS_X509_CRT_PARSE_C)