mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-25 17:25:37 +01:00
Adapt programs / test suites
This commit is contained in:
parent
84bbeb58df
commit
d2a2d61a68
@ -95,8 +95,8 @@ int main( int argc, char *argv[] )
|
||||
off_t filesize, offset;
|
||||
#endif
|
||||
|
||||
memset( &cipher_ctx, 0, sizeof( cipher_context_t ));
|
||||
memset( &md_ctx, 0, sizeof( md_context_t ));
|
||||
cipher_init( &cipher_ctx );
|
||||
md_init( &md_ctx );
|
||||
|
||||
/*
|
||||
* Parse the command-line arguments.
|
||||
@ -533,8 +533,8 @@ exit:
|
||||
memset( buffer, 0, sizeof( buffer ) );
|
||||
memset( digest, 0, sizeof( digest ) );
|
||||
|
||||
cipher_free_ctx( &cipher_ctx );
|
||||
md_free_ctx( &md_ctx );
|
||||
cipher_free( &cipher_ctx );
|
||||
md_free( &md_ctx );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ int main( int argc, char *argv[] )
|
||||
const md_info_t *md_info;
|
||||
md_context_t md_ctx;
|
||||
|
||||
memset( &md_ctx, 0, sizeof( md_context_t ));
|
||||
md_init( &md_ctx );
|
||||
|
||||
if( argc == 1 )
|
||||
{
|
||||
@ -217,7 +217,7 @@ int main( int argc, char *argv[] )
|
||||
ret |= generic_print( md_info, argv[i] );
|
||||
|
||||
exit:
|
||||
md_free_ctx( &md_ctx );
|
||||
md_free( &md_ctx );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ void cipher_null_args( )
|
||||
unsigned char buf[1] = { 0 };
|
||||
size_t olen;
|
||||
|
||||
memset( &ctx, 0, sizeof( cipher_context_t ) );
|
||||
cipher_init( &ctx );
|
||||
|
||||
TEST_ASSERT( cipher_get_block_size( NULL ) == 0 );
|
||||
TEST_ASSERT( cipher_get_block_size( &ctx ) == 0 );
|
||||
@ -111,8 +111,8 @@ void enc_dec_buf( int cipher_id, char *cipher_string, int key_len,
|
||||
/*
|
||||
* Prepare contexts
|
||||
*/
|
||||
memset( &ctx_dec, 0, sizeof( ctx_dec ) );
|
||||
memset( &ctx_enc, 0, sizeof( ctx_enc ) );
|
||||
cipher_init( &ctx_dec );
|
||||
cipher_init( &ctx_enc );
|
||||
|
||||
memset( key, 0x2a, sizeof( key ) );
|
||||
|
||||
@ -207,8 +207,8 @@ void enc_dec_buf( int cipher_id, char *cipher_string, int key_len,
|
||||
/*
|
||||
* Done
|
||||
*/
|
||||
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
|
||||
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_enc ) );
|
||||
cipher_free( &ctx_dec );
|
||||
cipher_free( &ctx_enc );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -231,7 +231,7 @@ void enc_fail( int cipher_id, int pad_mode, int key_len,
|
||||
memset( key, 0, 32 );
|
||||
memset( iv , 0, 16 );
|
||||
|
||||
memset( &ctx, 0, sizeof( ctx ) );
|
||||
cipher_init( &ctx );
|
||||
|
||||
memset( inbuf, 5, 64 );
|
||||
memset( encbuf, 0, 64 );
|
||||
@ -259,7 +259,7 @@ void enc_fail( int cipher_id, int pad_mode, int key_len,
|
||||
TEST_ASSERT( ret == cipher_finish( &ctx, encbuf + outlen, &outlen ) );
|
||||
|
||||
/* done */
|
||||
TEST_ASSERT( 0 == cipher_free_ctx( &ctx ) );
|
||||
cipher_free( &ctx );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -280,7 +280,7 @@ void dec_empty_buf()
|
||||
memset( key, 0, 32 );
|
||||
memset( iv , 0, 16 );
|
||||
|
||||
memset( &ctx_dec, 0, sizeof( ctx_dec ) );
|
||||
cipher_init( &ctx_dec );
|
||||
|
||||
memset( encbuf, 0, 64 );
|
||||
memset( decbuf, 0, 64 );
|
||||
@ -308,7 +308,7 @@ void dec_empty_buf()
|
||||
&ctx_dec, decbuf + outlen, &outlen ) );
|
||||
TEST_ASSERT( 0 == outlen );
|
||||
|
||||
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
|
||||
cipher_free( &ctx_dec );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -336,8 +336,8 @@ void enc_dec_buf_multipart( int cipher_id, int key_len, int first_length_val,
|
||||
memset( key, 0, 32 );
|
||||
memset( iv , 0, 16 );
|
||||
|
||||
memset( &ctx_dec, 0, sizeof( ctx_dec ) );
|
||||
memset( &ctx_enc, 0, sizeof( ctx_enc ) );
|
||||
cipher_init( &ctx_dec );
|
||||
cipher_init( &ctx_enc );
|
||||
|
||||
memset( inbuf, 5, 64 );
|
||||
memset( encbuf, 0, 64 );
|
||||
@ -397,8 +397,8 @@ void enc_dec_buf_multipart( int cipher_id, int key_len, int first_length_val,
|
||||
|
||||
TEST_ASSERT( 0 == memcmp(inbuf, decbuf, length) );
|
||||
|
||||
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
|
||||
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_enc ) );
|
||||
cipher_free( &ctx_dec );
|
||||
cipher_free( &ctx_enc );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -423,6 +423,8 @@ void decrypt_test_vec( int cipher_id, int pad_mode,
|
||||
unsigned char output[200];
|
||||
size_t outlen, total_len;
|
||||
|
||||
cipher_init( &ctx );
|
||||
|
||||
memset( key, 0x00, sizeof( key ) );
|
||||
memset( iv, 0x00, sizeof( iv ) );
|
||||
memset( cipher, 0x00, sizeof( cipher ) );
|
||||
@ -477,7 +479,7 @@ void decrypt_test_vec( int cipher_id, int pad_mode,
|
||||
TEST_ASSERT( 0 == memcmp( output, clear, clear_len ) );
|
||||
}
|
||||
|
||||
cipher_free_ctx( &ctx );
|
||||
cipher_free( &ctx );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -499,6 +501,8 @@ void auth_crypt_tv( int cipher_id, char *hex_key, char *hex_iv,
|
||||
unsigned char output[200];
|
||||
size_t outlen;
|
||||
|
||||
cipher_init( &ctx );
|
||||
|
||||
memset( key, 0x00, sizeof( key ) );
|
||||
memset( iv, 0x00, sizeof( iv ) );
|
||||
memset( cipher, 0x00, sizeof( cipher ) );
|
||||
@ -563,7 +567,7 @@ void auth_crypt_tv( int cipher_id, char *hex_key, char *hex_iv,
|
||||
|
||||
|
||||
cleanup:
|
||||
cipher_free_ctx( &ctx );
|
||||
cipher_free( &ctx );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -580,6 +584,8 @@ void test_vec_ecb( int cipher_id, int operation, char *hex_key,
|
||||
unsigned char output[32];
|
||||
size_t outlen;
|
||||
|
||||
cipher_init( &ctx );
|
||||
|
||||
memset( key, 0x00, sizeof( key ) );
|
||||
memset( input, 0x00, sizeof( input ) );
|
||||
memset( result, 0x00, sizeof( result ) );
|
||||
@ -610,7 +616,7 @@ void test_vec_ecb( int cipher_id, int operation, char *hex_key,
|
||||
TEST_ASSERT( 0 == memcmp( output, result,
|
||||
cipher_get_block_size( &ctx ) ) );
|
||||
|
||||
cipher_free_ctx( &ctx );
|
||||
cipher_free( &ctx );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -620,13 +626,15 @@ void set_padding( int cipher_id, int pad_mode, int ret )
|
||||
const cipher_info_t *cipher_info;
|
||||
cipher_context_t ctx;
|
||||
|
||||
cipher_init( &ctx );
|
||||
|
||||
cipher_info = cipher_info_from_type( cipher_id );
|
||||
TEST_ASSERT( NULL != cipher_info );
|
||||
TEST_ASSERT( 0 == cipher_init_ctx( &ctx, cipher_info ) );
|
||||
|
||||
TEST_ASSERT( ret == cipher_set_padding_mode( &ctx, pad_mode ) );
|
||||
|
||||
TEST_ASSERT( 0 == cipher_free_ctx( &ctx ) );
|
||||
cipher_free( &ctx );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
@ -639,7 +647,7 @@ void check_padding( int pad_mode, char *input_str, int ret, int dlen_check )
|
||||
size_t ilen, dlen;
|
||||
|
||||
/* build a fake context just for getting access to get_padding */
|
||||
memset( &ctx, 0, sizeof( ctx ) );
|
||||
cipher_init( &ctx );
|
||||
cipher_info.mode = POLARSSL_MODE_CBC;
|
||||
ctx.cipher_info = &cipher_info;
|
||||
|
||||
|
@ -15,7 +15,7 @@ void md_process( )
|
||||
md_context_t ctx;
|
||||
unsigned char buf[150];
|
||||
|
||||
memset( &ctx, 0, sizeof ctx );
|
||||
md_init( &ctx );
|
||||
|
||||
/*
|
||||
* Very minimal testing of md_process, just make sure the various
|
||||
@ -31,7 +31,7 @@ void md_process( )
|
||||
TEST_ASSERT( info != NULL );
|
||||
TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
|
||||
TEST_ASSERT( md_process( &ctx, buf ) == 0 );
|
||||
TEST_ASSERT( md_free_ctx( &ctx ) == 0 );
|
||||
md_free( &ctx );
|
||||
}
|
||||
}
|
||||
/* END_CASE */
|
||||
@ -43,7 +43,7 @@ void md_null_args( )
|
||||
const md_info_t *info = md_info_from_type( *( md_list() ) );
|
||||
unsigned char buf[1] = { 0 };
|
||||
|
||||
memset( &ctx, 0, sizeof( md_context_t ) );
|
||||
md_init( &ctx );
|
||||
|
||||
TEST_ASSERT( md_get_size( NULL ) == 0 );
|
||||
|
||||
@ -179,7 +179,9 @@ void md_text_multi( char *text_md_name, char *text_src_string,
|
||||
unsigned char output[100];
|
||||
|
||||
const md_info_t *md_info = NULL;
|
||||
md_context_t ctx = MD_CONTEXT_T_INIT;
|
||||
md_context_t ctx;
|
||||
|
||||
md_init( &ctx );
|
||||
|
||||
memset(md_name, 0x00, 100);
|
||||
memset(src_str, 0x00, 1000);
|
||||
@ -196,7 +198,7 @@ void md_text_multi( char *text_md_name, char *text_src_string,
|
||||
TEST_ASSERT ( ctx.md_ctx != NULL );
|
||||
TEST_ASSERT ( 0 == md_update( &ctx, src_str, strlen( (char *) src_str ) ) );
|
||||
TEST_ASSERT ( 0 == md_finish( &ctx, output ) );
|
||||
TEST_ASSERT ( 0 == md_free_ctx( &ctx ) );
|
||||
md_free( &ctx );
|
||||
|
||||
hexify( hash_str, output, md_get_size(md_info) );
|
||||
|
||||
@ -214,7 +216,9 @@ void md_hex_multi( char *text_md_name, char *hex_src_string,
|
||||
unsigned char output[100];
|
||||
int src_len;
|
||||
const md_info_t *md_info = NULL;
|
||||
md_context_t ctx = MD_CONTEXT_T_INIT;
|
||||
md_context_t ctx;
|
||||
|
||||
md_init( &ctx );
|
||||
|
||||
memset(md_name, 0x00, 100);
|
||||
memset(src_str, 0x00, 10000);
|
||||
@ -232,7 +236,7 @@ void md_hex_multi( char *text_md_name, char *hex_src_string,
|
||||
TEST_ASSERT ( ctx.md_ctx != NULL );
|
||||
TEST_ASSERT ( 0 == md_update( &ctx, src_str, src_len ) );
|
||||
TEST_ASSERT ( 0 == md_finish( &ctx, output ) );
|
||||
TEST_ASSERT ( 0 == md_free_ctx( &ctx ) );
|
||||
md_free( &ctx );
|
||||
|
||||
hexify( hash_str, output, md_get_size(md_info) );
|
||||
|
||||
@ -283,7 +287,9 @@ void md_hmac_multi( char *text_md_name, int trunc_size, char *hex_key_string,
|
||||
unsigned char output[100];
|
||||
int key_len, src_len;
|
||||
const md_info_t *md_info = NULL;
|
||||
md_context_t ctx = MD_CONTEXT_T_INIT;
|
||||
md_context_t ctx;
|
||||
|
||||
md_init( &ctx );
|
||||
|
||||
memset(md_name, 0x00, 100);
|
||||
memset(src_str, 0x00, 10000);
|
||||
@ -314,7 +320,7 @@ void md_hmac_multi( char *text_md_name, int trunc_size, char *hex_key_string,
|
||||
TEST_ASSERT ( 0 == md_hmac_reset( &ctx ) );
|
||||
TEST_ASSERT ( 0 == md_hmac_update( &ctx, src_str, src_len ) );
|
||||
TEST_ASSERT ( 0 == md_hmac_finish( &ctx, output ) );
|
||||
TEST_ASSERT ( 0 == md_free_ctx( &ctx ) );
|
||||
md_free( &ctx );
|
||||
|
||||
hexify( hash_str, output, md_get_size(md_info) );
|
||||
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
||||
|
@ -21,6 +21,8 @@ void pbkdf2_hmac( int hash, char *hex_password_string, char *hex_salt_string,
|
||||
int pw_len, salt_len;
|
||||
unsigned char key[100];
|
||||
|
||||
md_init( &ctx );
|
||||
|
||||
memset(pw_str, 0x00, 100);
|
||||
memset(salt_str, 0x00, 100);
|
||||
memset(dst_str, 0x00, 100);
|
||||
@ -36,7 +38,7 @@ void pbkdf2_hmac( int hash, char *hex_password_string, char *hex_salt_string,
|
||||
TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
|
||||
TEST_ASSERT( pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
|
||||
it_cnt, key_len, key ) == 0 );
|
||||
TEST_ASSERT( md_free_ctx( &ctx ) == 0 );
|
||||
md_free( &ctx );
|
||||
|
||||
hexify( dst_str, key, key_len );
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, result_key_string ) == 0 );
|
||||
|
@ -22,6 +22,8 @@ void pbkdf2_hmac( int hash, char *hex_password_string,
|
||||
int pw_len, salt_len;
|
||||
unsigned char key[100];
|
||||
|
||||
md_init( &ctx );
|
||||
|
||||
memset(pw_str, 0x00, 100);
|
||||
memset(salt_str, 0x00, 100);
|
||||
memset(dst_str, 0x00, 100);
|
||||
@ -37,7 +39,7 @@ void pbkdf2_hmac( int hash, char *hex_password_string,
|
||||
TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
|
||||
TEST_ASSERT( pkcs5_pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
|
||||
it_cnt, key_len, key ) == 0 );
|
||||
TEST_ASSERT( md_free_ctx( &ctx ) == 0 );
|
||||
md_free( &ctx );
|
||||
|
||||
hexify( dst_str, key, key_len );
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, result_key_string ) == 0 );
|
||||
|
Loading…
Reference in New Issue
Block a user