Merge pull request #17762 from pstef/ctr-mbedtls

3DS: enable mbedTLS
This commit is contained in:
LibretroAdmin 2025-04-09 13:25:38 -07:00 committed by GitHub
commit 17ac0529c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 38 additions and 2 deletions

View File

@ -100,7 +100,7 @@ else
#HAVE_SOCKET_LEGACY = 1 #HAVE_SOCKET_LEGACY = 1
HAVE_THREADS = 1 HAVE_THREADS = 1
#HAVE_SSL = 1 #HAVE_SSL = 1
#HAVE_BUILTINMBEDTLS = 1 HAVE_BUILTINMBEDTLS = 1
HAVE_CORE_INFO_CACHE = 1 HAVE_CORE_INFO_CACHE = 1
include Makefile.common include Makefile.common

View File

@ -28,6 +28,14 @@
#ifndef MBEDTLS_CONFIG_H #ifndef MBEDTLS_CONFIG_H
#define 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) #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
#define _CRT_SECURE_NO_DEPRECATE 1 #define _CRT_SECURE_NO_DEPRECATE 1
#endif #endif
@ -2020,7 +2028,9 @@
* *
* This module is used by the HAVEGE random number generator. * This module is used by the HAVEGE random number generator.
*/ */
#ifndef _3DS
#define MBEDTLS_TIMING_C #define MBEDTLS_TIMING_C
#endif
/** /**
* \def MBEDTLS_VERSION_C * \def MBEDTLS_VERSION_C

View File

@ -400,6 +400,7 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
memcpy( client_ip, &addr4->sin_addr.s_addr, *ip_len ); memcpy( client_ip, &addr4->sin_addr.s_addr, *ip_len );
} }
#ifndef MBEDTLS_NO_IPV6
else else
{ {
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) &client_addr; 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); memcpy( client_ip, &addr6->sin6_addr.s6_addr, *ip_len);
} }
#endif
} }
return( 0 ); return( 0 );

View File

@ -3,6 +3,10 @@
#include <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
#if defined(_3DS) && !defined(_POSIX_THREADS)
#include <../rthreads/ctr_pthread.h>
#endif
#ifdef RC_C89_HELPERS #ifdef RC_C89_HELPERS
int rc_strncasecmp(const char* left, const char* right, size_t length) int rc_strncasecmp(const char* left, const char* right, size_t length)

View File

@ -25,6 +25,11 @@
#include <net/net_socket.h> #include <net/net_socket.h>
#include <net/net_socket_ssl.h> #include <net/net_socket_ssl.h>
#ifdef _3DS
#include <3ds/types.h>
#include <3ds/services/ps.h>
#endif
#if defined(HAVE_BUILTINMBEDTLS) #if defined(HAVE_BUILTINMBEDTLS)
#include "../../deps/mbedtls/mbedtls/config.h" #include "../../deps/mbedtls/mbedtls/config.h"
#include "../../deps/mbedtls/mbedtls/certs.h" #include "../../deps/mbedtls/mbedtls/certs.h"
@ -76,6 +81,15 @@ static void ssl_debug(void *ctx, int level,
fflush((FILE*)ctx); 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) void* ssl_socket_init(int fd, const char *domain)
{ {
static const char *pers = "libretro"; static const char *pers = "libretro";
@ -98,7 +112,13 @@ void* ssl_socket_init(int fd, const char *domain)
state->net_ctx.fd = fd; 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; goto error;
#if defined(MBEDTLS_X509_CRT_PARSE_C) #if defined(MBEDTLS_X509_CRT_PARSE_C)