Replace malloc with calloc
- platform layer currently broken (not adapted yet)
- memmory_buffer_alloc too
diff --git a/library/cipher_wrap.c b/library/cipher_wrap.c
index 490f981..59d77df 100644
--- a/library/cipher_wrap.c
+++ b/library/cipher_wrap.c
@@ -70,7 +70,7 @@
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
-#define mbedtls_malloc malloc
+#define mbedtls_calloc calloc
#define mbedtls_free free
#endif
@@ -78,7 +78,7 @@
/* shared by all GCM ciphers */
static void *gcm_ctx_alloc( void )
{
- return mbedtls_malloc( sizeof( mbedtls_gcm_context ) );
+ return mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
}
static void gcm_ctx_free( void *ctx )
@@ -92,7 +92,7 @@
/* shared by all CCM ciphers */
static void *ccm_ctx_alloc( void )
{
- return mbedtls_malloc( sizeof( mbedtls_ccm_context ) );
+ return mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
}
static void ccm_ctx_free( void *ctx )
@@ -153,7 +153,7 @@
static void * aes_ctx_alloc( void )
{
- mbedtls_aes_context *aes = mbedtls_malloc( sizeof( mbedtls_aes_context ) );
+ mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
if( aes == NULL )
return( NULL );
@@ -510,7 +510,7 @@
static void * camellia_ctx_alloc( void )
{
mbedtls_camellia_context *ctx;
- ctx = mbedtls_malloc( sizeof( mbedtls_camellia_context ) );
+ ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
if( ctx == NULL )
return( NULL );
@@ -897,7 +897,7 @@
static void * des_ctx_alloc( void )
{
- mbedtls_des_context *des = mbedtls_malloc( sizeof( mbedtls_des_context ) );
+ mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
if( des == NULL )
return( NULL );
@@ -916,7 +916,7 @@
static void * des3_ctx_alloc( void )
{
mbedtls_des3_context *des3;
- des3 = mbedtls_malloc( sizeof( mbedtls_des3_context ) );
+ des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
if( des3 == NULL )
return( NULL );
@@ -1115,7 +1115,7 @@
static void * blowfish_ctx_alloc( void )
{
mbedtls_blowfish_context *ctx;
- ctx = mbedtls_malloc( sizeof( mbedtls_blowfish_context ) );
+ ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
if( ctx == NULL )
return( NULL );
@@ -1225,7 +1225,7 @@
static void * arc4_ctx_alloc( void )
{
mbedtls_arc4_context *ctx;
- ctx = mbedtls_malloc( sizeof( mbedtls_arc4_context ) );
+ ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
if( ctx == NULL )
return( NULL );