Skip to content

Commit

Permalink
externals/mbedtls: Apply spresense changes from previous version
Browse files Browse the repository at this point in the history
Apply some of changes for Spresense SDK from previous version.
  • Loading branch information
SPRESENSE committed Mar 10, 2022
1 parent 29df7d5 commit abb5a67
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
6 changes: 3 additions & 3 deletions externals/mbedtls/mbedtls-v2/include/mbedtls/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@
*
* Uncomment this macro to prevent loading of default entropy functions.
*/
//#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES

/**
* \def MBEDTLS_NO_PLATFORM_ENTROPY
Expand All @@ -1247,7 +1247,7 @@
*
* Uncomment this macro to disable the built-in platform entropy functions.
*/
//#define MBEDTLS_NO_PLATFORM_ENTROPY
#define MBEDTLS_NO_PLATFORM_ENTROPY

/**
* \def MBEDTLS_ENTROPY_FORCE_SHA256
Expand Down Expand Up @@ -1485,7 +1485,7 @@
*
* Enable the checkup functions (*_self_test).
*/
#define MBEDTLS_SELF_TEST
//#define MBEDTLS_SELF_TEST

/**
* \def MBEDTLS_SHA256_SMALLER
Expand Down
9 changes: 8 additions & 1 deletion externals/mbedtls/mbedtls-v2/library/ecp.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,12 @@ void mbedtls_ecp_group_free( mbedtls_ecp_group *grp )
{
for( i = 0; i < grp->T_size; i++ )
mbedtls_ecp_point_free( &grp->T[i] );
mbedtls_free( grp->T );

if (grp->T != NULL)
{
mbedtls_free( grp->T );
grp->T = NULL;
}
}

mbedtls_platform_zeroize( grp, sizeof( mbedtls_ecp_group ) );
Expand Down Expand Up @@ -1862,6 +1867,8 @@ static int ecp_precompute_comb( const mbedtls_ecp_group *grp,
const unsigned char T_size = 1U << ( w - 1 );
mbedtls_ecp_point *cur, *TT[COMB_MAX_PRE - 1];

memset(TT, 0, COMB_MAX_PRE - 1);

#if defined(MBEDTLS_ECP_RESTARTABLE)
if( rs_ctx != NULL && rs_ctx->rsm != NULL )
{
Expand Down
15 changes: 15 additions & 0 deletions externals/mbedtls/mbedtls-v2/library/entropy.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@
#include "mbedtls/havege.h"
#endif

static int entropy_dummy_source( void *data, unsigned char *output,
size_t len, size_t *olen )
{
((void) data);

memset( output, 0x2a, len );
*olen = len;

return( 0 );
}

#define ENTROPY_MAX_LOOP 256 /**< Maximum amount to loop before error */

void mbedtls_entropy_init( mbedtls_entropy_context *ctx )
Expand Down Expand Up @@ -112,6 +123,10 @@ void mbedtls_entropy_init( mbedtls_entropy_context *ctx )
MBEDTLS_ENTROPY_SOURCE_STRONG );
ctx->initial_entropy_run = 0;
#endif
#else
mbedtls_entropy_add_source( ctx, entropy_dummy_source, NULL,
MBEDTLS_ENTROPY_MIN_HARDWARE,
MBEDTLS_ENTROPY_SOURCE_STRONG );
#endif /* MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES */
}

Expand Down
9 changes: 6 additions & 3 deletions externals/mbedtls/mbedtls-v2/library/net_sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#if !defined(unix) && !defined(__unix__) && !defined(__unix) && \
!defined(__APPLE__) && !defined(_WIN32) && !defined(__QNXNTO__) && \
!defined(__HAIKU__) && !defined(__midipix__)
!defined(__HAIKU__) && !defined(__midipix__) && !defined(__NuttX__)
#error "This module only works on Unix and Windows, see MBEDTLS_NET_C in config.h"
#endif

Expand Down Expand Up @@ -84,6 +84,7 @@ static int wsa_init_done = 0;

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
Expand Down Expand Up @@ -128,7 +129,7 @@ static int net_prepare( void )
wsa_init_done = 1;
}
#else
#if !defined(EFIX64) && !defined(EFI32)
#if !defined(EFIX64) && !defined(EFI32) && !defined(__NuttX__)
signal( SIGPIPE, SIG_IGN );
#endif
#endif
Expand Down Expand Up @@ -347,7 +348,9 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,

#if defined(__socklen_t_defined) || defined(_SOCKLEN_T) || \
defined(_SOCKLEN_T_DECLARED) || defined(__DEFINED_socklen_t) || \
defined(socklen_t) || (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L)
defined(socklen_t) || \
(defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || \
defined(__NuttX__)
socklen_t n = (socklen_t) sizeof( client_addr );
socklen_t type_len = (socklen_t) sizeof( type );
#else
Expand Down
2 changes: 1 addition & 1 deletion externals/mbedtls/mbedtls-v2/library/timing.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#if !defined(unix) && !defined(__unix__) && !defined(__unix) && \
!defined(__APPLE__) && !defined(_WIN32) && !defined(__QNXNTO__) && \
!defined(__HAIKU__) && !defined(__midipix__)
!defined(__HAIKU__) && !defined(__midipix__) && !defined(__NuttX__)
#error "This module only works on Unix and Windows, see MBEDTLS_TIMING_C in config.h"
#endif

Expand Down

0 comments on commit abb5a67

Please sign in to comment.