mirror of
https://github.com/libretro/RetroArch
synced 2025-04-01 13:20:43 +00:00
(deps/mbedtls) Cleanups
This commit is contained in:
parent
996840d2d4
commit
3580db3ebe
21
deps/mbedtls/asn1write.c
vendored
21
deps/mbedtls/asn1write.c
vendored
@ -33,11 +33,8 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len )
|
||||
{
|
||||
@ -334,27 +331,27 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data
|
||||
if( ( cur = mbedtls_asn1_find_named_data( *head, oid, oid_len ) ) == NULL )
|
||||
{
|
||||
/* Add new entry if not present yet based on OID */
|
||||
cur = (mbedtls_asn1_named_data*)mbedtls_calloc( 1,
|
||||
cur = (mbedtls_asn1_named_data*)calloc( 1,
|
||||
sizeof(mbedtls_asn1_named_data) );
|
||||
if( cur == NULL )
|
||||
return( NULL );
|
||||
|
||||
cur->oid.len = oid_len;
|
||||
cur->oid.p = (unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)mbedtls_calloc( 1, oid_len );
|
||||
cur->oid.p = (unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)calloc( 1, oid_len );
|
||||
if( cur->oid.p == NULL )
|
||||
{
|
||||
mbedtls_free( cur );
|
||||
free( cur );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
memcpy( cur->oid.p, oid, oid_len );
|
||||
|
||||
cur->val.len = val_len;
|
||||
cur->val.p = (unsigned char*)mbedtls_calloc( 1, val_len );
|
||||
cur->val.p = (unsigned char*)calloc( 1, val_len );
|
||||
if( cur->val.p == NULL )
|
||||
{
|
||||
mbedtls_free( cur->oid.p );
|
||||
mbedtls_free( cur );
|
||||
free( cur->oid.p );
|
||||
free( cur );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
@ -368,11 +365,11 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data
|
||||
* Preserve old data until the allocation succeeded, to leave list in
|
||||
* a consistent state in case allocation fails.
|
||||
*/
|
||||
void *p = mbedtls_calloc( 1, val_len );
|
||||
void *p = calloc( 1, val_len );
|
||||
if( p == NULL )
|
||||
return( NULL );
|
||||
|
||||
mbedtls_free( cur->val.p );
|
||||
free( cur->val.p );
|
||||
cur->val.p = (unsigned char*)p;
|
||||
cur->val.len = val_len;
|
||||
}
|
||||
|
18
deps/mbedtls/bignum.c
vendored
18
deps/mbedtls/bignum.c
vendored
@ -50,13 +50,9 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
/* Implementation that should never be optimized out by the compiler */
|
||||
static void mbedtls_mpi_zeroize( mbedtls_mpi_uint *v, size_t n ) {
|
||||
@ -100,7 +96,7 @@ void mbedtls_mpi_free( mbedtls_mpi *X )
|
||||
if( X->p != NULL )
|
||||
{
|
||||
mbedtls_mpi_zeroize( X->p, X->n );
|
||||
mbedtls_free( X->p );
|
||||
free( X->p );
|
||||
}
|
||||
|
||||
X->s = 1;
|
||||
@ -120,14 +116,14 @@ int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs )
|
||||
|
||||
if( X->n < nblimbs )
|
||||
{
|
||||
if( ( p = (mbedtls_mpi_uint*)mbedtls_calloc( nblimbs, ciL ) ) == NULL )
|
||||
if( ( p = (mbedtls_mpi_uint*)calloc( nblimbs, ciL ) ) == NULL )
|
||||
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
|
||||
|
||||
if( X->p != NULL )
|
||||
{
|
||||
memcpy( p, X->p, X->n * ciL );
|
||||
mbedtls_mpi_zeroize( X->p, X->n );
|
||||
mbedtls_free( X->p );
|
||||
free( X->p );
|
||||
}
|
||||
|
||||
X->n = nblimbs;
|
||||
@ -158,14 +154,14 @@ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs )
|
||||
if( i < nblimbs )
|
||||
i = nblimbs;
|
||||
|
||||
if( ( p = (mbedtls_mpi_uint*)mbedtls_calloc( i, ciL ) ) == NULL )
|
||||
if( ( p = (mbedtls_mpi_uint*)calloc( i, ciL ) ) == NULL )
|
||||
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
|
||||
|
||||
if( X->p != NULL )
|
||||
{
|
||||
memcpy( p, X->p, i * ciL );
|
||||
mbedtls_mpi_zeroize( X->p, X->n );
|
||||
mbedtls_free( X->p );
|
||||
free( X->p );
|
||||
}
|
||||
|
||||
X->n = i;
|
||||
@ -658,7 +654,7 @@ int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, int radix, FILE
|
||||
return( MBEDTLS_ERR_MPI_FILE_IO_ERROR );
|
||||
}
|
||||
else
|
||||
mbedtls_printf( "%s%s", p, s );
|
||||
printf( "%s%s", p, s );
|
||||
|
||||
cleanup:
|
||||
|
||||
|
3
deps/mbedtls/cipher.c
vendored
3
deps/mbedtls/cipher.c
vendored
@ -47,9 +47,6 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
||||
|
37
deps/mbedtls/cipher_wrap.c
vendored
37
deps/mbedtls/cipher_wrap.c
vendored
@ -67,17 +67,14 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(MBEDTLS_GCM_C)
|
||||
/* shared by all GCM ciphers */
|
||||
static void *gcm_ctx_alloc( void )
|
||||
{
|
||||
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
|
||||
void *ctx = calloc( 1, sizeof( mbedtls_gcm_context ) );
|
||||
|
||||
if( ctx != NULL )
|
||||
mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
|
||||
@ -88,7 +85,7 @@ static void *gcm_ctx_alloc( void )
|
||||
static void gcm_ctx_free( void *ctx )
|
||||
{
|
||||
mbedtls_gcm_free((mbedtls_gcm_context*)ctx);
|
||||
mbedtls_free(ctx);
|
||||
free(ctx);
|
||||
}
|
||||
#endif /* MBEDTLS_GCM_C */
|
||||
|
||||
@ -96,7 +93,7 @@ static void gcm_ctx_free( void *ctx )
|
||||
/* shared by all CCM ciphers */
|
||||
static void *ccm_ctx_alloc( void )
|
||||
{
|
||||
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
|
||||
void *ctx = calloc( 1, sizeof( mbedtls_ccm_context ) );
|
||||
|
||||
if( ctx != NULL )
|
||||
mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
|
||||
@ -107,7 +104,7 @@ static void *ccm_ctx_alloc( void )
|
||||
static void ccm_ctx_free( void *ctx )
|
||||
{
|
||||
mbedtls_ccm_free((mbedtls_ccm_context*)ctx);
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
#endif /* MBEDTLS_CCM_C */
|
||||
|
||||
@ -162,7 +159,7 @@ static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
|
||||
|
||||
static void * aes_ctx_alloc( void )
|
||||
{
|
||||
mbedtls_aes_context *aes = (mbedtls_aes_context*)mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
|
||||
mbedtls_aes_context *aes = (mbedtls_aes_context*)calloc( 1, sizeof( mbedtls_aes_context ) );
|
||||
|
||||
if( aes == NULL )
|
||||
return( NULL );
|
||||
@ -175,7 +172,7 @@ static void * aes_ctx_alloc( void )
|
||||
static void aes_ctx_free( void *ctx )
|
||||
{
|
||||
mbedtls_aes_free( (mbedtls_aes_context *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
static const mbedtls_cipher_base_t aes_info = {
|
||||
@ -519,7 +516,7 @@ static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
|
||||
static void * camellia_ctx_alloc( void )
|
||||
{
|
||||
mbedtls_camellia_context *ctx = (mbedtls_camellia_context*)
|
||||
mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
|
||||
calloc( 1, sizeof( mbedtls_camellia_context ) );
|
||||
|
||||
if( ctx == NULL )
|
||||
return( NULL );
|
||||
@ -532,7 +529,7 @@ static void * camellia_ctx_alloc( void )
|
||||
static void camellia_ctx_free( void *ctx )
|
||||
{
|
||||
mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
static const mbedtls_cipher_base_t camellia_info = {
|
||||
@ -907,7 +904,7 @@ static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
|
||||
static void * des_ctx_alloc( void )
|
||||
{
|
||||
mbedtls_des_context *des = (mbedtls_des_context*)
|
||||
mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
|
||||
calloc( 1, sizeof( mbedtls_des_context ) );
|
||||
|
||||
if( des == NULL )
|
||||
return( NULL );
|
||||
@ -920,12 +917,12 @@ static void * des_ctx_alloc( void )
|
||||
static void des_ctx_free( void *ctx )
|
||||
{
|
||||
mbedtls_des_free( (mbedtls_des_context *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
static void * des3_ctx_alloc( void )
|
||||
{
|
||||
mbedtls_des3_context *des3 = (mbedtls_des3_context*)mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
|
||||
mbedtls_des3_context *des3 = (mbedtls_des3_context*)calloc( 1, sizeof( mbedtls_des3_context ) );
|
||||
|
||||
if( des3 == NULL )
|
||||
return( NULL );
|
||||
@ -938,7 +935,7 @@ static void * des3_ctx_alloc( void )
|
||||
static void des3_ctx_free( void *ctx )
|
||||
{
|
||||
mbedtls_des3_free( (mbedtls_des3_context *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
static const mbedtls_cipher_base_t des_info = {
|
||||
@ -1123,7 +1120,7 @@ static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
|
||||
static void * blowfish_ctx_alloc( void )
|
||||
{
|
||||
mbedtls_blowfish_context *ctx = (mbedtls_blowfish_context*)mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
|
||||
mbedtls_blowfish_context *ctx = (mbedtls_blowfish_context*)calloc( 1, sizeof( mbedtls_blowfish_context ) );
|
||||
|
||||
if( ctx == NULL )
|
||||
return( NULL );
|
||||
@ -1136,7 +1133,7 @@ static void * blowfish_ctx_alloc( void )
|
||||
static void blowfish_ctx_free( void *ctx )
|
||||
{
|
||||
mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
static const mbedtls_cipher_base_t blowfish_info = {
|
||||
@ -1232,7 +1229,7 @@ static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
|
||||
static void * arc4_ctx_alloc( void )
|
||||
{
|
||||
mbedtls_arc4_context *ctx = (mbedtls_arc4_context*)mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
|
||||
mbedtls_arc4_context *ctx = (mbedtls_arc4_context*)calloc( 1, sizeof( mbedtls_arc4_context ) );
|
||||
|
||||
if( ctx == NULL )
|
||||
return( NULL );
|
||||
@ -1245,7 +1242,7 @@ static void * arc4_ctx_alloc( void )
|
||||
static void arc4_ctx_free( void *ctx )
|
||||
{
|
||||
mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
static const mbedtls_cipher_base_t arc4_base_info = {
|
||||
|
12
deps/mbedtls/dhm.c
vendored
12
deps/mbedtls/dhm.c
vendored
@ -49,13 +49,9 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
#include "arc4_alt.h"
|
||||
|
||||
@ -530,7 +526,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n )
|
||||
*n = (size_t) size;
|
||||
|
||||
if( *n + 1 == 0 ||
|
||||
( *buf = (unsigned char*)mbedtls_calloc( 1, *n + 1 ) ) == NULL )
|
||||
( *buf = (unsigned char*)calloc( 1, *n + 1 ) ) == NULL )
|
||||
{
|
||||
fclose( f );
|
||||
return( MBEDTLS_ERR_DHM_ALLOC_FAILED );
|
||||
@ -539,7 +535,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n )
|
||||
if( fread( *buf, 1, *n, f ) != *n )
|
||||
{
|
||||
fclose( f );
|
||||
mbedtls_free( *buf );
|
||||
free( *buf );
|
||||
return( MBEDTLS_ERR_DHM_FILE_IO_ERROR );
|
||||
}
|
||||
|
||||
@ -568,7 +564,7 @@ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path )
|
||||
ret = mbedtls_dhm_parse_dhm( dhm, buf, n );
|
||||
|
||||
mbedtls_zeroize( buf, n );
|
||||
mbedtls_free( buf );
|
||||
free( buf );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
16
deps/mbedtls/ecp.c
vendored
16
deps/mbedtls/ecp.c
vendored
@ -57,13 +57,9 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
#include "mbedtls/ecp_internal.h"
|
||||
|
||||
@ -331,7 +327,7 @@ 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 );
|
||||
free( grp->T );
|
||||
}
|
||||
|
||||
mbedtls_zeroize( grp, sizeof( mbedtls_ecp_group ) );
|
||||
@ -798,7 +794,7 @@ static int ecp_normalize_jac_many( const mbedtls_ecp_group *grp,
|
||||
}
|
||||
#endif
|
||||
|
||||
if( ( c = (mbedtls_mpi*)mbedtls_calloc( t_len, sizeof( mbedtls_mpi ) ) ) == NULL )
|
||||
if( ( c = (mbedtls_mpi*)calloc( t_len, sizeof( mbedtls_mpi ) ) ) == NULL )
|
||||
return( MBEDTLS_ERR_ECP_ALLOC_FAILED );
|
||||
|
||||
mbedtls_mpi_init( &u ); mbedtls_mpi_init( &Zi ); mbedtls_mpi_init( &ZZi );
|
||||
@ -860,7 +856,7 @@ cleanup:
|
||||
mbedtls_mpi_free( &u ); mbedtls_mpi_free( &Zi ); mbedtls_mpi_free( &ZZi );
|
||||
for( i = 0; i < t_len; i++ )
|
||||
mbedtls_mpi_free( &c[i] );
|
||||
mbedtls_free( c );
|
||||
free( c );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
@ -1385,7 +1381,7 @@ static int ecp_mul_comb( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
|
||||
if( T == NULL )
|
||||
{
|
||||
T = (mbedtls_ecp_point*)mbedtls_calloc( pre_len, sizeof( mbedtls_ecp_point ) );
|
||||
T = (mbedtls_ecp_point*)calloc( pre_len, sizeof( mbedtls_ecp_point ) );
|
||||
if( T == NULL )
|
||||
{
|
||||
ret = MBEDTLS_ERR_ECP_ALLOC_FAILED;
|
||||
@ -1428,7 +1424,7 @@ cleanup:
|
||||
{
|
||||
for( i = 0; i < pre_len; i++ )
|
||||
mbedtls_ecp_point_free( &T[i] );
|
||||
mbedtls_free( T );
|
||||
free( T );
|
||||
}
|
||||
|
||||
mbedtls_mpi_free( &M );
|
||||
|
8
deps/mbedtls/mbedtls/compat-1.3.h
vendored
8
deps/mbedtls/mbedtls/compat-1.3.h
vendored
@ -2101,14 +2101,14 @@
|
||||
#define platform_set_printf mbedtls_platform_set_printf
|
||||
#define platform_set_snprintf mbedtls_platform_set_snprintf
|
||||
#define polarssl_exit mbedtls_exit
|
||||
#define polarssl_fprintf mbedtls_fprintf
|
||||
#define polarssl_free mbedtls_free
|
||||
#define polarssl_fprintf fprintf
|
||||
#define polarssl_free free
|
||||
#define polarssl_mutex_free mbedtls_mutex_free
|
||||
#define polarssl_mutex_init mbedtls_mutex_init
|
||||
#define polarssl_mutex_lock mbedtls_mutex_lock
|
||||
#define polarssl_mutex_unlock mbedtls_mutex_unlock
|
||||
#define polarssl_printf mbedtls_printf
|
||||
#define polarssl_snprintf mbedtls_snprintf
|
||||
#define polarssl_printf printf
|
||||
#define polarssl_snprintf snprintf
|
||||
#define polarssl_strerror mbedtls_strerror
|
||||
#define ripemd160 mbedtls_ripemd160
|
||||
#define ripemd160_context mbedtls_ripemd160_context
|
||||
|
74
deps/mbedtls/mbedtls/platform.h
vendored
74
deps/mbedtls/mbedtls/platform.h
vendored
@ -69,82 +69,8 @@ extern "C" {
|
||||
|
||||
/* \} name SECTION: Module settings */
|
||||
|
||||
/*
|
||||
* The function pointers for calloc and free
|
||||
*/
|
||||
#if defined(MBEDTLS_PLATFORM_MEMORY)
|
||||
#if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
|
||||
defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
|
||||
#define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
|
||||
#define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO
|
||||
#else
|
||||
/* For size_t */
|
||||
#include <stddef.h>
|
||||
extern void * (*mbedtls_calloc)( size_t n, size_t size );
|
||||
extern void (*mbedtls_free)( void *ptr );
|
||||
|
||||
/**
|
||||
* \brief Set your own memory implementation function pointers
|
||||
*
|
||||
* \param calloc_func the calloc function implementation
|
||||
* \param free_func the free function implementation
|
||||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
|
||||
void (*free_func)( void * ) );
|
||||
#endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */
|
||||
#else /* !MBEDTLS_PLATFORM_MEMORY */
|
||||
#define mbedtls_free free
|
||||
#define mbedtls_calloc calloc
|
||||
#endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */
|
||||
|
||||
/*
|
||||
* The function pointers for fprintf
|
||||
*/
|
||||
#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
|
||||
/* We need FILE * */
|
||||
#include <stdio.h>
|
||||
extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... );
|
||||
|
||||
/**
|
||||
* \brief Set your own fprintf function pointer
|
||||
*
|
||||
* \param fprintf_func the fprintf function implementation
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
|
||||
... ) );
|
||||
#else
|
||||
#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
|
||||
#define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
|
||||
#else
|
||||
#define mbedtls_fprintf fprintf
|
||||
#endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */
|
||||
#endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
|
||||
|
||||
/*
|
||||
* The function pointers for printf
|
||||
*/
|
||||
#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
|
||||
extern int (*mbedtls_printf)( const char *format, ... );
|
||||
|
||||
/**
|
||||
* \brief Set your own printf function pointer
|
||||
*
|
||||
* \param printf_func the printf function implementation
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) );
|
||||
#else /* !MBEDTLS_PLATFORM_PRINTF_ALT */
|
||||
#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
|
||||
#define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
|
||||
#else
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */
|
||||
#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
|
||||
|
||||
/*
|
||||
* The function pointers for exit
|
||||
|
9
deps/mbedtls/md.c
vendored
9
deps/mbedtls/md.c
vendored
@ -36,11 +36,8 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -167,7 +164,7 @@ void mbedtls_md_free( mbedtls_md_context_t *ctx )
|
||||
if( ctx->hmac_ctx != NULL )
|
||||
{
|
||||
mbedtls_zeroize( ctx->hmac_ctx, 2 * ctx->md_info->block_size );
|
||||
mbedtls_free( ctx->hmac_ctx );
|
||||
free( ctx->hmac_ctx );
|
||||
}
|
||||
|
||||
mbedtls_zeroize( ctx, sizeof( mbedtls_md_context_t ) );
|
||||
@ -203,7 +200,7 @@ int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_inf
|
||||
|
||||
if( hmac != 0 )
|
||||
{
|
||||
ctx->hmac_ctx = mbedtls_calloc( 2, md_info->block_size );
|
||||
ctx->hmac_ctx = calloc( 2, md_info->block_size );
|
||||
if( ctx->hmac_ctx == NULL )
|
||||
{
|
||||
md_info->ctx_free_func( ctx->md_ctx );
|
||||
|
25
deps/mbedtls/md_wrap.c
vendored
25
deps/mbedtls/md_wrap.c
vendored
@ -55,11 +55,8 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
|
||||
@ -81,7 +78,7 @@ static void md5_finish_wrap( void *ctx, unsigned char *output )
|
||||
|
||||
static void *md5_ctx_alloc( void )
|
||||
{
|
||||
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md5_context ) );
|
||||
void *ctx = calloc( 1, sizeof( mbedtls_md5_context ) );
|
||||
|
||||
if( ctx != NULL )
|
||||
mbedtls_md5_init( (mbedtls_md5_context *) ctx );
|
||||
@ -92,7 +89,7 @@ static void *md5_ctx_alloc( void )
|
||||
static void md5_ctx_free( void *ctx )
|
||||
{
|
||||
mbedtls_md5_free( (mbedtls_md5_context *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
static void md5_clone_wrap( void *dst, const void *src )
|
||||
@ -143,7 +140,7 @@ static void ripemd160_finish_wrap( void *ctx, unsigned char *output )
|
||||
|
||||
static void *ripemd160_ctx_alloc( void )
|
||||
{
|
||||
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ripemd160_context ) );
|
||||
void *ctx = calloc( 1, sizeof( mbedtls_ripemd160_context ) );
|
||||
|
||||
if( ctx != NULL )
|
||||
mbedtls_ripemd160_init( (mbedtls_ripemd160_context *) ctx );
|
||||
@ -154,7 +151,7 @@ static void *ripemd160_ctx_alloc( void )
|
||||
static void ripemd160_ctx_free( void *ctx )
|
||||
{
|
||||
mbedtls_ripemd160_free( (mbedtls_ripemd160_context *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
static void ripemd160_clone_wrap( void *dst, const void *src )
|
||||
@ -205,7 +202,7 @@ static void sha1_finish_wrap( void *ctx, unsigned char *output )
|
||||
|
||||
static void *sha1_ctx_alloc( void )
|
||||
{
|
||||
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha1_context ) );
|
||||
void *ctx = calloc( 1, sizeof( mbedtls_sha1_context ) );
|
||||
|
||||
if( ctx != NULL )
|
||||
mbedtls_sha1_init( (mbedtls_sha1_context *) ctx );
|
||||
@ -222,7 +219,7 @@ static void sha1_clone_wrap( void *dst, const void *src )
|
||||
static void sha1_ctx_free( void *ctx )
|
||||
{
|
||||
mbedtls_sha1_free( (mbedtls_sha1_context *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
static void sha1_process_wrap( void *ctx, const unsigned char *data )
|
||||
@ -276,7 +273,7 @@ static void sha224_wrap( const unsigned char *input, size_t ilen,
|
||||
|
||||
static void *sha224_ctx_alloc( void )
|
||||
{
|
||||
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) );
|
||||
void *ctx = calloc( 1, sizeof( mbedtls_sha256_context ) );
|
||||
|
||||
if( ctx != NULL )
|
||||
mbedtls_sha256_init( (mbedtls_sha256_context *) ctx );
|
||||
@ -287,7 +284,7 @@ static void *sha224_ctx_alloc( void )
|
||||
static void sha224_ctx_free( void *ctx )
|
||||
{
|
||||
mbedtls_sha256_free( (mbedtls_sha256_context *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
static void sha224_clone_wrap( void *dst, const void *src )
|
||||
@ -370,7 +367,7 @@ static void sha384_wrap( const unsigned char *input, size_t ilen,
|
||||
|
||||
static void *sha384_ctx_alloc( void )
|
||||
{
|
||||
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) );
|
||||
void *ctx = calloc( 1, sizeof( mbedtls_sha512_context ) );
|
||||
|
||||
if( ctx != NULL )
|
||||
mbedtls_sha512_init( (mbedtls_sha512_context *) ctx );
|
||||
@ -381,7 +378,7 @@ static void *sha384_ctx_alloc( void )
|
||||
static void sha384_ctx_free( void *ctx )
|
||||
{
|
||||
mbedtls_sha512_free( (mbedtls_sha512_context *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
static void sha384_clone_wrap( void *dst, const void *src )
|
||||
|
25
deps/mbedtls/pem.c
vendored
25
deps/mbedtls/pem.c
vendored
@ -38,11 +38,8 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(MBEDTLS_PEM_PARSE_C)
|
||||
#include "arc4_alt.h"
|
||||
@ -323,12 +320,12 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
||||
if( ret == MBEDTLS_ERR_BASE64_INVALID_CHARACTER )
|
||||
return( MBEDTLS_ERR_PEM_INVALID_DATA + ret );
|
||||
|
||||
if( ( buf = (unsigned char*)mbedtls_calloc( 1, len ) ) == NULL )
|
||||
if( ( buf = (unsigned char*)calloc( 1, len ) ) == NULL )
|
||||
return( MBEDTLS_ERR_PEM_ALLOC_FAILED );
|
||||
|
||||
if( ( ret = mbedtls_base64_decode( buf, len, &len, s1, s2 - s1 ) ) != 0 )
|
||||
{
|
||||
mbedtls_free( buf );
|
||||
free( buf );
|
||||
return( MBEDTLS_ERR_PEM_INVALID_DATA + ret );
|
||||
}
|
||||
|
||||
@ -338,7 +335,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
||||
( defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) )
|
||||
if( pwd == NULL )
|
||||
{
|
||||
mbedtls_free( buf );
|
||||
free( buf );
|
||||
return( MBEDTLS_ERR_PEM_PASSWORD_REQUIRED );
|
||||
}
|
||||
|
||||
@ -366,11 +363,11 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
||||
*/
|
||||
if( len <= 2 || buf[0] != 0x30 || buf[1] > 0x83 )
|
||||
{
|
||||
mbedtls_free( buf );
|
||||
free( buf );
|
||||
return( MBEDTLS_ERR_PEM_PASSWORD_MISMATCH );
|
||||
}
|
||||
#else
|
||||
mbedtls_free( buf );
|
||||
free( buf );
|
||||
return( MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE );
|
||||
#endif /* MBEDTLS_MD5_C && MBEDTLS_CIPHER_MODE_CBC &&
|
||||
( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
|
||||
@ -384,8 +381,8 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
||||
|
||||
void mbedtls_pem_free( mbedtls_pem_context *ctx )
|
||||
{
|
||||
mbedtls_free( ctx->buf );
|
||||
mbedtls_free( ctx->info );
|
||||
free( ctx->buf );
|
||||
free( ctx->info );
|
||||
|
||||
mbedtls_zeroize( ctx, sizeof( mbedtls_pem_context ) );
|
||||
}
|
||||
@ -409,13 +406,13 @@ int mbedtls_pem_write_buffer( const char *header, const char *footer,
|
||||
return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
|
||||
}
|
||||
|
||||
if( ( encode_buf = (unsigned char*)mbedtls_calloc( 1, use_len ) ) == NULL )
|
||||
if( ( encode_buf = (unsigned char*)calloc( 1, use_len ) ) == NULL )
|
||||
return( MBEDTLS_ERR_PEM_ALLOC_FAILED );
|
||||
|
||||
if( ( ret = mbedtls_base64_encode( encode_buf, use_len, &use_len, der_data,
|
||||
der_len ) ) != 0 )
|
||||
{
|
||||
mbedtls_free( encode_buf );
|
||||
free( encode_buf );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
@ -439,7 +436,7 @@ int mbedtls_pem_write_buffer( const char *header, const char *footer,
|
||||
*p++ = '\0';
|
||||
*olen = p - buf;
|
||||
|
||||
mbedtls_free( encode_buf );
|
||||
free( encode_buf );
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_PEM_WRITE_C */
|
||||
|
21
deps/mbedtls/pk_wrap.c
vendored
21
deps/mbedtls/pk_wrap.c
vendored
@ -44,11 +44,8 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
@ -143,7 +140,7 @@ static int rsa_check_pair_wrap( const void *pub, const void *prv )
|
||||
|
||||
static void *rsa_alloc_wrap( void )
|
||||
{
|
||||
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_rsa_context ) );
|
||||
void *ctx = calloc( 1, sizeof( mbedtls_rsa_context ) );
|
||||
|
||||
if( ctx != NULL )
|
||||
mbedtls_rsa_init( (mbedtls_rsa_context *) ctx, 0, 0 );
|
||||
@ -154,7 +151,7 @@ static void *rsa_alloc_wrap( void )
|
||||
static void rsa_free_wrap( void *ctx )
|
||||
{
|
||||
mbedtls_rsa_free( (mbedtls_rsa_context *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
static void rsa_debug( const void *ctx, mbedtls_pk_debug_item *items )
|
||||
@ -259,7 +256,7 @@ static int eckey_check_pair( const void *pub, const void *prv )
|
||||
|
||||
static void *eckey_alloc_wrap( void )
|
||||
{
|
||||
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecp_keypair ) );
|
||||
void *ctx = calloc( 1, sizeof( mbedtls_ecp_keypair ) );
|
||||
|
||||
if( ctx != NULL )
|
||||
mbedtls_ecp_keypair_init( ctx );
|
||||
@ -270,7 +267,7 @@ static void *eckey_alloc_wrap( void )
|
||||
static void eckey_free_wrap( void *ctx )
|
||||
{
|
||||
mbedtls_ecp_keypair_free( (mbedtls_ecp_keypair *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
static void eckey_debug( const void *ctx, mbedtls_pk_debug_item *items )
|
||||
@ -358,7 +355,7 @@ static int ecdsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
|
||||
|
||||
static void *ecdsa_alloc_wrap( void )
|
||||
{
|
||||
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecdsa_context ) );
|
||||
void *ctx = calloc( 1, sizeof( mbedtls_ecdsa_context ) );
|
||||
|
||||
if( ctx != NULL )
|
||||
mbedtls_ecdsa_init( (mbedtls_ecdsa_context *) ctx );
|
||||
@ -369,7 +366,7 @@ static void *ecdsa_alloc_wrap( void )
|
||||
static void ecdsa_free_wrap( void *ctx )
|
||||
{
|
||||
mbedtls_ecdsa_free( (mbedtls_ecdsa_context *) ctx );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
const mbedtls_pk_info_t mbedtls_ecdsa_info = {
|
||||
@ -472,7 +469,7 @@ static int rsa_alt_check_pair( const void *pub, const void *prv )
|
||||
|
||||
static void *rsa_alt_alloc_wrap( void )
|
||||
{
|
||||
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_rsa_alt_context ) );
|
||||
void *ctx = calloc( 1, sizeof( mbedtls_rsa_alt_context ) );
|
||||
|
||||
if( ctx != NULL )
|
||||
memset( ctx, 0, sizeof( mbedtls_rsa_alt_context ) );
|
||||
@ -483,7 +480,7 @@ static void *rsa_alt_alloc_wrap( void )
|
||||
static void rsa_alt_free_wrap( void *ctx )
|
||||
{
|
||||
mbedtls_zeroize( ctx, sizeof( mbedtls_rsa_alt_context ) );
|
||||
mbedtls_free( ctx );
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
const mbedtls_pk_info_t mbedtls_rsa_alt_info = {
|
||||
|
4
deps/mbedtls/pkcs5.c
vendored
4
deps/mbedtls/pkcs5.c
vendored
@ -46,10 +46,8 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
static int pkcs5_parse_pbkdf2_params( const mbedtls_asn1_buf *params,
|
||||
mbedtls_asn1_buf *salt, int *iterations,
|
||||
|
13
deps/mbedtls/pkparse.c
vendored
13
deps/mbedtls/pkparse.c
vendored
@ -54,11 +54,8 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
#include "arc4_alt.h"
|
||||
@ -89,7 +86,7 @@ int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n )
|
||||
*n = (size_t) size;
|
||||
|
||||
if( *n + 1 == 0 ||
|
||||
( *buf = mbedtls_calloc( 1, *n + 1 ) ) == NULL )
|
||||
( *buf = calloc( 1, *n + 1 ) ) == NULL )
|
||||
{
|
||||
fclose( f );
|
||||
return( MBEDTLS_ERR_PK_ALLOC_FAILED );
|
||||
@ -98,7 +95,7 @@ int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n )
|
||||
if( fread( *buf, 1, *n, f ) != *n )
|
||||
{
|
||||
fclose( f );
|
||||
mbedtls_free( *buf );
|
||||
free( *buf );
|
||||
return( MBEDTLS_ERR_PK_FILE_IO_ERROR );
|
||||
}
|
||||
|
||||
@ -132,7 +129,7 @@ int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx,
|
||||
(const unsigned char *) pwd, strlen( pwd ) );
|
||||
|
||||
mbedtls_zeroize( buf, n );
|
||||
mbedtls_free( buf );
|
||||
free( buf );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
@ -152,7 +149,7 @@ int mbedtls_pk_parse_public_keyfile( mbedtls_pk_context *ctx, const char *path )
|
||||
ret = mbedtls_pk_parse_public_key( ctx, buf, n );
|
||||
|
||||
mbedtls_zeroize( buf, n );
|
||||
mbedtls_free( buf );
|
||||
free( buf );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
5
deps/mbedtls/pkwrite.c
vendored
5
deps/mbedtls/pkwrite.c
vendored
@ -48,11 +48,8 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
/*
|
||||
|
48
deps/mbedtls/platform.c
vendored
48
deps/mbedtls/platform.c
vendored
@ -29,54 +29,6 @@
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
|
||||
/*
|
||||
* Make dummy function to prevent NULL pointer dereferences
|
||||
*/
|
||||
static int platform_printf_uninit( const char *format, ... )
|
||||
{
|
||||
((void) format);
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_PRINTF platform_printf_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_PRINTF */
|
||||
|
||||
int (*mbedtls_printf)( const char *, ... ) = MBEDTLS_PLATFORM_STD_PRINTF;
|
||||
|
||||
int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) )
|
||||
{
|
||||
mbedtls_printf = printf_func;
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
|
||||
/*
|
||||
* Make dummy function to prevent NULL pointer dereferences
|
||||
*/
|
||||
static int platform_fprintf_uninit( FILE *stream, const char *format, ... )
|
||||
{
|
||||
((void) stream);
|
||||
((void) format);
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_FPRINTF platform_fprintf_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_FPRINTF */
|
||||
|
||||
int (*mbedtls_fprintf)( FILE *, const char *, ... ) =
|
||||
MBEDTLS_PLATFORM_STD_FPRINTF;
|
||||
|
||||
int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
|
||||
{
|
||||
mbedtls_fprintf = fprintf_func;
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
|
||||
/*
|
||||
|
16
deps/mbedtls/rsa.c
vendored
16
deps/mbedtls/rsa.c
vendored
@ -59,12 +59,8 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#include "arc4_alt.h"
|
||||
|
||||
@ -1202,14 +1198,14 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
|
||||
* In order to prevent Lenstra's attack, make the signature in a
|
||||
* temporary buffer and check it before returning it.
|
||||
*/
|
||||
sig_try = mbedtls_calloc( 1, ctx->len );
|
||||
sig_try = calloc( 1, ctx->len );
|
||||
if( sig_try == NULL )
|
||||
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
|
||||
|
||||
verif = mbedtls_calloc( 1, ctx->len );
|
||||
verif = calloc( 1, ctx->len );
|
||||
if( verif == NULL )
|
||||
{
|
||||
mbedtls_free( sig_try );
|
||||
free( sig_try );
|
||||
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
|
||||
}
|
||||
|
||||
@ -1230,8 +1226,8 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
|
||||
memcpy( sig, sig_try, ctx->len );
|
||||
|
||||
cleanup:
|
||||
mbedtls_free( sig_try );
|
||||
mbedtls_free( verif );
|
||||
free( sig_try );
|
||||
free( verif );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
19
deps/mbedtls/ssl_cache.c
vendored
19
deps/mbedtls/ssl_cache.c
vendored
@ -33,11 +33,8 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "mbedtls/ssl_cache.h"
|
||||
|
||||
@ -102,7 +99,7 @@ int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session )
|
||||
*/
|
||||
if( entry->peer_cert.p != NULL )
|
||||
{
|
||||
if( ( session->peer_cert = mbedtls_calloc( 1,
|
||||
if( ( session->peer_cert = calloc( 1,
|
||||
sizeof(mbedtls_x509_crt) ) ) == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
@ -113,7 +110,7 @@ int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session )
|
||||
if( mbedtls_x509_crt_parse( session->peer_cert, entry->peer_cert.p,
|
||||
entry->peer_cert.len ) != 0 )
|
||||
{
|
||||
mbedtls_free( session->peer_cert );
|
||||
free( session->peer_cert );
|
||||
session->peer_cert = NULL;
|
||||
ret = 1;
|
||||
goto exit;
|
||||
@ -221,7 +218,7 @@ int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
|
||||
/*
|
||||
* max_entries not reached, create new entry
|
||||
*/
|
||||
cur = mbedtls_calloc( 1, sizeof(mbedtls_ssl_cache_entry) );
|
||||
cur = calloc( 1, sizeof(mbedtls_ssl_cache_entry) );
|
||||
if( cur == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
@ -247,7 +244,7 @@ int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
|
||||
*/
|
||||
if( cur->peer_cert.p != NULL )
|
||||
{
|
||||
mbedtls_free( cur->peer_cert.p );
|
||||
free( cur->peer_cert.p );
|
||||
memset( &cur->peer_cert, 0, sizeof(mbedtls_x509_buf) );
|
||||
}
|
||||
|
||||
@ -256,7 +253,7 @@ int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
|
||||
*/
|
||||
if( session->peer_cert != NULL )
|
||||
{
|
||||
cur->peer_cert.p = mbedtls_calloc( 1, session->peer_cert->raw.len );
|
||||
cur->peer_cert.p = calloc( 1, session->peer_cert->raw.len );
|
||||
if( cur->peer_cert.p == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
@ -312,10 +309,10 @@ void mbedtls_ssl_cache_free( mbedtls_ssl_cache_context *cache )
|
||||
mbedtls_ssl_session_free( &prv->session );
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
mbedtls_free( prv->peer_cert.p );
|
||||
free( prv->peer_cert.p );
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
||||
mbedtls_free( prv );
|
||||
free( prv );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
|
19
deps/mbedtls/ssl_cli.c
vendored
19
deps/mbedtls/ssl_cli.c
vendored
@ -29,11 +29,8 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "mbedtls/debug.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
@ -390,7 +387,7 @@ static void ssl_write_ecjpake_kkpp_ext( mbedtls_ssl_context *ssl,
|
||||
return;
|
||||
}
|
||||
|
||||
ssl->handshake->ecjpake_cache = mbedtls_calloc( 1, kkpp_len );
|
||||
ssl->handshake->ecjpake_cache = calloc( 1, kkpp_len );
|
||||
if( ssl->handshake->ecjpake_cache == NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "allocation failed" ) );
|
||||
@ -1203,7 +1200,7 @@ static int ssl_parse_ecjpake_kkpp( mbedtls_ssl_context *ssl,
|
||||
}
|
||||
|
||||
/* If we got here, we no longer need our cached extension */
|
||||
mbedtls_free( ssl->handshake->ecjpake_cache );
|
||||
free( ssl->handshake->ecjpake_cache );
|
||||
ssl->handshake->ecjpake_cache = NULL;
|
||||
ssl->handshake->ecjpake_cache_len = 0;
|
||||
|
||||
@ -1339,9 +1336,9 @@ static int ssl_parse_hello_verify_request( mbedtls_ssl_context *ssl )
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO );
|
||||
}
|
||||
|
||||
mbedtls_free( ssl->handshake->verify_cookie );
|
||||
free( ssl->handshake->verify_cookie );
|
||||
|
||||
ssl->handshake->verify_cookie = mbedtls_calloc( 1, cookie_len );
|
||||
ssl->handshake->verify_cookie = calloc( 1, cookie_len );
|
||||
if( ssl->handshake->verify_cookie == NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc failed (%d bytes)", cookie_len ) );
|
||||
@ -1427,7 +1424,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
|
||||
else
|
||||
{
|
||||
/* We made it through the verification process */
|
||||
mbedtls_free( ssl->handshake->verify_cookie );
|
||||
free( ssl->handshake->verify_cookie );
|
||||
ssl->handshake->verify_cookie = NULL;
|
||||
ssl->handshake->verify_cookie_len = 0;
|
||||
}
|
||||
@ -3216,11 +3213,11 @@ static int ssl_parse_new_session_ticket( mbedtls_ssl_context *ssl )
|
||||
|
||||
mbedtls_zeroize( ssl->session_negotiate->ticket,
|
||||
ssl->session_negotiate->ticket_len );
|
||||
mbedtls_free( ssl->session_negotiate->ticket );
|
||||
free( ssl->session_negotiate->ticket );
|
||||
ssl->session_negotiate->ticket = NULL;
|
||||
ssl->session_negotiate->ticket_len = 0;
|
||||
|
||||
if( ( ticket = mbedtls_calloc( 1, ticket_len ) ) == NULL )
|
||||
if( ( ticket = calloc( 1, ticket_len ) ) == NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "ticket alloc failed" ) );
|
||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
|
3
deps/mbedtls/ssl_cookie.c
vendored
3
deps/mbedtls/ssl_cookie.c
vendored
@ -33,9 +33,6 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
#include "mbedtls/ssl_cookie.h"
|
||||
|
11
deps/mbedtls/ssl_srv.c
vendored
11
deps/mbedtls/ssl_srv.c
vendored
@ -29,11 +29,8 @@
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "mbedtls/debug.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
@ -61,9 +58,9 @@ int mbedtls_ssl_set_client_transport_id( mbedtls_ssl_context *ssl,
|
||||
if( ssl->conf->endpoint != MBEDTLS_SSL_IS_SERVER )
|
||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||
|
||||
mbedtls_free( ssl->cli_id );
|
||||
free( ssl->cli_id );
|
||||
|
||||
if( ( ssl->cli_id = mbedtls_calloc( 1, ilen ) ) == NULL )
|
||||
if( ( ssl->cli_id = calloc( 1, ilen ) ) == NULL )
|
||||
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
|
||||
|
||||
memcpy( ssl->cli_id, info, ilen );
|
||||
@ -267,7 +264,7 @@ static int ssl_parse_supported_elliptic_curves( mbedtls_ssl_context *ssl,
|
||||
if( our_size > MBEDTLS_ECP_DP_MAX )
|
||||
our_size = MBEDTLS_ECP_DP_MAX;
|
||||
|
||||
if( ( curves = mbedtls_calloc( our_size, sizeof( *curves ) ) ) == NULL )
|
||||
if( ( curves = calloc( our_size, sizeof( *curves ) ) ) == NULL )
|
||||
{
|
||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR );
|
||||
|
@ -71,7 +71,7 @@ static void ssl_debug(void *ctx, int level,
|
||||
{
|
||||
((void) level);
|
||||
|
||||
mbedtls_fprintf((FILE*)ctx, "%s:%04d: %s", file, line, str);
|
||||
fprintf((FILE*)ctx, "%s:%04d: %s", file, line, str);
|
||||
fflush((FILE*)ctx);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user