1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

Memory-allocation abstraction layer and buffer-based allocator added

This commit is contained in:
Paul Bakker
2013-07-03 13:37:05 +02:00
parent f863485fea
commit 6e339b52e8
18 changed files with 818 additions and 103 deletions

View File

@ -37,6 +37,13 @@
#include "polarssl/bignum.h"
#include "polarssl/bn_mul.h"
#if defined(POLARSSL_MEMORY_C)
#include "polarssl/memory.h"
#else
#define polarssl_malloc malloc
#define polarssl_free free
#endif
#include <stdlib.h>
#define ciL (sizeof(t_uint)) /* chars in limb */
@ -73,7 +80,7 @@ void mpi_free( mpi *X )
if( X->p != NULL )
{
memset( X->p, 0, X->n * ciL );
free( X->p );
polarssl_free( X->p );
}
X->s = 1;
@ -93,7 +100,7 @@ int mpi_grow( mpi *X, size_t nblimbs )
if( X->n < nblimbs )
{
if( ( p = (t_uint *) malloc( nblimbs * ciL ) ) == NULL )
if( ( p = (t_uint *) polarssl_malloc( nblimbs * ciL ) ) == NULL )
return( POLARSSL_ERR_MPI_MALLOC_FAILED );
memset( p, 0, nblimbs * ciL );
@ -102,7 +109,7 @@ int mpi_grow( mpi *X, size_t nblimbs )
{
memcpy( p, X->p, X->n * ciL );
memset( X->p, 0, X->n * ciL );
free( X->p );
polarssl_free( X->p );
}
X->n = nblimbs;