early-access version 1503
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_md_process( )
|
||||
void mbedtls_md_process( )
|
||||
{
|
||||
const int *md_type_ptr;
|
||||
const mbedtls_md_info_t *info;
|
||||
@@ -40,7 +40,7 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_null_args( )
|
||||
void md_null_args( )
|
||||
{
|
||||
mbedtls_md_context_t ctx;
|
||||
const mbedtls_md_info_t *info = mbedtls_md_info_from_type( *( mbedtls_md_list() ) );
|
||||
@@ -103,7 +103,7 @@ void md_null_args( )
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_info( int md_type, char *md_name, int md_size )
|
||||
void md_info( int md_type, char * md_name, int md_size )
|
||||
{
|
||||
const mbedtls_md_info_t *md_info;
|
||||
const int *md_type_ptr;
|
||||
@@ -126,17 +126,16 @@ void md_info( int md_type, char *md_name, int md_size )
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_text( char *text_md_name, char *text_src_string, char *hex_hash_string )
|
||||
void md_text( char * text_md_name, char * text_src_string,
|
||||
data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[1000];
|
||||
unsigned char hash_str[1000];
|
||||
unsigned char output[100];
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( src_str, 0x00, 1000 );
|
||||
memset( hash_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) src_str, text_src_string, sizeof( src_str ) - 1 );
|
||||
@@ -145,47 +144,42 @@ void md_text( char *text_md_name, char *text_src_string, char *hex_hash_string )
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md( md_info, src_str, strlen( (char *) src_str ), output ) );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_hex( char *text_md_name, char *hex_src_string, char *hex_hash_string )
|
||||
void md_hex( char * text_md_name, data_t * src_str, data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[10000];
|
||||
unsigned char hash_str[10000];
|
||||
unsigned char output[100];
|
||||
int src_len;
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( src_str, 0x00, 10000 );
|
||||
memset( hash_str, 0x00, 10000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
|
||||
md_info = mbedtls_md_info_from_string( md_name );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
TEST_ASSERT ( 0 == mbedtls_md( md_info, src_str, src_len, output ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md( md_info, src_str->x, src_str->len, output ) );
|
||||
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_text_multi( char *text_md_name, char *text_src_string,
|
||||
char *hex_hash_string )
|
||||
void md_text_multi( char * text_md_name, char * text_src_string,
|
||||
data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[1000];
|
||||
unsigned char hash_str[1000];
|
||||
unsigned char output[100];
|
||||
int halfway, len;
|
||||
|
||||
@@ -197,7 +191,6 @@ void md_text_multi( char *text_md_name, char *text_src_string,
|
||||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( src_str, 0x00, 1000 );
|
||||
memset( hash_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
|
||||
@@ -217,17 +210,18 @@ void md_text_multi( char *text_md_name, char *text_src_string,
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str + halfway, len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx, output ) );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hash->len) == 0 );
|
||||
|
||||
/* Test clone */
|
||||
memset( hash_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx_copy, src_str + halfway, len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx_copy, output ) );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hash->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_md_free( &ctx );
|
||||
@@ -236,23 +230,18 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_hex_multi( char *text_md_name, char *hex_src_string,
|
||||
char *hex_hash_string )
|
||||
void md_hex_multi( char * text_md_name, data_t * src_str, data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[10000];
|
||||
unsigned char hash_str[10000];
|
||||
unsigned char output[100];
|
||||
int src_len, halfway;
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
mbedtls_md_context_t ctx, ctx_copy;
|
||||
int halfway;
|
||||
|
||||
mbedtls_md_init( &ctx );
|
||||
mbedtls_md_init( &ctx_copy );
|
||||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( src_str, 0x00, 10000 );
|
||||
memset( hash_str, 0x00, 10000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
|
||||
@@ -261,27 +250,27 @@ void md_hex_multi( char *text_md_name, char *hex_src_string,
|
||||
TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx, md_info, 0 ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx_copy, md_info, 0 ) );
|
||||
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
halfway = src_len / 2;
|
||||
halfway = src_str->len / 2;
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_starts( &ctx ) );
|
||||
TEST_ASSERT ( ctx.md_ctx != NULL );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str, halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str->x, halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_clone( &ctx_copy, &ctx ) );
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str + halfway, src_len - halfway) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str->x + halfway, src_str->len - halfway) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx, output ) );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hash->len ) == 0 );
|
||||
|
||||
/* Test clone */
|
||||
memset( hash_str, 0x00, 10000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx_copy, src_str + halfway, src_len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx_copy, src_str->x + halfway, src_str->len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx_copy, output ) );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hash->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_md_free( &ctx );
|
||||
@@ -290,56 +279,42 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_md_hmac( char *text_md_name, int trunc_size, char *hex_key_string,
|
||||
char *hex_src_string, char *hex_hash_string )
|
||||
void mbedtls_md_hmac( char * text_md_name, int trunc_size,
|
||||
data_t * key_str, data_t * src_str,
|
||||
data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[10000];
|
||||
unsigned char key_str[10000];
|
||||
unsigned char hash_str[10000];
|
||||
unsigned char output[100];
|
||||
int key_len, src_len;
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( src_str, 0x00, 10000 );
|
||||
memset( key_str, 0x00, 10000 );
|
||||
memset( hash_str, 0x00, 10000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
|
||||
md_info = mbedtls_md_info_from_string( md_name );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
TEST_ASSERT ( mbedtls_md_hmac( md_info, key_str, key_len, src_str, src_len, output ) == 0 );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
TEST_ASSERT ( mbedtls_md_hmac( md_info, key_str->x, key_str->len, src_str->x, src_str->len, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
trunc_size, hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_hmac_multi( char *text_md_name, int trunc_size, char *hex_key_string,
|
||||
char *hex_src_string, char *hex_hash_string )
|
||||
void md_hmac_multi( char * text_md_name, int trunc_size, data_t * key_str,
|
||||
data_t * src_str, data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[10000];
|
||||
unsigned char key_str[10000];
|
||||
unsigned char hash_str[10000];
|
||||
unsigned char output[100];
|
||||
int key_len, src_len, halfway;
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
mbedtls_md_context_t ctx;
|
||||
int halfway;
|
||||
|
||||
mbedtls_md_init( &ctx );
|
||||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( src_str, 0x00, 10000 );
|
||||
memset( key_str, 0x00, 10000 );
|
||||
memset( hash_str, 0x00, 10000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
|
||||
@@ -347,30 +322,27 @@ void md_hmac_multi( char *text_md_name, int trunc_size, char *hex_key_string,
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx, md_info, 1 ) );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
halfway = src_len / 2;
|
||||
halfway = src_str->len / 2;
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_starts( &ctx, key_str, key_len ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_starts( &ctx, key_str->x, key_str->len ) );
|
||||
TEST_ASSERT ( ctx.md_ctx != NULL );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str, halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str + halfway, src_len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str->x, halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str->x + halfway, src_str->len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_finish( &ctx, output ) );
|
||||
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
trunc_size, hash->len ) == 0 );
|
||||
|
||||
/* Test again, for reset() */
|
||||
memset( hash_str, 0x00, 10000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_reset( &ctx ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str, halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str + halfway, src_len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str->x, halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str->x + halfway, src_str->len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_finish( &ctx, output ) );
|
||||
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
trunc_size, hash->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_md_free( &ctx );
|
||||
@@ -378,15 +350,14 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
||||
void mbedtls_md_file( char *text_md_name, char *filename, char *hex_hash_string )
|
||||
void mbedtls_md_file( char * text_md_name, char * filename,
|
||||
data_t * hash )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char hash_str[1000];
|
||||
unsigned char output[100];
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( hash_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
|
||||
@@ -394,8 +365,9 @@ void mbedtls_md_file( char *text_md_name, char *filename, char *hex_hash_string
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
||||
TEST_ASSERT( mbedtls_md_file( md_info, filename, output ) == 0 );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
|
||||
mbedtls_md_get_size( md_info ),
|
||||
hash->len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
Reference in New Issue
Block a user