diff --git a/components/mbedtls/library/aes.c b/components/mbedtls/library/aes.c index 6903585194..a186dee981 100644 --- a/components/mbedtls/library/aes.c +++ b/components/mbedtls/library/aes.c @@ -1237,8 +1237,9 @@ int mbedtls_aes_self_test( int verbose ) unsigned char stream_block[16]; #endif mbedtls_aes_context ctx; - - memset( key, 0, 32 ); + + memset( key, 0, 32 ); + mbedtls_aes_init( &ctx ); /* * ECB mode @@ -1254,8 +1255,6 @@ int mbedtls_aes_self_test( int verbose ) memset( buf, 0, 16 ); - mbedtls_aes_init( &ctx ); - if( v == MBEDTLS_AES_DECRYPT ) { mbedtls_aes_setkey_dec( &ctx, key, 128 + u * 64 ); @@ -1268,7 +1267,6 @@ int mbedtls_aes_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - mbedtls_aes_free( &ctx ); ret = 1; goto exit; } @@ -1285,8 +1283,6 @@ int mbedtls_aes_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - mbedtls_aes_free( &ctx ); - ret = 1; goto exit; } @@ -1294,8 +1290,6 @@ int mbedtls_aes_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "passed\n" ); - - mbedtls_aes_free( &ctx ); } if( verbose != 0 ) @@ -1318,8 +1312,6 @@ int mbedtls_aes_self_test( int verbose ) memset( prv, 0, 16 ); memset( buf, 0, 16 ); - mbedtls_aes_init( &ctx ); - if( v == MBEDTLS_AES_DECRYPT ) { mbedtls_aes_setkey_dec( &ctx, key, 128 + u * 64 ); @@ -1332,8 +1324,6 @@ int mbedtls_aes_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - mbedtls_aes_free( &ctx ); - ret = 1; goto exit; } @@ -1358,8 +1348,6 @@ int mbedtls_aes_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - mbedtls_aes_free( &ctx ); - ret = 1; goto exit; } @@ -1367,8 +1355,6 @@ int mbedtls_aes_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "passed\n" ); - - mbedtls_aes_free( &ctx ); } if( verbose != 0 ) @@ -1391,8 +1377,6 @@ int mbedtls_aes_self_test( int verbose ) memcpy( iv, aes_test_cfb128_iv, 16 ); memcpy( key, aes_test_cfb128_key[u], 16 + u * 8 ); - mbedtls_aes_init( &ctx ); - offset = 0; mbedtls_aes_setkey_enc( &ctx, key, 128 + u * 64 ); @@ -1449,8 +1433,6 @@ int mbedtls_aes_self_test( int verbose ) memcpy( nonce_counter, aes_test_ctr_nonce_counter[u], 16 ); memcpy( key, aes_test_ctr_key[u], 16 ); - mbedtls_aes_init( &ctx ); - offset = 0; mbedtls_aes_setkey_enc( &ctx, key, 128 ); diff --git a/components/mbedtls/library/sha1.c b/components/mbedtls/library/sha1.c index 46ed34f943..2ccf2a2f52 100644 --- a/components/mbedtls/library/sha1.c +++ b/components/mbedtls/library/sha1.c @@ -396,13 +396,13 @@ int mbedtls_sha1_self_test( int verbose ) unsigned char sha1sum[20]; mbedtls_sha1_context ctx; + mbedtls_sha1_init( &ctx ); + /* * SHA-1 */ for( i = 0; i < 3; i++ ) { - mbedtls_sha1_init( &ctx ); - if( verbose != 0 ) mbedtls_printf( " SHA-1 test #%d: ", i + 1 ); @@ -426,22 +426,19 @@ int mbedtls_sha1_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - mbedtls_sha1_free( &ctx ); - ret = 1; goto exit; } if( verbose != 0 ) mbedtls_printf( "passed\n" ); - - mbedtls_sha1_free( &ctx ); } if( verbose != 0 ) mbedtls_printf( "\n" ); exit: + mbedtls_sha1_free( &ctx ); return( ret ); } diff --git a/components/mbedtls/library/sha256.c b/components/mbedtls/library/sha256.c index cc6bd335df..4e82c0b793 100644 --- a/components/mbedtls/library/sha256.c +++ b/components/mbedtls/library/sha256.c @@ -393,13 +393,13 @@ int mbedtls_sha256_self_test( int verbose ) unsigned char sha256sum[32]; mbedtls_sha256_context ctx; + mbedtls_sha256_init( &ctx ); + for( i = 0; i < 6; i++ ) { j = i % 3; k = i < 3; - mbedtls_sha256_init( &ctx ); - if( verbose != 0 ) mbedtls_printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 ); @@ -423,22 +423,19 @@ int mbedtls_sha256_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - mbedtls_sha256_free( &ctx ); - ret = 1; goto exit; } if( verbose != 0 ) mbedtls_printf( "passed\n" ); - - mbedtls_sha256_free( &ctx ); } if( verbose != 0 ) mbedtls_printf( "\n" ); exit: + mbedtls_sha256_free( &ctx ); return( ret ); } diff --git a/components/mbedtls/library/sha512.c b/components/mbedtls/library/sha512.c index 245ede0eb2..0f9e1e5352 100644 --- a/components/mbedtls/library/sha512.c +++ b/components/mbedtls/library/sha512.c @@ -449,13 +449,13 @@ int mbedtls_sha512_self_test( int verbose ) unsigned char sha512sum[64]; mbedtls_sha512_context ctx; + mbedtls_sha512_init( &ctx ); + for( i = 0; i < 6; i++ ) { j = i % 3; k = i < 3; - mbedtls_sha512_init( &ctx ); - if( verbose != 0 ) mbedtls_printf( " SHA-%d test #%d: ", 512 - k * 128, j + 1 ); @@ -479,23 +479,19 @@ int mbedtls_sha512_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - mbedtls_sha512_free( &ctx ); - ret = 1; goto exit; } if( verbose != 0 ) mbedtls_printf( "passed\n" ); - - mbedtls_sha512_free( &ctx ); } if( verbose != 0 ) mbedtls_printf( "\n" ); exit: - + mbedtls_sha512_free( &ctx ); return( ret ); }