1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-28 00:21:48 +03:00

Add _init() and _free() for cipher modules

This commit is contained in:
Paul Bakker
2014-06-18 11:12:03 +02:00
parent 0464dd9357
commit c7ea99af4f
17 changed files with 375 additions and 61 deletions

View File

@ -46,6 +46,24 @@
#if !defined(POLARSSL_ARC4_ALT)
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
}
void arc4_init( arc4_context *ctx )
{
memset( ctx, 0, sizeof( arc4_context ) );
}
void arc4_free( arc4_context *ctx )
{
if( ctx == NULL )
return;
polarssl_zeroize( ctx, sizeof( arc4_context ) );
}
/*
* ARC4 key schedule
*/
@ -146,11 +164,13 @@ static const unsigned char arc4_test_ct[3][8] =
*/
int arc4_self_test( int verbose )
{
int i;
int i, ret = 0;
unsigned char ibuf[8];
unsigned char obuf[8];
arc4_context ctx;
arc4_init( &ctx );
for( i = 0; i < 3; i++ )
{
if( verbose != 0 )
@ -166,7 +186,8 @@ int arc4_self_test( int verbose )
if( verbose != 0 )
polarssl_printf( "failed\n" );
return( 1 );
ret = 1;
goto exit;
}
if( verbose != 0 )
@ -176,7 +197,10 @@ int arc4_self_test( int verbose )
if( verbose != 0 )
polarssl_printf( "\n" );
return( 0 );
exit:
arc4_free( &ctx );
return( ret );
}
#endif /* POLARSSL_SELF_TEST */