Call init functions in MD alloc wrappers

When someone defines MBEDTLS_MD5_ALT for example, the init function may need
to do more that just zeroizing the context
This commit is contained in:
Manuel Pégourié-Gonnard 2015-06-23 11:30:47 +02:00
parent 1cd10adc7c
commit ab5932192a

View File

@ -95,7 +95,12 @@ static void md2_finish_wrap( void *ctx, unsigned char *output )
static void *md2_ctx_alloc( void )
{
return mbedtls_calloc( 1, sizeof( mbedtls_md2_context ) );
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md2_context ) );
if( ctx != NULL )
mbedtls_md2_init( (mbedtls_md2_context *) ctx );
return( ctx );
}
static void md2_ctx_free( void *ctx )
@ -147,7 +152,12 @@ static void md4_finish_wrap( void *ctx, unsigned char *output )
static void *md4_ctx_alloc( void )
{
return mbedtls_calloc( 1, sizeof( mbedtls_md4_context ) );
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md4_context ) );
if( ctx != NULL )
mbedtls_md4_init( (mbedtls_md4_context *) ctx );
return( ctx );
}
static void md4_ctx_free( void *ctx )
@ -197,7 +207,12 @@ static void md5_finish_wrap( void *ctx, unsigned char *output )
static void *md5_ctx_alloc( void )
{
return mbedtls_calloc( 1, sizeof( mbedtls_md5_context ) );
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md5_context ) );
if( ctx != NULL )
mbedtls_md5_init( (mbedtls_md5_context *) ctx );
return( ctx );
}
static void md5_ctx_free( void *ctx )
@ -247,13 +262,10 @@ static void ripemd160_finish_wrap( void *ctx, unsigned char *output )
static void *ripemd160_ctx_alloc( void )
{
mbedtls_ripemd160_context *ctx;
ctx = mbedtls_calloc( 1, sizeof( mbedtls_ripemd160_context ) );
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ripemd160_context ) );
if( ctx == NULL )
return( NULL );
mbedtls_ripemd160_init( ctx );
if( ctx != NULL )
mbedtls_ripemd160_init( (mbedtls_ripemd160_context *) ctx );
return( ctx );
}
@ -305,13 +317,10 @@ static void sha1_finish_wrap( void *ctx, unsigned char *output )
static void *sha1_ctx_alloc( void )
{
mbedtls_sha1_context *ctx;
ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha1_context ) );
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha1_context ) );
if( ctx == NULL )
return( NULL );
mbedtls_sha1_init( ctx );
if( ctx != NULL )
mbedtls_sha1_init( (mbedtls_sha1_context *) ctx );
return( ctx );
}
@ -372,7 +381,12 @@ static void sha224_wrap( const unsigned char *input, size_t ilen,
static void *sha224_ctx_alloc( void )
{
return mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) );
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) );
if( ctx != NULL )
mbedtls_sha256_init( (mbedtls_sha256_context *) ctx );
return( ctx );
}
static void sha224_ctx_free( void *ctx )
@ -424,13 +438,10 @@ static void sha256_wrap( const unsigned char *input, size_t ilen,
static void *sha256_ctx_alloc( void )
{
mbedtls_sha256_context *ctx;
ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) );
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) );
if( ctx == NULL )
return( NULL );
mbedtls_sha256_init( ctx );
if( ctx != NULL )
mbedtls_sha256_init( (mbedtls_sha256_context *) ctx );
return( ctx );
}
@ -488,7 +499,12 @@ static void sha384_wrap( const unsigned char *input, size_t ilen,
static void *sha384_ctx_alloc( void )
{
return mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) );
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) );
if( ctx != NULL )
mbedtls_sha512_init( (mbedtls_sha512_context *) ctx );
return( ctx );
}
static void sha384_ctx_free( void *ctx )
@ -540,13 +556,10 @@ static void sha512_wrap( const unsigned char *input, size_t ilen,
static void *sha512_ctx_alloc( void )
{
mbedtls_sha512_context *ctx;
ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) );
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) );
if( ctx == NULL )
return( NULL );
mbedtls_sha512_init( ctx );
if( ctx != NULL )
mbedtls_sha512_init( (mbedtls_sha512_context *) ctx );
return( ctx );
}