mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 11:15:43 +01:00
Adapt programs / test suites
This commit is contained in:
parent
8f870b047c
commit
a317a98221
@ -53,6 +53,13 @@ havege_state;
|
||||
*/
|
||||
void havege_init( havege_state *hs );
|
||||
|
||||
/**
|
||||
* \brief Clear HAVEGE state
|
||||
*
|
||||
* \param hs HAVEGE state to be cleared
|
||||
*/
|
||||
void havege_free( havege_state *hs );
|
||||
|
||||
/**
|
||||
* \brief HAVEGE rand function
|
||||
*
|
||||
|
@ -83,6 +83,9 @@ void entropy_init( entropy_context *ctx )
|
||||
|
||||
void entropy_free( entropy_context *ctx )
|
||||
{
|
||||
#if defined(POLARSSL_HAVEGE_C)
|
||||
havege_free( &ctx->havege_data );
|
||||
#endif
|
||||
polarssl_zeroize( ctx, sizeof( entropy_context ) );
|
||||
#if defined(POLARSSL_THREADING_C)
|
||||
polarssl_mutex_free( &ctx->mutex );
|
||||
|
@ -43,6 +43,11 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* On average, one iteration accesses two 8-word blocks in the havege WALK
|
||||
* table, and generates 16 words in the RES array.
|
||||
@ -200,6 +205,14 @@ void havege_init( havege_state *hs )
|
||||
havege_fill( hs );
|
||||
}
|
||||
|
||||
void havege_free( havege_state *hs )
|
||||
{
|
||||
if( hs == NULL )
|
||||
return;
|
||||
|
||||
polarssl_zeroize( hs, sizeof( havege_state ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* HAVEGE rand function
|
||||
*/
|
||||
|
@ -82,8 +82,7 @@ int main( int argc, char *argv[] )
|
||||
((void) argv);
|
||||
|
||||
memset( &rsa, 0, sizeof( rsa ) );
|
||||
memset( &dhm, 0, sizeof( dhm ) );
|
||||
|
||||
dhm_init( &dhm );
|
||||
aes_init( &aes );
|
||||
|
||||
/*
|
||||
@ -284,6 +283,7 @@ exit:
|
||||
aes_free( &aes );
|
||||
rsa_free( &rsa );
|
||||
dhm_free( &dhm );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -154,6 +154,7 @@ int main( int argc, char *argv[] )
|
||||
exit:
|
||||
|
||||
mpi_free( &G ); mpi_free( &P ); mpi_free( &Q );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -83,7 +83,7 @@ int main( int argc, char *argv[] )
|
||||
((void) argv);
|
||||
|
||||
memset( &rsa, 0, sizeof( rsa ) );
|
||||
memset( &dhm, 0, sizeof( dhm ) );
|
||||
dhm_init( &dhm );
|
||||
aes_init( &aes );
|
||||
|
||||
/*
|
||||
@ -284,6 +284,7 @@ exit:
|
||||
aes_free( &aes );
|
||||
rsa_free( &rsa );
|
||||
dhm_free( &dhm );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -229,6 +229,7 @@ exit:
|
||||
|
||||
ecdsa_free( &ctx_verify );
|
||||
ecdsa_free( &ctx_sign );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
return( ret );
|
||||
|
@ -388,6 +388,7 @@ exit:
|
||||
}
|
||||
|
||||
pk_free( &key );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -140,6 +140,7 @@ int main( int argc, char *argv[] )
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(POLARSSL_ERROR_C)
|
||||
|
@ -140,6 +140,7 @@ int main( int argc, char *argv[] )
|
||||
printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" );
|
||||
|
||||
exit:
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(POLARSSL_ERROR_C)
|
||||
|
@ -151,6 +151,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
exit:
|
||||
pk_free( &pk );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(POLARSSL_ERROR_C)
|
||||
|
@ -164,6 +164,7 @@ int main( int argc, char *argv[] )
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -152,6 +152,7 @@ int main( int argc, char *argv[] )
|
||||
printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" );
|
||||
|
||||
exit:
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -154,6 +154,7 @@ exit:
|
||||
fclose( fpriv );
|
||||
|
||||
rsa_free( &rsa );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -161,6 +161,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
exit:
|
||||
pk_free( &pk );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -115,6 +115,7 @@ cleanup:
|
||||
printf("\n");
|
||||
|
||||
fclose( f );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
return( ret );
|
||||
|
@ -48,7 +48,7 @@ int main( int argc, char *argv[] )
|
||||
{
|
||||
FILE *f;
|
||||
time_t t;
|
||||
int i, k;
|
||||
int i, k, ret = 0;
|
||||
havege_state hs;
|
||||
unsigned char buf[1024];
|
||||
|
||||
@ -73,8 +73,9 @@ int main( int argc, char *argv[] )
|
||||
if( havege_random( &hs, buf, sizeof( buf ) ) != 0 )
|
||||
{
|
||||
printf( "Failed to get random from source.\n" );
|
||||
fclose( f );
|
||||
return( 1 );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
fwrite( buf, sizeof( buf ), 1, f );
|
||||
@ -89,7 +90,9 @@ int main( int argc, char *argv[] )
|
||||
|
||||
printf(" \n ");
|
||||
|
||||
exit:
|
||||
havege_free( &hs );
|
||||
fclose( f );
|
||||
return( 0 );
|
||||
return( ret );
|
||||
}
|
||||
#endif /* POLARSSL_HAVEGE_C */
|
||||
|
@ -290,6 +290,7 @@ exit:
|
||||
|
||||
x509_crt_free( &cacert );
|
||||
ssl_free( &ssl );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
memset( &ssl, 0, sizeof( ssl ) );
|
||||
|
@ -1209,6 +1209,7 @@ exit:
|
||||
#endif
|
||||
ssl_session_free( &saved_session );
|
||||
ssl_free( &ssl );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
memset( &ssl, 0, sizeof( ssl ) );
|
||||
|
@ -376,6 +376,7 @@ exit:
|
||||
x509_crt_free( &srvcert );
|
||||
pk_free( &pkey );
|
||||
ssl_free( &ssl );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -816,6 +816,7 @@ exit:
|
||||
x509_crt_free( &cacert );
|
||||
pk_free( &pkey );
|
||||
ssl_free( &ssl );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -492,6 +492,7 @@ exit:
|
||||
#if defined(POLARSSL_SSL_CACHE_C)
|
||||
ssl_cache_free( &cache );
|
||||
#endif
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
polarssl_mutex_free( &debug_mutex );
|
||||
|
@ -373,6 +373,7 @@ exit:
|
||||
#if defined(POLARSSL_SSL_CACHE_C)
|
||||
ssl_cache_free( &cache );
|
||||
#endif
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -626,7 +626,7 @@ int main( int argc, char *argv[] )
|
||||
pk_init( &pkey2 );
|
||||
#endif
|
||||
#if defined(POLARSSL_DHM_C) && defined(POLARSSL_FS_IO)
|
||||
memset( &dhm, 0, sizeof( dhm_context ) );
|
||||
dhm_init( &dhm );
|
||||
#endif
|
||||
#if defined(POLARSSL_SSL_CACHE_C)
|
||||
ssl_cache_init( &cache );
|
||||
@ -1655,6 +1655,9 @@ exit:
|
||||
if( client_fd != -1 )
|
||||
net_close( client_fd );
|
||||
|
||||
#if defined(POLARSSL_DHM_C) && defined(POLARSSL_FS_IO)
|
||||
dhm_free( &dhm );
|
||||
#endif
|
||||
#if defined(POLARSSL_X509_CRT_PARSE_C)
|
||||
x509_crt_free( &cacert );
|
||||
x509_crt_free( &srvcert );
|
||||
@ -1673,6 +1676,7 @@ exit:
|
||||
#endif
|
||||
|
||||
ssl_free( &ssl );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(POLARSSL_SSL_CACHE_C)
|
||||
|
@ -414,6 +414,7 @@ int main( int argc, char *argv[] )
|
||||
havege_state hs;
|
||||
havege_init( &hs );
|
||||
TIME_AND_TSC( "HAVEGE", havege_random( &hs, buf, BUFSIZE ) );
|
||||
havege_free( &hs );
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -434,6 +435,7 @@ int main( int argc, char *argv[] )
|
||||
TIME_AND_TSC( "CTR_DRBG (PR)",
|
||||
if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
|
||||
exit(1) );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -531,7 +533,7 @@ int main( int argc, char *argv[] )
|
||||
size_t olen;
|
||||
for( i = 0; i < DHM_SIZES; i++ )
|
||||
{
|
||||
memset( &dhm, 0, sizeof( dhm_context ) );
|
||||
dhm_init( &dhm );
|
||||
|
||||
if( mpi_read_string( &dhm.P, 16, dhm_P[i] ) != 0 ||
|
||||
mpi_read_string( &dhm.G, 16, dhm_G[i] ) != 0 )
|
||||
|
@ -258,6 +258,7 @@ int main( int argc, char *argv[] )
|
||||
printf( "String value (PolarSSL Private Encrypt, OpenSSL Public Decrypt): '%s'\n", o_priv_decrypted );
|
||||
|
||||
exit:
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -417,6 +417,7 @@ exit:
|
||||
x509_crt_free( &srvcert );
|
||||
pk_free( &pkey );
|
||||
ssl_free( &ssl );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
if( client_fd != -1 )
|
||||
|
@ -492,6 +492,7 @@ exit:
|
||||
x509_crl_free( &cacrl );
|
||||
#endif
|
||||
pk_free( &pkey );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -329,6 +329,7 @@ exit:
|
||||
|
||||
x509write_csr_free( &req );
|
||||
pk_free( &key );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -652,6 +652,7 @@ exit:
|
||||
pk_free( &loaded_subject_key );
|
||||
pk_free( &loaded_issuer_key );
|
||||
mpi_free( &serial );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -45,6 +45,8 @@ void ctr_drbg_validate_pr( char *add_init_string, char *entropy_string,
|
||||
TEST_ASSERT( ctr_drbg_random_with_add( &ctx, buf, 16, add2, add2_len ) == 0 );
|
||||
hexify( output_str, buf, 16 );
|
||||
TEST_ASSERT( strcmp( (char *) output_str, result_str ) == 0 );
|
||||
|
||||
ctr_drbg_free( &ctx );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -79,6 +81,8 @@ void ctr_drbg_validate_nopr( char *add_init_string, char *entropy_string,
|
||||
TEST_ASSERT( ctr_drbg_random_with_add( &ctx, buf, 16, add2, add2_len ) == 0 );
|
||||
hexify( output_str, buf, 16 );
|
||||
TEST_ASSERT( strcmp( (char *) output_str, result_str ) == 0 );
|
||||
|
||||
ctr_drbg_free( &ctx );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -150,6 +154,8 @@ void ctr_drbg_entropy_usage( )
|
||||
last_idx = test_offset_idx;
|
||||
TEST_ASSERT( ctr_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
|
||||
TEST_ASSERT( test_offset_idx - last_idx == 13 );
|
||||
|
||||
ctr_drbg_free( &ctx );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -161,6 +167,8 @@ void ctr_drbg_seed_file( char *path, int ret )
|
||||
TEST_ASSERT( ctr_drbg_init( &ctx, rnd_std_rand, NULL, NULL, 0 ) == 0 );
|
||||
TEST_ASSERT( ctr_drbg_write_seed_file( &ctx, path ) == ret );
|
||||
TEST_ASSERT( ctr_drbg_update_seed_file( &ctx, path ) == ret );
|
||||
|
||||
ctr_drbg_free( &ctx );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
@ -25,8 +25,8 @@ void dhm_do_dhm( int radix_P, char *input_P,
|
||||
int x_size, i;
|
||||
rnd_pseudo_info rnd_info;
|
||||
|
||||
memset( &ctx_srv, 0x00, sizeof( dhm_context ) );
|
||||
memset( &ctx_cli, 0x00, sizeof( dhm_context ) );
|
||||
dhm_init( &ctx_srv );
|
||||
dhm_init( &ctx_cli );
|
||||
memset( ske, 0x00, 1000 );
|
||||
memset( pub_cli, 0x00, 1000 );
|
||||
memset( sec_srv, 0x00, 1000 );
|
||||
@ -103,7 +103,7 @@ void dhm_file( char *filename, char *p, char *g, int len )
|
||||
dhm_context ctx;
|
||||
mpi P, G;
|
||||
|
||||
memset( &ctx, 0, sizeof ctx );
|
||||
dhm_init( &ctx );
|
||||
mpi_init( &P ); mpi_init( &G );
|
||||
|
||||
TEST_ASSERT( mpi_read_string( &P, 16, p ) == 0 );
|
||||
|
@ -597,6 +597,7 @@ void rsa_gen_key( int nrbits, int exponent, int result)
|
||||
}
|
||||
|
||||
rsa_free( &ctx );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
Loading…
Reference in New Issue
Block a user