Skip to content

Commit 17ac052

Browse files
Merge pull request #17762 from pstef/ctr-mbedtls
3DS: enable mbedTLS
2 parents 634a0a9 + 1f26793 commit 17ac052

5 files changed

Lines changed: 38 additions & 2 deletions

File tree

Makefile.ctr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ else
100100
#HAVE_SOCKET_LEGACY = 1
101101
HAVE_THREADS = 1
102102
#HAVE_SSL = 1
103-
#HAVE_BUILTINMBEDTLS = 1
103+
HAVE_BUILTINMBEDTLS = 1
104104
HAVE_CORE_INFO_CACHE = 1
105105

106106
include Makefile.common

deps/mbedtls/mbedtls/config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
#ifndef MBEDTLS_CONFIG_H
2929
#define MBEDTLS_CONFIG_H
3030

31+
#ifdef _3DS
32+
#define unix
33+
#define MBEDTLS_NO_IPV6
34+
#ifndef _SOCKLEN_T_DECLARED
35+
#define _SOCKLEN_T_DECLARED
36+
#endif
37+
#endif
38+
3139
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
3240
#define _CRT_SECURE_NO_DEPRECATE 1
3341
#endif
@@ -2020,7 +2028,9 @@
20202028
*
20212029
* This module is used by the HAVEGE random number generator.
20222030
*/
2031+
#ifndef _3DS
20232032
#define MBEDTLS_TIMING_C
2033+
#endif
20242034

20252035
/**
20262036
* \def MBEDTLS_VERSION_C

deps/mbedtls/net_sockets.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
400400

401401
memcpy( client_ip, &addr4->sin_addr.s_addr, *ip_len );
402402
}
403+
#ifndef MBEDTLS_NO_IPV6
403404
else
404405
{
405406
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) &client_addr;
@@ -410,6 +411,7 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
410411

411412
memcpy( client_ip, &addr6->sin6_addr.s6_addr, *ip_len);
412413
}
414+
#endif
413415
}
414416

415417
return( 0 );

deps/rcheevos/src/rc_compat.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include <ctype.h>
44
#include <stdarg.h>
55

6+
#if defined(_3DS) && !defined(_POSIX_THREADS)
7+
#include <../rthreads/ctr_pthread.h>
8+
#endif
9+
610
#ifdef RC_C89_HELPERS
711

812
int rc_strncasecmp(const char* left, const char* right, size_t length)

libretro-common/net/net_socket_ssl_mbed.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
#include <net/net_socket.h>
2626
#include <net/net_socket_ssl.h>
2727

28+
#ifdef _3DS
29+
#include <3ds/types.h>
30+
#include <3ds/services/ps.h>
31+
#endif
32+
2833
#if defined(HAVE_BUILTINMBEDTLS)
2934
#include "../../deps/mbedtls/mbedtls/config.h"
3035
#include "../../deps/mbedtls/mbedtls/certs.h"
@@ -76,6 +81,15 @@ static void ssl_debug(void *ctx, int level,
7681
fflush((FILE*)ctx);
7782
}
7883

84+
#ifdef _3DS
85+
int ctr_entropy_func(void *data, unsigned char *buffer, size_t size)
86+
{
87+
(void)data;
88+
PS_GenerateRandomBytes(buffer, size);
89+
return 0;
90+
}
91+
#endif
92+
7993
void* ssl_socket_init(int fd, const char *domain)
8094
{
8195
static const char *pers = "libretro";
@@ -98,7 +112,13 @@ void* ssl_socket_init(int fd, const char *domain)
98112

99113
state->net_ctx.fd = fd;
100114

101-
if (mbedtls_ctr_drbg_seed(&state->ctr_drbg, mbedtls_entropy_func, &state->entropy, (const unsigned char*)pers, strlen(pers)) != 0)
115+
if (mbedtls_ctr_drbg_seed(&state->ctr_drbg,
116+
#ifdef _3DS
117+
ctr_entropy_func,
118+
#else
119+
mbedtls_entropy_func,
120+
#endif
121+
&state->entropy, (const unsigned char*)pers, strlen(pers)) != 0)
102122
goto error;
103123

104124
#if defined(MBEDTLS_X509_CRT_PARSE_C)

0 commit comments

Comments
 (0)