From d30ca130e8a597b8dfeda7ccfab9a54bd2db4967 Mon Sep 17 00:00:00 2001 From: Azim Khan Date: Fri, 9 Jun 2017 04:32:58 +0100 Subject: [PATCH] Combine hex parameters in a struct --- tests/suites/helpers.function | 7 + tests/suites/test_suite_aes.function | 98 +++---- tests/suites/test_suite_arc4.function | 12 +- tests/suites/test_suite_asn1write.function | 28 +- tests/suites/test_suite_base64.function | 33 +-- tests/suites/test_suite_blowfish.function | 93 +++---- tests/suites/test_suite_camellia.function | 80 +++--- tests/suites/test_suite_ccm.function | 55 ++-- tests/suites/test_suite_cipher.function | 84 +++--- tests/suites/test_suite_cmac.function | 74 +++--- tests/suites/test_suite_ctr_drbg.function | 35 ++- tests/suites/test_suite_debug.function | 5 +- tests/suites/test_suite_des.function | 108 ++++---- tests/suites/test_suite_ecdh.function | 32 ++- tests/suites/test_suite_ecdsa.function | 19 +- tests/suites/test_suite_ecjpake.function | 36 +-- tests/suites/test_suite_ecp.function | 30 +-- tests/suites/test_suite_entropy.function | 8 +- tests/suites/test_suite_gcm.function | 40 ++- tests/suites/test_suite_hmac_drbg.function | 89 +++---- tests/suites/test_suite_md.function | 74 +++--- tests/suites/test_suite_mdx.function | 20 +- tests/suites/test_suite_mpi.function | 17 +- tests/suites/test_suite_pem.function | 8 +- tests/suites/test_suite_pk.function | 65 +++-- tests/suites/test_suite_pkcs1_v15.function | 49 ++-- tests/suites/test_suite_pkcs1_v21.function | 67 ++--- tests/suites/test_suite_pkcs5.function | 33 +-- tests/suites/test_suite_pkparse.function | 5 +- tests/suites/test_suite_rsa.data | 6 +- tests/suites/test_suite_rsa.function | 287 ++++++++------------- tests/suites/test_suite_shax.function | 35 ++- tests/suites/test_suite_ssl.data | 32 +-- tests/suites/test_suite_ssl.function | 11 +- tests/suites/test_suite_x509parse.function | 45 ++-- tests/suites/test_suite_xtea.function | 50 ++-- 36 files changed, 756 insertions(+), 1014 deletions(-) diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function index 6bab65f65..c772af9a5 100644 --- a/tests/suites/helpers.function +++ b/tests/suites/helpers.function @@ -39,6 +39,13 @@ typedef UINT32 uint32_t; #include #endif +/* Type for Hex parameters */ +typedef struct HexParam_tag +{ + uint8_t * x; + uint32_t len; +} HexParam_t; + /*----------------------------------------------------------------------------*/ /* Constants */ diff --git a/tests/suites/test_suite_aes.function b/tests/suites/test_suite_aes.function index ad65a1b36..a0f1b13eb 100644 --- a/tests/suites/test_suite_aes.function +++ b/tests/suites/test_suite_aes.function @@ -8,9 +8,8 @@ */ /* BEGIN_CASE */ -void aes_encrypt_ecb( uint8_t * key_str, uint32_t key_len, uint8_t * src_str, - uint32_t src_str_len, uint8_t * hex_dst_string, - uint32_t hex_dst_string_len, int setkey_result ) +void aes_encrypt_ecb( HexParam_t * key_str, HexParam_t * src_str, + HexParam_t * hex_dst_string, int setkey_result ) { unsigned char output[100]; mbedtls_aes_context ctx; @@ -19,12 +18,12 @@ void aes_encrypt_ecb( uint8_t * key_str, uint32_t key_len, uint8_t * src_str, mbedtls_aes_init( &ctx ); - TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str, key_len * 8 ) == setkey_result ); + TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == setkey_result ); if( setkey_result == 0 ) { - TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_ENCRYPT, src_str, output ) == 0 ); + TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_ENCRYPT, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 ); } exit: @@ -33,9 +32,8 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void aes_decrypt_ecb( uint8_t * key_str, uint32_t key_len, uint8_t * src_str, - uint32_t src_str_len, uint8_t * hex_dst_string, - uint32_t hex_dst_string_len, int setkey_result ) +void aes_decrypt_ecb( HexParam_t * key_str, HexParam_t * src_str, + HexParam_t * hex_dst_string, int setkey_result ) { unsigned char output[100]; mbedtls_aes_context ctx; @@ -44,12 +42,12 @@ void aes_decrypt_ecb( uint8_t * key_str, uint32_t key_len, uint8_t * src_str, mbedtls_aes_init( &ctx ); - TEST_ASSERT( mbedtls_aes_setkey_dec( &ctx, key_str, key_len * 8 ) == setkey_result ); + TEST_ASSERT( mbedtls_aes_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == setkey_result ); if( setkey_result == 0 ) { - TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_DECRYPT, src_str, output ) == 0 ); + TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_DECRYPT, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 ); } exit: @@ -58,10 +56,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ -void aes_encrypt_cbc( uint8_t * key_str, uint32_t key_len, uint8_t * iv_str, - uint32_t iv_str_len, uint8_t * src_str, - uint32_t data_len, uint8_t * hex_dst_string, - uint32_t hex_dst_string_len, int cbc_result ) +void aes_encrypt_cbc( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string, + int cbc_result ) { unsigned char output[100]; mbedtls_aes_context ctx; @@ -70,12 +67,12 @@ void aes_encrypt_cbc( uint8_t * key_str, uint32_t key_len, uint8_t * iv_str, mbedtls_aes_init( &ctx ); - mbedtls_aes_setkey_enc( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_ENCRYPT, data_len, iv_str, src_str, output ) == cbc_result ); + mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result ); if( cbc_result == 0 ) { - TEST_ASSERT( hexcmp( output, hex_dst_string, data_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); } exit: @@ -84,10 +81,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ -void aes_decrypt_cbc( uint8_t * key_str, uint32_t key_len, uint8_t * iv_str, - uint32_t iv_str_len, uint8_t * src_str, - uint32_t data_len, uint8_t * hex_dst_string, - uint32_t hex_dst_string_len, int cbc_result ) +void aes_decrypt_cbc( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string, + int cbc_result ) { unsigned char output[100]; mbedtls_aes_context ctx; @@ -96,12 +92,12 @@ void aes_decrypt_cbc( uint8_t * key_str, uint32_t key_len, uint8_t * iv_str, mbedtls_aes_init( &ctx ); - mbedtls_aes_setkey_dec( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_DECRYPT, data_len, iv_str, src_str, output ) == cbc_result ); + mbedtls_aes_setkey_dec( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result ); if( cbc_result == 0) { - TEST_ASSERT( hexcmp( output, hex_dst_string, data_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); } exit: @@ -234,11 +230,8 @@ exit: /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ -void aes_encrypt_cfb128( uint8_t * key_str, uint32_t key_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len - ) +void aes_encrypt_cfb128( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_aes_context ctx; @@ -248,10 +241,10 @@ void aes_encrypt_cfb128( uint8_t * key_str, uint32_t key_len, mbedtls_aes_init( &ctx ); - mbedtls_aes_setkey_enc( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); + mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_ENCRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 ); exit: mbedtls_aes_free( &ctx ); @@ -259,11 +252,8 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ -void aes_decrypt_cfb128( uint8_t * key_str, uint32_t key_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len - ) +void aes_decrypt_cfb128( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_aes_context ctx; @@ -273,10 +263,10 @@ void aes_decrypt_cfb128( uint8_t * key_str, uint32_t key_len, mbedtls_aes_init( &ctx ); - mbedtls_aes_setkey_enc( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); + mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_DECRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 ); exit: mbedtls_aes_free( &ctx ); @@ -284,10 +274,8 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ -void aes_encrypt_cfb8( uint8_t * key_str, uint32_t key_len, uint8_t * iv_str, - uint32_t iv_str_len, uint8_t * src_str, - uint32_t src_len, uint8_t * hex_dst_string, - uint32_t hex_dst_string_len ) +void aes_encrypt_cfb8( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_aes_context ctx; @@ -296,10 +284,10 @@ void aes_encrypt_cfb8( uint8_t * key_str, uint32_t key_len, uint8_t * iv_str, mbedtls_aes_init( &ctx ); - mbedtls_aes_setkey_enc( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_ENCRYPT, src_len, iv_str, src_str, output ) == 0 ); + mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); exit: mbedtls_aes_free( &ctx ); @@ -307,10 +295,8 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ -void aes_decrypt_cfb8( uint8_t * key_str, uint32_t key_len, uint8_t * iv_str, - uint32_t iv_str_len, uint8_t * src_str, - uint32_t src_len, uint8_t * hex_dst_string, - uint32_t hex_dst_string_len ) +void aes_decrypt_cfb8( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_aes_context ctx; @@ -319,10 +305,10 @@ void aes_decrypt_cfb8( uint8_t * key_str, uint32_t key_len, uint8_t * iv_str, mbedtls_aes_init( &ctx ); - mbedtls_aes_setkey_enc( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_DECRYPT, src_len, iv_str, src_str, output ) == 0 ); + mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); exit: mbedtls_aes_free( &ctx ); diff --git a/tests/suites/test_suite_arc4.function b/tests/suites/test_suite_arc4.function index e3ff30376..2a56a5b2d 100644 --- a/tests/suites/test_suite_arc4.function +++ b/tests/suites/test_suite_arc4.function @@ -8,10 +8,8 @@ */ /* BEGIN_CASE */ -void mbedtls_arc4_crypt( uint8_t * src_str, uint32_t src_len, - uint8_t * key_str, uint32_t key_len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len - ) +void mbedtls_arc4_crypt( HexParam_t * src_str, HexParam_t * key_str, + HexParam_t * hex_dst_string ) { unsigned char dst_str[1000]; mbedtls_arc4_context ctx; @@ -20,10 +18,10 @@ void mbedtls_arc4_crypt( uint8_t * src_str, uint32_t src_len, mbedtls_arc4_init( &ctx ); - mbedtls_arc4_setup(&ctx, key_str, key_len); - TEST_ASSERT( mbedtls_arc4_crypt(&ctx, src_len, src_str, dst_str ) == 0 ); + mbedtls_arc4_setup(&ctx, key_str->x, key_str->len); + TEST_ASSERT( mbedtls_arc4_crypt(&ctx, src_str->len, src_str->x, dst_str ) == 0 ); - TEST_ASSERT( hexcmp( dst_str, hex_dst_string, src_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( dst_str, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); exit: mbedtls_arc4_free( &ctx ); diff --git a/tests/suites/test_suite_asn1write.function b/tests/suites/test_suite_asn1write.function index 3befa44d2..3b2d86e79 100644 --- a/tests/suites/test_suite_asn1write.function +++ b/tests/suites/test_suite_asn1write.function @@ -11,8 +11,7 @@ */ /* BEGIN_CASE */ -void mbedtls_asn1_write_octet_string( uint8_t * str, uint32_t str_len, - uint8_t * asn1, uint32_t asn1_len, +void mbedtls_asn1_write_octet_string( HexParam_t * str, HexParam_t * asn1, int buf_len, int result ) { int ret; @@ -25,7 +24,7 @@ void mbedtls_asn1_write_octet_string( uint8_t * str, uint32_t str_len, p = buf + GUARD_LEN + buf_len; - ret = mbedtls_asn1_write_octet_string( &p, buf + GUARD_LEN, str, str_len ); + ret = mbedtls_asn1_write_octet_string( &p, buf + GUARD_LEN, str->x, str->len ); /* Check for buffer overwrite on both sides */ for( i = 0; i < GUARD_LEN; i++ ) @@ -36,17 +35,17 @@ void mbedtls_asn1_write_octet_string( uint8_t * str, uint32_t str_len, if( result >= 0 ) { - TEST_ASSERT( p + asn1_len == buf + GUARD_LEN + buf_len ); + TEST_ASSERT( (size_t) ret == asn1->len ); + TEST_ASSERT( p + asn1->len == buf + GUARD_LEN + buf_len ); - TEST_ASSERT( memcmp( p, asn1, asn1_len ) == 0 ); + TEST_ASSERT( memcmp( p, asn1->x, asn1->len ) == 0 ); } } /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_asn1_write_ia5_string( char * str, uint8_t * asn1, - uint32_t asn1_len, int buf_len, int result - ) +void mbedtls_asn1_write_ia5_string( char * str, HexParam_t * asn1, + int buf_len, int result ) { int ret; unsigned char buf[150]; @@ -71,16 +70,17 @@ void mbedtls_asn1_write_ia5_string( char * str, uint8_t * asn1, if( result >= 0 ) { - TEST_ASSERT( p + asn1_len == buf + GUARD_LEN + buf_len ); + TEST_ASSERT( (size_t) ret == asn1->len ); + TEST_ASSERT( p + asn1->len == buf + GUARD_LEN + buf_len ); - TEST_ASSERT( memcmp( p, asn1, asn1_len ) == 0 ); + TEST_ASSERT( memcmp( p, asn1->x, asn1->len ) == 0 ); } } /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_asn1_write_len( int len, uint8_t * asn1, uint32_t asn1_len, - int buf_len, int result ) +void mbedtls_asn1_write_len( int len, HexParam_t * asn1, int buf_len, + int result ) { int ret; unsigned char buf[150]; @@ -105,9 +105,9 @@ void mbedtls_asn1_write_len( int len, uint8_t * asn1, uint32_t asn1_len, if( result >= 0 ) { - TEST_ASSERT( p + asn1_len == buf + GUARD_LEN + buf_len ); + TEST_ASSERT( p + asn1->len == buf + GUARD_LEN + buf_len ); - TEST_ASSERT( memcmp( p, asn1, asn1_len ) == 0 ); + TEST_ASSERT( memcmp( p, asn1->x, asn1->len ) == 0 ); /* Read back with mbedtls_asn1_get_len() to check */ ret = mbedtls_asn1_get_len( &p, buf + GUARD_LEN + buf_len, &read_len ); diff --git a/tests/suites/test_suite_base64.function b/tests/suites/test_suite_base64.function index 3077f16aa..53f0f6921 100644 --- a/tests/suites/test_suite_base64.function +++ b/tests/suites/test_suite_base64.function @@ -49,16 +49,15 @@ void mbedtls_base64_decode( char * src_string, char * dst_string, int result ) /* END_CASE */ /* BEGIN_CASE */ -void base64_encode_hex( char * src_hex, char * dst, int dst_buf_size, +void base64_encode_hex( HexParam_t * src, char * dst, int dst_buf_size, int result ) { - unsigned char *src = NULL, *res = NULL; - size_t len, src_len; + unsigned char *res = NULL; + size_t len; - src = unhexify_alloc( src_hex, &src_len ); res = zero_alloc( dst_buf_size ); - TEST_ASSERT( mbedtls_base64_encode( res, dst_buf_size, &len, src, src_len ) == result ); + TEST_ASSERT( mbedtls_base64_encode( res, dst_buf_size, &len, src->x, src->len ) == result ); if( result == 0 ) { TEST_ASSERT( len == strlen( dst ) ); @@ -66,45 +65,39 @@ void base64_encode_hex( char * src_hex, char * dst, int dst_buf_size, } exit: - mbedtls_free( src ); mbedtls_free( res ); } /* END_CASE */ /* BEGIN_CASE */ -void base64_decode_hex( char * src, char * dst_hex, int dst_buf_size, +void base64_decode_hex( char * src, HexParam_t * dst, int dst_buf_size, int result ) { - unsigned char *dst = NULL, *res = NULL; - size_t len, dst_len; + unsigned char *res = NULL; + size_t len; - dst = unhexify_alloc( dst_hex, &dst_len ); res = zero_alloc( dst_buf_size ); TEST_ASSERT( mbedtls_base64_decode( res, dst_buf_size, &len, (unsigned char *) src, strlen( src ) ) == result ); if( result == 0 ) { - TEST_ASSERT( len == dst_len ); - TEST_ASSERT( memcmp( dst, res, len ) == 0 ); + TEST_ASSERT( len == dst->len ); + TEST_ASSERT( memcmp( dst->x, res, len ) == 0 ); } exit: - mbedtls_free( dst ); mbedtls_free( res ); } /* END_CASE */ /* BEGIN_CASE */ -void base64_decode_hex_src( char * src_hex, char * dst_ref, int result ) +void base64_decode_hex_src( HexParam_t * src, char * dst_ref, int result ) { unsigned char dst[1000] = { 0 }; - unsigned char *src; - size_t src_len, len; + size_t len; - src = unhexify_alloc( src_hex, &src_len ); - - TEST_ASSERT( mbedtls_base64_decode( dst, sizeof( dst ), &len, src, src_len ) == result ); + TEST_ASSERT( mbedtls_base64_decode( dst, sizeof( dst ), &len, src->x, src->len ) == result ); if( result == 0 ) { TEST_ASSERT( len == strlen( dst_ref ) ); @@ -112,7 +105,7 @@ void base64_decode_hex_src( char * src_hex, char * dst_ref, int result ) } exit: - mbedtls_free( src ); + ;; } /* END_CASE */ diff --git a/tests/suites/test_suite_blowfish.function b/tests/suites/test_suite_blowfish.function index 55ab619fc..d88eac463 100644 --- a/tests/suites/test_suite_blowfish.function +++ b/tests/suites/test_suite_blowfish.function @@ -8,10 +8,8 @@ */ /* BEGIN_CASE */ -void blowfish_encrypt_ecb( uint8_t * key_str, uint32_t key_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len, int setkey_result ) +void blowfish_encrypt_ecb( HexParam_t * key_str, HexParam_t * src_str, + HexParam_t * hex_dst_string, int setkey_result ) { unsigned char output[100]; mbedtls_blowfish_context ctx; @@ -20,12 +18,12 @@ void blowfish_encrypt_ecb( uint8_t * key_str, uint32_t key_len, mbedtls_blowfish_init( &ctx ); - TEST_ASSERT( mbedtls_blowfish_setkey( &ctx, key_str, key_len * 8 ) == setkey_result ); + TEST_ASSERT( mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ) == setkey_result ); if( setkey_result == 0 ) { - TEST_ASSERT( mbedtls_blowfish_crypt_ecb( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, src_str, output ) == 0 ); + TEST_ASSERT( mbedtls_blowfish_crypt_ecb( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 8, hex_dst_string->len ) == 0 ); } exit: @@ -34,10 +32,8 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void blowfish_decrypt_ecb( uint8_t * key_str, uint32_t key_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len, int setkey_result ) +void blowfish_decrypt_ecb( HexParam_t * key_str, HexParam_t * src_str, + HexParam_t * hex_dst_string, int setkey_result ) { unsigned char output[100]; mbedtls_blowfish_context ctx; @@ -46,12 +42,12 @@ void blowfish_decrypt_ecb( uint8_t * key_str, uint32_t key_len, mbedtls_blowfish_init( &ctx ); - TEST_ASSERT( mbedtls_blowfish_setkey( &ctx, key_str, key_len * 8 ) == setkey_result ); + TEST_ASSERT( mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ) == setkey_result ); if( setkey_result == 0 ) { - TEST_ASSERT( mbedtls_blowfish_crypt_ecb( &ctx, MBEDTLS_BLOWFISH_DECRYPT, src_str, output ) == 0 ); + TEST_ASSERT( mbedtls_blowfish_crypt_ecb( &ctx, MBEDTLS_BLOWFISH_DECRYPT, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 8, hex_dst_string->len ) == 0 ); } exit: @@ -60,11 +56,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ -void blowfish_encrypt_cbc( uint8_t * key_str, uint32_t key_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t data_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len, int cbc_result ) +void blowfish_encrypt_cbc( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string, + int cbc_result ) { unsigned char output[100]; mbedtls_blowfish_context ctx; @@ -73,13 +67,13 @@ void blowfish_encrypt_cbc( uint8_t * key_str, uint32_t key_len, mbedtls_blowfish_init( &ctx ); - mbedtls_blowfish_setkey( &ctx, key_str, key_len * 8 ); + mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ); - TEST_ASSERT( mbedtls_blowfish_crypt_cbc( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, data_len , iv_str, src_str, output ) == cbc_result ); + TEST_ASSERT( mbedtls_blowfish_crypt_cbc( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, src_str->len , iv_str->x, src_str->x, output ) == cbc_result ); if( cbc_result == 0 ) { - TEST_ASSERT( hexcmp( output, hex_dst_string, data_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); } exit: @@ -88,11 +82,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ -void blowfish_decrypt_cbc( uint8_t * key_str, uint32_t key_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t data_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len, int cbc_result ) +void blowfish_decrypt_cbc( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string, + int cbc_result ) { unsigned char output[100]; mbedtls_blowfish_context ctx; @@ -101,12 +93,12 @@ void blowfish_decrypt_cbc( uint8_t * key_str, uint32_t key_len, mbedtls_blowfish_init( &ctx ); - mbedtls_blowfish_setkey( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_blowfish_crypt_cbc( &ctx, MBEDTLS_BLOWFISH_DECRYPT, data_len , iv_str, src_str, output ) == cbc_result ); + mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_blowfish_crypt_cbc( &ctx, MBEDTLS_BLOWFISH_DECRYPT, src_str->len , iv_str->x, src_str->x, output ) == cbc_result ); if( cbc_result == 0) { - TEST_ASSERT( hexcmp( output, hex_dst_string, data_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); } exit: @@ -115,11 +107,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ -void blowfish_encrypt_cfb64( uint8_t * key_str, uint32_t key_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t src_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len ) +void blowfish_encrypt_cfb64( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string + ) { unsigned char output[100]; mbedtls_blowfish_context ctx; @@ -129,10 +119,10 @@ void blowfish_encrypt_cfb64( uint8_t * key_str, uint32_t key_len, mbedtls_blowfish_init( &ctx ); - mbedtls_blowfish_setkey( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_blowfish_crypt_cfb64( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, src_len, &iv_offset, iv_str, src_str, output ) == 0 ); + mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_blowfish_crypt_cfb64( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, src_str->len, &iv_offset, iv_str->x, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); exit: mbedtls_blowfish_free( &ctx ); @@ -140,11 +130,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ -void blowfish_decrypt_cfb64( uint8_t * key_str, uint32_t key_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t src_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len ) +void blowfish_decrypt_cfb64( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string + ) { unsigned char output[100]; mbedtls_blowfish_context ctx; @@ -154,10 +142,10 @@ void blowfish_decrypt_cfb64( uint8_t * key_str, uint32_t key_len, mbedtls_blowfish_init( &ctx ); - mbedtls_blowfish_setkey( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_blowfish_crypt_cfb64( &ctx, MBEDTLS_BLOWFISH_DECRYPT, src_len, &iv_offset, iv_str, src_str, output ) == 0 ); + mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_blowfish_crypt_cfb64( &ctx, MBEDTLS_BLOWFISH_DECRYPT, src_str->len, &iv_offset, iv_str->x, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); exit: mbedtls_blowfish_free( &ctx ); @@ -165,11 +153,8 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ -void blowfish_encrypt_ctr( uint8_t * key_str, uint32_t key_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t src_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len ) +void blowfish_encrypt_ctr( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string ) { unsigned char stream_str[100]; unsigned char output[100]; @@ -181,10 +166,10 @@ void blowfish_encrypt_ctr( uint8_t * key_str, uint32_t key_len, mbedtls_blowfish_init( &ctx ); - mbedtls_blowfish_setkey( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_blowfish_crypt_ctr( &ctx, src_len, &iv_offset, iv_str, stream_str, src_str, output ) == 0 ); + mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_blowfish_crypt_ctr( &ctx, src_str->len, &iv_offset, iv_str->x, stream_str, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); exit: mbedtls_blowfish_free( &ctx ); diff --git a/tests/suites/test_suite_camellia.function b/tests/suites/test_suite_camellia.function index 96d25a251..4bfa1a5da 100644 --- a/tests/suites/test_suite_camellia.function +++ b/tests/suites/test_suite_camellia.function @@ -8,10 +8,8 @@ */ /* BEGIN_CASE */ -void camellia_encrypt_ecb( uint8_t * key_str, uint32_t key_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len, int setkey_result ) +void camellia_encrypt_ecb( HexParam_t * key_str, HexParam_t * src_str, + HexParam_t * hex_dst_string, int setkey_result ) { unsigned char output[100]; mbedtls_camellia_context ctx; @@ -20,12 +18,12 @@ void camellia_encrypt_ecb( uint8_t * key_str, uint32_t key_len, mbedtls_camellia_init( &ctx ); - TEST_ASSERT( mbedtls_camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == setkey_result ); + TEST_ASSERT( mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == setkey_result ); if( setkey_result == 0 ) { - TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str, output ) == 0 ); + TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 ); } exit: @@ -34,10 +32,8 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void camellia_decrypt_ecb( uint8_t * key_str, uint32_t key_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len, int setkey_result ) +void camellia_decrypt_ecb( HexParam_t * key_str, HexParam_t * src_str, + HexParam_t * hex_dst_string, int setkey_result ) { unsigned char output[100]; mbedtls_camellia_context ctx; @@ -46,12 +42,12 @@ void camellia_decrypt_ecb( uint8_t * key_str, uint32_t key_len, mbedtls_camellia_init( &ctx ); - TEST_ASSERT( mbedtls_camellia_setkey_dec( &ctx, key_str, key_len * 8 ) == setkey_result ); + TEST_ASSERT( mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == setkey_result ); if( setkey_result == 0 ) { - TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str, output ) == 0 ); + TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 ); } exit: @@ -60,11 +56,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ -void camellia_encrypt_cbc( uint8_t * key_str, uint32_t key_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t data_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len, int cbc_result ) +void camellia_encrypt_cbc( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string, + int cbc_result ) { unsigned char output[100]; mbedtls_camellia_context ctx; @@ -73,12 +67,12 @@ void camellia_encrypt_cbc( uint8_t * key_str, uint32_t key_len, mbedtls_camellia_init( &ctx ); - mbedtls_camellia_setkey_enc( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_camellia_crypt_cbc( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == cbc_result ); + mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_camellia_crypt_cbc( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->len, iv_str->x, src_str->x, output) == cbc_result ); if( cbc_result == 0 ) { - TEST_ASSERT( hexcmp( output, hex_dst_string, data_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); } exit: @@ -87,11 +81,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ -void camellia_decrypt_cbc( uint8_t * key_str, uint32_t key_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t data_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len, int cbc_result ) +void camellia_decrypt_cbc( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string, + int cbc_result ) { unsigned char output[100]; mbedtls_camellia_context ctx; @@ -100,12 +92,12 @@ void camellia_decrypt_cbc( uint8_t * key_str, uint32_t key_len, mbedtls_camellia_init( &ctx ); - mbedtls_camellia_setkey_dec( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_camellia_crypt_cbc( &ctx, MBEDTLS_CAMELLIA_DECRYPT, data_len, iv_str, src_str, output ) == cbc_result ); + mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_camellia_crypt_cbc( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result ); if( cbc_result == 0 ) { - TEST_ASSERT( hexcmp( output, hex_dst_string, data_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); } exit: @@ -114,11 +106,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ -void camellia_encrypt_cfb128( uint8_t * key_str, uint32_t key_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len ) +void camellia_encrypt_cfb128( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, + HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_camellia_context ctx; @@ -128,10 +118,10 @@ void camellia_encrypt_cfb128( uint8_t * key_str, uint32_t key_len, mbedtls_camellia_init( &ctx ); - mbedtls_camellia_setkey_enc( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); + mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 ); exit: mbedtls_camellia_free( &ctx ); @@ -139,11 +129,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ -void camellia_decrypt_cfb128( uint8_t * key_str, uint32_t key_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len ) +void camellia_decrypt_cfb128( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, + HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_camellia_context ctx; @@ -153,10 +141,10 @@ void camellia_decrypt_cfb128( uint8_t * key_str, uint32_t key_len, mbedtls_camellia_init( &ctx ); - mbedtls_camellia_setkey_enc( &ctx, key_str, key_len * 8 ); - TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); + mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); + TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_DECRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 ); exit: mbedtls_camellia_free( &ctx ); diff --git a/tests/suites/test_suite_ccm.function b/tests/suites/test_suite_ccm.function index 5dbc837e4..b9df023a7 100644 --- a/tests/suites/test_suite_ccm.function +++ b/tests/suites/test_suite_ccm.function @@ -116,34 +116,31 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_ccm_encrypt_and_tag( int cipher_id, uint8_t * key, - uint32_t key_len, uint8_t * msg, - uint32_t msg_len, uint8_t * iv, - uint32_t iv_len, uint8_t * add, - uint32_t add_len, uint8_t * result, - uint32_t result_len ) +void mbedtls_ccm_encrypt_and_tag( int cipher_id, HexParam_t * key, + HexParam_t * msg, HexParam_t * iv, + HexParam_t * add, HexParam_t * result ) { mbedtls_ccm_context ctx; size_t tag_len; - uint8_t * msg_n_tag = (uint8_t *)malloc( result_len + 2 ); + uint8_t * msg_n_tag = (uint8_t *)malloc( result->len + 2 ); mbedtls_ccm_init( &ctx ); - memset( msg_n_tag, 0, result_len + 2 ); - memcpy( msg_n_tag, msg, msg_len ); + memset( msg_n_tag, 0, result->len + 2 ); + memcpy( msg_n_tag, msg->x, msg->len ); - tag_len = result_len - msg_len; + tag_len = result->len - msg->len; - TEST_ASSERT( mbedtls_ccm_setkey( &ctx, cipher_id, key, key_len * 8 ) == 0 ); + TEST_ASSERT( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ) == 0 ); /* Test with input == output */ - TEST_ASSERT( mbedtls_ccm_encrypt_and_tag( &ctx, msg_len, iv, iv_len, add, add_len, - msg_n_tag, msg_n_tag, msg_n_tag + msg_len, tag_len ) == 0 ); + TEST_ASSERT( mbedtls_ccm_encrypt_and_tag( &ctx, msg->len, iv->x, iv->len, add->x, add->len, + msg_n_tag, msg_n_tag, msg_n_tag + msg->len, tag_len ) == 0 ); - TEST_ASSERT( memcmp( msg_n_tag, result, result_len ) == 0 ); + TEST_ASSERT( memcmp( msg_n_tag, result->x, result->len ) == 0 ); /* Check we didn't write past the end */ - TEST_ASSERT( msg_n_tag[result_len] == 0 && msg_n_tag[result_len + 1] == 0 ); + TEST_ASSERT( msg_n_tag[result->len] == 0 && msg_n_tag[result->len + 1] == 0 ); exit: mbedtls_ccm_free( &ctx ); @@ -152,12 +149,10 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_ccm_auth_decrypt( int cipher_id, uint8_t * key, uint32_t key_len, - uint8_t * msg, uint32_t msg_len, uint8_t * iv, - uint32_t iv_len, uint8_t * add, - uint32_t add_len, int tag_len, - char * result, uint8_t * hex_msg, - uint32_t hex_msg_len ) +void mbedtls_ccm_auth_decrypt( int cipher_id, HexParam_t * key, + HexParam_t * msg, HexParam_t * iv, + HexParam_t * add, int tag_len, char * result, + HexParam_t * hex_msg ) { unsigned char tag[16]; mbedtls_ccm_context ctx; @@ -167,8 +162,8 @@ void mbedtls_ccm_auth_decrypt( int cipher_id, uint8_t * key, uint32_t key_len, memset( tag, 0x00, sizeof( tag ) ); - msg_len -= tag_len; - memcpy( tag, msg + msg_len, tag_len ); + msg->len -= tag_len; + memcpy( tag, msg->x + msg->len, tag_len ); if( strcmp( "FAIL", result ) == 0 ) { @@ -179,26 +174,26 @@ void mbedtls_ccm_auth_decrypt( int cipher_id, uint8_t * key, uint32_t key_len, ret = 0; } - TEST_ASSERT( mbedtls_ccm_setkey( &ctx, cipher_id, key, key_len * 8 ) == 0 ); + TEST_ASSERT( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ) == 0 ); /* Test with input == output */ - TEST_ASSERT( mbedtls_ccm_auth_decrypt( &ctx, msg_len, iv, iv_len, add, add_len, - msg, msg, msg + msg_len, tag_len ) == ret ); + TEST_ASSERT( mbedtls_ccm_auth_decrypt( &ctx, msg->len, iv->x, iv->len, add->x, add->len, + msg->x, msg->x, msg->x + msg->len, tag_len ) == ret ); if( ret == 0 ) { - TEST_ASSERT( memcmp( msg, hex_msg, hex_msg_len ) == 0 ); + TEST_ASSERT( memcmp( msg->x, hex_msg->x, hex_msg->len ) == 0 ); } else { size_t i; - for( i = 0; i < msg_len; i++ ) - TEST_ASSERT( msg[i] == 0 ); + for( i = 0; i < msg->len; i++ ) + TEST_ASSERT( msg->x[i] == 0 ); } /* Check we didn't write past the end (where the original tag is) */ - TEST_ASSERT( memcmp( msg + msg_len, tag, tag_len ) == 0 ); + TEST_ASSERT( memcmp( msg->x + msg->len, tag, tag_len ) == 0 ); exit: mbedtls_ccm_free( &ctx ); diff --git a/tests/suites/test_suite_cipher.function b/tests/suites/test_suite_cipher.function index 435c9a384..767e44102 100644 --- a/tests/suites/test_suite_cipher.function +++ b/tests/suites/test_suite_cipher.function @@ -471,12 +471,10 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void decrypt_test_vec( int cipher_id, int pad_mode, uint8_t * key, - uint32_t key_len, uint8_t * iv, uint32_t iv_len, - uint8_t * cipher, uint32_t cipher_len, uint8_t * clear, - uint32_t clear_len, uint8_t * ad, uint32_t ad_len, - uint8_t * tag, uint32_t tag_len, int finish_result, - int tag_result ) +void decrypt_test_vec( int cipher_id, int pad_mode, HexParam_t * key, + HexParam_t * iv, HexParam_t * cipher, + HexParam_t * clear, HexParam_t * ad, HexParam_t * tag, + int finish_result, int tag_result ) { unsigned char output[265]; mbedtls_cipher_context_t ctx; @@ -494,35 +492,35 @@ void decrypt_test_vec( int cipher_id, int pad_mode, uint8_t * key, /* Prepare context */ TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx, mbedtls_cipher_info_from_type( cipher_id ) ) ); - TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key, 8 * key_len, MBEDTLS_DECRYPT ) ); + TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key->x, 8 * key->len, MBEDTLS_DECRYPT ) ); #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) if( pad_mode != -1 ) TEST_ASSERT( 0 == mbedtls_cipher_set_padding_mode( &ctx, pad_mode ) ); #else (void) pad_mode; #endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */ - TEST_ASSERT( 0 == mbedtls_cipher_set_iv( &ctx, iv, iv_len ) ); + TEST_ASSERT( 0 == mbedtls_cipher_set_iv( &ctx, iv->x, iv->len ) ); TEST_ASSERT( 0 == mbedtls_cipher_reset( &ctx ) ); #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C) - TEST_ASSERT( 0 == mbedtls_cipher_update_ad( &ctx, ad, ad_len ) ); + TEST_ASSERT( 0 == mbedtls_cipher_update_ad( &ctx, ad->x, ad->len ) ); #endif - /* decode buffer and check tag */ + /* decode buffer and check tag->x */ total_len = 0; - TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx, cipher, cipher_len, output, &outlen ) ); + TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx, cipher->x, cipher->len, output, &outlen ) ); total_len += outlen; TEST_ASSERT( finish_result == mbedtls_cipher_finish( &ctx, output + outlen, &outlen ) ); total_len += outlen; #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C) - TEST_ASSERT( tag_result == mbedtls_cipher_check_tag( &ctx, tag, tag_len ) ); + TEST_ASSERT( tag_result == mbedtls_cipher_check_tag( &ctx, tag->x, tag->len ) ); #endif /* check plaintext only if everything went fine */ if( 0 == finish_result && 0 == tag_result ) { - TEST_ASSERT( total_len == clear_len ); - TEST_ASSERT( 0 == memcmp( output, clear, clear_len ) ); + TEST_ASSERT( total_len == clear->len ); + TEST_ASSERT( 0 == memcmp( output, clear->x, clear->len ) ); } exit: @@ -531,11 +529,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_AEAD */ -void auth_crypt_tv( int cipher_id, uint8_t * key, uint32_t key_len, - uint8_t * iv, uint32_t iv_len, uint8_t * ad, - uint32_t ad_len, uint8_t * cipher, uint32_t cipher_len, - uint8_t * tag, uint32_t tag_len, char * result, - uint8_t * clear, uint32_t clear_len ) +void auth_crypt_tv( int cipher_id, HexParam_t * key, HexParam_t * iv, + HexParam_t * ad, HexParam_t * cipher, HexParam_t * tag, + char * result, HexParam_t * clear ) { int ret; unsigned char output[267]; /* above + 2 (overwrite check) */ @@ -552,12 +548,12 @@ void auth_crypt_tv( int cipher_id, uint8_t * key, uint32_t key_len, /* Prepare context */ TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx, mbedtls_cipher_info_from_type( cipher_id ) ) ); - TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key, 8 * key_len, MBEDTLS_DECRYPT ) ); + TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key->x, 8 * key->len, MBEDTLS_DECRYPT ) ); - /* decode buffer and check tag */ - ret = mbedtls_cipher_auth_decrypt( &ctx, iv, iv_len, ad, ad_len, - cipher, cipher_len, output, &outlen, - tag, tag_len ); + /* decode buffer and check tag->x */ + ret = mbedtls_cipher_auth_decrypt( &ctx, iv->x, iv->len, ad->x, ad->len, + cipher->x, cipher->len, output, &outlen, + tag->x, tag->len ); /* make sure we didn't overwrite */ TEST_ASSERT( output[outlen + 0] == 0xFF ); @@ -573,27 +569,27 @@ void auth_crypt_tv( int cipher_id, uint8_t * key, uint32_t key_len, /* otherwise, make sure it was decrypted properly */ TEST_ASSERT( ret == 0 ); - TEST_ASSERT( outlen == clear_len ); - TEST_ASSERT( memcmp( output, clear, clear_len ) == 0 ); + TEST_ASSERT( outlen == clear->len ); + TEST_ASSERT( memcmp( output, clear->x, clear->len ) == 0 ); - /* then encrypt the clear and make sure we get the same ciphertext and tag */ + /* then encrypt the clear->x and make sure we get the same ciphertext and tag->x */ memset( output, 0xFF, sizeof( output ) ); outlen = 0; - ret = mbedtls_cipher_auth_encrypt( &ctx, iv, iv_len, ad, ad_len, - clear, clear_len, output, &outlen, - my_tag, tag_len ); + ret = mbedtls_cipher_auth_encrypt( &ctx, iv->x, iv->len, ad->x, ad->len, + clear->x, clear->len, output, &outlen, + my_tag, tag->len ); TEST_ASSERT( ret == 0 ); - TEST_ASSERT( outlen == clear_len ); - TEST_ASSERT( memcmp( output, cipher, clear_len ) == 0 ); - TEST_ASSERT( memcmp( my_tag, tag, tag_len ) == 0 ); + TEST_ASSERT( outlen == clear->len ); + TEST_ASSERT( memcmp( output, cipher->x, clear->len ) == 0 ); + TEST_ASSERT( memcmp( my_tag, tag->x, tag->len ) == 0 ); /* make sure we didn't overwrite */ TEST_ASSERT( output[outlen + 0] == 0xFF ); TEST_ASSERT( output[outlen + 1] == 0xFF ); - TEST_ASSERT( my_tag[tag_len + 0] == 0xFF ); - TEST_ASSERT( my_tag[tag_len + 1] == 0xFF ); + TEST_ASSERT( my_tag[tag->len + 0] == 0xFF ); + TEST_ASSERT( my_tag[tag->len + 1] == 0xFF ); exit: @@ -602,9 +598,9 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void test_vec_ecb( int cipher_id, int operation, uint8_t * key, - uint32_t key_len, uint8_t * input, uint32_t input_len, - uint8_t * result, uint32_t result_len, int finish_result ) +void test_vec_ecb( int cipher_id, int operation, HexParam_t * key, + HexParam_t * input, HexParam_t * result, int finish_result + ) { mbedtls_cipher_context_t ctx; unsigned char output[32]; @@ -619,9 +615,9 @@ void test_vec_ecb( int cipher_id, int operation, uint8_t * key, mbedtls_cipher_info_from_type( cipher_id ) ) ); - TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key, 8 * key_len, operation ) ); + TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key->x, 8 * key->len, operation ) ); - TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx, input, + TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx, input->x, mbedtls_cipher_get_block_size( &ctx ), output, &outlen ) ); TEST_ASSERT( outlen == mbedtls_cipher_get_block_size( &ctx ) ); @@ -631,7 +627,7 @@ void test_vec_ecb( int cipher_id, int operation, uint8_t * key, /* check plaintext only if everything went fine */ if( 0 == finish_result ) - TEST_ASSERT( 0 == memcmp( output, result, + TEST_ASSERT( 0 == memcmp( output, result->x, mbedtls_cipher_get_block_size( &ctx ) ) ); exit: @@ -659,8 +655,8 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ -void check_padding( int pad_mode, uint8_t * input, uint32_t ilen, int ret, - int dlen_check ) +void check_padding( int pad_mode, HexParam_t * input, int ret, int dlen_check + ) { mbedtls_cipher_info_t cipher_info; mbedtls_cipher_context_t ctx; @@ -674,7 +670,7 @@ void check_padding( int pad_mode, uint8_t * input, uint32_t ilen, int ret, TEST_ASSERT( 0 == mbedtls_cipher_set_padding_mode( &ctx, pad_mode ) ); - TEST_ASSERT( ret == ctx.get_padding( input, ilen, &dlen ) ); + TEST_ASSERT( ret == ctx.get_padding( input->x, input->len, &dlen ) ); if( 0 == ret ) TEST_ASSERT( dlen == (size_t) dlen_check ); } diff --git a/tests/suites/test_suite_cmac.function b/tests/suites/test_suite_cmac.function index 08ee207ee..85b3be149 100644 --- a/tests/suites/test_suite_cmac.function +++ b/tests/suites/test_suite_cmac.function @@ -119,16 +119,13 @@ void mbedtls_cmac_setkey( int cipher_type, int key_size, int result ) /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_cmac_multiple_blocks( int cipher_type, uint8_t * key, - uint32_t key_len, int keybits, - int block_size, uint8_t * block1, - uint32_t block1_sz, int block1_len, - uint8_t * block2, uint32_t block2_sz, - int block2_len, uint8_t * block3, - uint32_t block3_sz, int block3_len, - uint8_t * block4, uint32_t block4_sz, - int block4_len, uint8_t * expected_result, - uint32_t expected_result_len ) +void mbedtls_cmac_multiple_blocks( int cipher_type, HexParam_t * key, + int keybits, int block_size, + HexParam_t * block1, int block1_len, + HexParam_t * block2, int block2_len, + HexParam_t * block3, int block3_len, + HexParam_t * block4, int block4_len, + HexParam_t * expected_result ) { const mbedtls_cipher_info_t *cipher_info; mbedtls_cipher_context_t ctx; @@ -151,34 +148,34 @@ void mbedtls_cmac_multiple_blocks( int cipher_type, uint8_t * key, TEST_ASSERT( mbedtls_cipher_setup( &ctx, cipher_info ) == 0 ); TEST_ASSERT( mbedtls_cipher_cmac_starts( &ctx, - (const unsigned char*)key, + (const unsigned char*)key->x, keybits ) == 0 ); /* Multiple partial and complete blocks. A negative length means skip the * update operation */ if( block1_len >= 0) TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx, - (unsigned char*)block1, + (unsigned char*)block1->x, block1_len ) == 0); if( block2_len >= 0 ) TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx, - (unsigned char*)block2, + (unsigned char*)block2->x, block2_len ) == 0); if( block3_len >= 0 ) TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx, - (unsigned char*)block3, + (unsigned char*)block3->x, block3_len ) == 0); if( block4_len >= 0 ) TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx, - (unsigned char*)block4, + (unsigned char*)block4->x, block4_len ) == 0); TEST_ASSERT( mbedtls_cipher_cmac_finish( &ctx, output ) == 0 ); - TEST_ASSERT( memcmp( output, expected_result, block_size ) == 0 ); + TEST_ASSERT( memcmp( output, expected_result->x, block_size ) == 0 ); exit: mbedtls_cipher_free( &ctx ); @@ -187,31 +184,22 @@ exit: /* BEGIN_CASE */ void mbedtls_cmac_multiple_operations_same_key( int cipher_type, - uint8_t * key, - uint32_t key_len, int keybits, + HexParam_t * key, int keybits, int block_size, - uint8_t * block_a1, - uint32_t block_a1_sz, + HexParam_t * block_a1, int block_a1_len, - uint8_t * block_a2, - uint32_t block_a2_sz, + HexParam_t * block_a2, int block_a2_len, - uint8_t * block_a3, - uint32_t block_a3_sz, + HexParam_t * block_a3, int block_a3_len, - uint8_t * expected_result_a, - uint32_t expected_result_a_len, - uint8_t * block_b1, - uint32_t block_b1_sz, + HexParam_t * expected_result_a, + HexParam_t * block_b1, int block_b1_len, - uint8_t * block_b2, - uint32_t block_b2_sz, + HexParam_t * block_b2, int block_b2_len, - uint8_t * block_b3, - uint32_t block_b3_sz, + HexParam_t * block_b3, int block_b3_len, - uint8_t * expected_result_b, - uint32_t expected_result_b_len + HexParam_t * expected_result_b ) { const mbedtls_cipher_info_t *cipher_info; @@ -240,7 +228,7 @@ void mbedtls_cmac_multiple_operations_same_key( int cipher_type, TEST_ASSERT( mbedtls_cipher_setup( &ctx, cipher_info ) == 0 ); TEST_ASSERT( mbedtls_cipher_cmac_starts( &ctx, - (const unsigned char*)key, + (const unsigned char*)key->x, keybits ) == 0 ); /* Sequence A */ @@ -249,22 +237,22 @@ void mbedtls_cmac_multiple_operations_same_key( int cipher_type, * update operation */ if( block_a1_len >= 0 ) TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx, - (unsigned char*)block_a1, + (unsigned char*)block_a1->x, block_a1_len ) == 0); if( block_a2_len >= 0 ) TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx, - (unsigned char*)block_a2, + (unsigned char*)block_a2->x, block_a2_len ) == 0); if( block_a3_len >= 0 ) TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx, - (unsigned char*)block_a3, + (unsigned char*)block_a3->x, block_a3_len ) == 0); TEST_ASSERT( mbedtls_cipher_cmac_finish( &ctx, output ) == 0 ); - TEST_ASSERT( memcmp( output, expected_result_a, block_size ) == 0 ); + TEST_ASSERT( memcmp( output, expected_result_a->x, block_size ) == 0 ); TEST_ASSERT( mbedtls_cipher_cmac_reset( &ctx ) == 0 ); @@ -274,22 +262,22 @@ void mbedtls_cmac_multiple_operations_same_key( int cipher_type, * update operation */ if( block_b1_len >= 0) TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx, - (unsigned char*)block_b1, + (unsigned char*)block_b1->x, block_b1_len ) == 0); if( block_b2_len >= 0 ) TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx, - (unsigned char*)block_b2, + (unsigned char*)block_b2->x, block_b2_len ) == 0); if( block_b3_len >= 0 ) TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx, - (unsigned char*)block_b3, + (unsigned char*)block_b3->x, block_b3_len ) == 0); TEST_ASSERT( mbedtls_cipher_cmac_finish( &ctx, output ) == 0 ); - TEST_ASSERT( memcmp( output, expected_result_b, block_size ) == 0 ); + TEST_ASSERT( memcmp( output, expected_result_b->x, block_size ) == 0 ); exit: mbedtls_cipher_free( &ctx ); diff --git a/tests/suites/test_suite_ctr_drbg.function b/tests/suites/test_suite_ctr_drbg.function index 7dd3d5c39..619c76e19 100644 --- a/tests/suites/test_suite_ctr_drbg.function +++ b/tests/suites/test_suite_ctr_drbg.function @@ -51,11 +51,9 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void ctr_drbg_validate_pr( uint8_t * add_init, uint32_t add_init_len, - uint8_t * entropy, uint32_t entropy_len, - uint8_t * add1, uint32_t add1_len, uint8_t * add2, - uint32_t add2_len, uint8_t * result_str, - uint32_t result_str_len ) +void ctr_drbg_validate_pr( HexParam_t * add_init, HexParam_t * entropy, + HexParam_t * add1, HexParam_t * add2, + HexParam_t * result_str ) { mbedtls_ctr_drbg_context ctx; unsigned char buf[512]; @@ -64,12 +62,12 @@ void ctr_drbg_validate_pr( uint8_t * add_init, uint32_t add_init_len, test_offset_idx = 0; - TEST_ASSERT( mbedtls_ctr_drbg_seed_entropy_len( &ctx, mbedtls_test_entropy_func, entropy, add_init, add_init_len, 32 ) == 0 ); + TEST_ASSERT( mbedtls_ctr_drbg_seed_entropy_len( &ctx, mbedtls_test_entropy_func, entropy->x, add_init->x, add_init->len, 32 ) == 0 ); mbedtls_ctr_drbg_set_prediction_resistance( &ctx, MBEDTLS_CTR_DRBG_PR_ON ); - TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, buf, 16, add1, add1_len ) == 0 ); - TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, buf, 16, add2, add2_len ) == 0 ); - TEST_ASSERT( hexcmp( buf, result_str, 16, result_str_len ) == 0 ); + TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, buf, 16, add1->x, add1->len ) == 0 ); + TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, buf, 16, add2->x, add2->len ) == 0 ); + TEST_ASSERT( hexcmp( buf, result_str->x, 16, result_str->len ) == 0 ); exit: mbedtls_ctr_drbg_free( &ctx ); @@ -77,12 +75,9 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void ctr_drbg_validate_nopr( uint8_t * add_init, uint32_t add_init_len, - uint8_t * entropy, uint32_t entropy_len, - uint8_t * add1, uint32_t add1_len, - uint8_t * add_reseed, uint32_t add_reseed_len, - uint8_t * add2, uint32_t add2_len, - uint8_t * result_str, uint32_t result_str_len ) +void ctr_drbg_validate_nopr( HexParam_t * add_init, HexParam_t * entropy, + HexParam_t * add1, HexParam_t * add_reseed, + HexParam_t * add2, HexParam_t * result_str ) { mbedtls_ctr_drbg_context ctx; unsigned char buf[512]; @@ -91,12 +86,12 @@ void ctr_drbg_validate_nopr( uint8_t * add_init, uint32_t add_init_len, test_offset_idx = 0; - TEST_ASSERT( mbedtls_ctr_drbg_seed_entropy_len( &ctx, mbedtls_test_entropy_func, entropy, add_init, add_init_len, 32 ) == 0 ); + TEST_ASSERT( mbedtls_ctr_drbg_seed_entropy_len( &ctx, mbedtls_test_entropy_func, entropy->x, add_init->x, add_init->len, 32 ) == 0 ); - TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, buf, 16, add1, add1_len ) == 0 ); - TEST_ASSERT( mbedtls_ctr_drbg_reseed( &ctx, add_reseed, add_reseed_len ) == 0 ); - TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, buf, 16, add2, add2_len ) == 0 ); - TEST_ASSERT( hexcmp( buf, result_str, 16, result_str_len ) == 0 ); + TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, buf, 16, add1->x, add1->len ) == 0 ); + TEST_ASSERT( mbedtls_ctr_drbg_reseed( &ctx, add_reseed->x, add_reseed->len ) == 0 ); + TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, buf, 16, add2->x, add2->len ) == 0 ); + TEST_ASSERT( hexcmp( buf, result_str->x, 16, result_str->len ) == 0 ); exit: mbedtls_ctr_drbg_free( &ctx ); diff --git a/tests/suites/test_suite_debug.function b/tests/suites/test_suite_debug.function index 8c51bf20a..f517c8a9f 100644 --- a/tests/suites/test_suite_debug.function +++ b/tests/suites/test_suite_debug.function @@ -105,8 +105,7 @@ exit: /* BEGIN_CASE */ void mbedtls_debug_print_buf( char * file, int line, char * text, - uint8_t * data, uint32_t data_len, - char * result_str ) + HexParam_t * data, char * result_str ) { mbedtls_ssl_context ssl; mbedtls_ssl_config conf; @@ -122,7 +121,7 @@ void mbedtls_debug_print_buf( char * file, int line, char * text, mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer); - mbedtls_debug_print_buf( &ssl, 0, file, line, text, data, data_len ); + mbedtls_debug_print_buf( &ssl, 0, file, line, text, data->x, data->len ); TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 ); diff --git a/tests/suites/test_suite_des.function b/tests/suites/test_suite_des.function index 3d1bb9235..8fab5e415 100644 --- a/tests/suites/test_suite_des.function +++ b/tests/suites/test_suite_des.function @@ -8,16 +8,15 @@ */ /* BEGIN_CASE */ -void des_check_weak( uint8_t * key, uint32_t key_len, int ret ) +void des_check_weak( HexParam_t * key, int ret ) { - TEST_ASSERT( mbedtls_des_key_check_weak( key ) == ret ); + TEST_ASSERT( mbedtls_des_key_check_weak( key->x ) == ret ); } /* END_CASE */ /* BEGIN_CASE */ -void des_encrypt_ecb( uint8_t * key_str, uint32_t key_str_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len ) +void des_encrypt_ecb( HexParam_t * key_str, HexParam_t * src_str, + HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_des_context ctx; @@ -26,10 +25,10 @@ void des_encrypt_ecb( uint8_t * key_str, uint32_t key_str_len, mbedtls_des_init( &ctx ); - mbedtls_des_setkey_enc( &ctx, key_str ); - TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str, output ) == 0 ); + mbedtls_des_setkey_enc( &ctx, key_str->x ); + TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 8, hex_dst_string->len ) == 0 ); exit: mbedtls_des_free( &ctx ); @@ -37,9 +36,8 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void des_decrypt_ecb( uint8_t * key_str, uint32_t key_str_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len ) +void des_decrypt_ecb( HexParam_t * key_str, HexParam_t * src_str, + HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_des_context ctx; @@ -48,10 +46,10 @@ void des_decrypt_ecb( uint8_t * key_str, uint32_t key_str_len, mbedtls_des_init( &ctx ); - mbedtls_des_setkey_dec( &ctx, key_str ); - TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str, output ) == 0 ); + mbedtls_des_setkey_dec( &ctx, key_str->x ); + TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 8, hex_dst_string->len ) == 0 ); exit: mbedtls_des_free( &ctx ); @@ -59,10 +57,8 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ -void des_encrypt_cbc( uint8_t * key_str, uint32_t key_str_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t src_len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len, +void des_encrypt_cbc( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string, int cbc_result ) { unsigned char output[100]; @@ -72,12 +68,12 @@ void des_encrypt_cbc( uint8_t * key_str, uint32_t key_str_len, mbedtls_des_init( &ctx ); - mbedtls_des_setkey_enc( &ctx, key_str ); - TEST_ASSERT( mbedtls_des_crypt_cbc( &ctx, MBEDTLS_DES_ENCRYPT, src_len, iv_str, src_str, output ) == cbc_result ); + mbedtls_des_setkey_enc( &ctx, key_str->x ); + TEST_ASSERT( mbedtls_des_crypt_cbc( &ctx, MBEDTLS_DES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result ); if( cbc_result == 0 ) { - TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); } exit: @@ -86,10 +82,8 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ -void des_decrypt_cbc( uint8_t * key_str, uint32_t key_str_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t src_len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len, +void des_decrypt_cbc( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string, int cbc_result ) { unsigned char output[100]; @@ -99,12 +93,12 @@ void des_decrypt_cbc( uint8_t * key_str, uint32_t key_str_len, mbedtls_des_init( &ctx ); - mbedtls_des_setkey_dec( &ctx, key_str ); - TEST_ASSERT( mbedtls_des_crypt_cbc( &ctx, MBEDTLS_DES_DECRYPT, src_len, iv_str, src_str, output ) == cbc_result ); + mbedtls_des_setkey_dec( &ctx, key_str->x ); + TEST_ASSERT( mbedtls_des_crypt_cbc( &ctx, MBEDTLS_DES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result ); if( cbc_result == 0 ) { - TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); } exit: @@ -113,9 +107,8 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void des3_encrypt_ecb( int key_count, uint8_t * key_str, uint32_t key_str_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len ) +void des3_encrypt_ecb( int key_count, HexParam_t * key_str, + HexParam_t * src_str, HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_des3_context ctx; @@ -125,15 +118,15 @@ void des3_encrypt_ecb( int key_count, uint8_t * key_str, uint32_t key_str_len, if( key_count == 2 ) - mbedtls_des3_set2key_enc( &ctx, key_str ); + mbedtls_des3_set2key_enc( &ctx, key_str->x ); else if( key_count == 3 ) - mbedtls_des3_set3key_enc( &ctx, key_str ); + mbedtls_des3_set3key_enc( &ctx, key_str->x ); else TEST_ASSERT( 0 ); - TEST_ASSERT( mbedtls_des3_crypt_ecb( &ctx, src_str, output ) == 0 ); + TEST_ASSERT( mbedtls_des3_crypt_ecb( &ctx, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 8, hex_dst_string->len ) == 0 ); exit: mbedtls_des3_free( &ctx ); @@ -141,9 +134,8 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void des3_decrypt_ecb( int key_count, uint8_t * key_str, uint32_t key_str_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len ) +void des3_decrypt_ecb( int key_count, HexParam_t * key_str, + HexParam_t * src_str, HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_des3_context ctx; @@ -153,15 +145,15 @@ void des3_decrypt_ecb( int key_count, uint8_t * key_str, uint32_t key_str_len, if( key_count == 2 ) - mbedtls_des3_set2key_dec( &ctx, key_str ); + mbedtls_des3_set2key_dec( &ctx, key_str->x ); else if( key_count == 3 ) - mbedtls_des3_set3key_dec( &ctx, key_str ); + mbedtls_des3_set3key_dec( &ctx, key_str->x ); else TEST_ASSERT( 0 ); - TEST_ASSERT( mbedtls_des3_crypt_ecb( &ctx, src_str, output ) == 0 ); + TEST_ASSERT( mbedtls_des3_crypt_ecb( &ctx, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 8, hex_dst_string->len ) == 0 ); exit: mbedtls_des3_free( &ctx ); @@ -169,11 +161,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ -void des3_encrypt_cbc( int key_count, uint8_t * key_str, uint32_t key_str_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t src_len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len, - int cbc_result ) +void des3_encrypt_cbc( int key_count, HexParam_t * key_str, + HexParam_t * iv_str, HexParam_t * src_str, + HexParam_t * hex_dst_string, int cbc_result ) { unsigned char output[100]; mbedtls_des3_context ctx; @@ -183,18 +173,18 @@ void des3_encrypt_cbc( int key_count, uint8_t * key_str, uint32_t key_str_len, if( key_count == 2 ) - mbedtls_des3_set2key_enc( &ctx, key_str ); + mbedtls_des3_set2key_enc( &ctx, key_str->x ); else if( key_count == 3 ) - mbedtls_des3_set3key_enc( &ctx, key_str ); + mbedtls_des3_set3key_enc( &ctx, key_str->x ); else TEST_ASSERT( 0 ); - TEST_ASSERT( mbedtls_des3_crypt_cbc( &ctx, MBEDTLS_DES_ENCRYPT, src_len, iv_str, src_str, output ) == cbc_result ); + TEST_ASSERT( mbedtls_des3_crypt_cbc( &ctx, MBEDTLS_DES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result ); if( cbc_result == 0 ) { - TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); } exit: @@ -203,11 +193,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ -void des3_decrypt_cbc( int key_count, uint8_t * key_str, uint32_t key_str_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t src_len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len, - int cbc_result ) +void des3_decrypt_cbc( int key_count, HexParam_t * key_str, + HexParam_t * iv_str, HexParam_t * src_str, + HexParam_t * hex_dst_string, int cbc_result ) { unsigned char output[100]; mbedtls_des3_context ctx; @@ -217,18 +205,18 @@ void des3_decrypt_cbc( int key_count, uint8_t * key_str, uint32_t key_str_len, if( key_count == 2 ) - mbedtls_des3_set2key_dec( &ctx, key_str ); + mbedtls_des3_set2key_dec( &ctx, key_str->x ); else if( key_count == 3 ) - mbedtls_des3_set3key_dec( &ctx, key_str ); + mbedtls_des3_set3key_dec( &ctx, key_str->x ); else TEST_ASSERT( 0 ); - TEST_ASSERT( mbedtls_des3_crypt_cbc( &ctx, MBEDTLS_DES_DECRYPT, src_len, iv_str, src_str, output ) == cbc_result ); + TEST_ASSERT( mbedtls_des3_crypt_cbc( &ctx, MBEDTLS_DES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result ); if( cbc_result == 0 ) { - TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); } exit: diff --git a/tests/suites/test_suite_ecdh.function b/tests/suites/test_suite_ecdh.function index 0b88e653f..2d71828eb 100644 --- a/tests/suites/test_suite_ecdh.function +++ b/tests/suites/test_suite_ecdh.function @@ -43,11 +43,9 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void ecdh_primitive_testvec( int id, uint8_t * rnd_buf_A, - uint32_t rnd_buf_A_len, char * xA_str, - char * yA_str, uint8_t * rnd_buf_B, - uint32_t rnd_buf_B_len, char * xB_str, - char * yB_str, char * z_str ) +void ecdh_primitive_testvec( int id, HexParam_t * rnd_buf_A, char * xA_str, + char * yA_str, HexParam_t * rnd_buf_B, + char * xB_str, char * yB_str, char * z_str ) { mbedtls_ecp_group grp; mbedtls_ecp_point qA, qB; @@ -61,36 +59,36 @@ void ecdh_primitive_testvec( int id, uint8_t * rnd_buf_A, TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 ); - rnd_info_A.buf = rnd_buf_A; - rnd_info_A.length = rnd_buf_A_len; + rnd_info_A.buf = rnd_buf_A->x; + rnd_info_A.length = rnd_buf_A->len; - /* Fix rnd_buf_A by shifting it left if necessary */ + /* Fix rnd_buf_A->x by shifting it left if necessary */ if( grp.nbits % 8 != 0 ) { unsigned char shift = 8 - ( grp.nbits % 8 ); size_t i; for( i = 0; i < rnd_info_A.length - 1; i++ ) - rnd_buf_A[i] = rnd_buf_A[i] << shift - | rnd_buf_A[i+1] >> ( 8 - shift ); + rnd_buf_A->x[i] = rnd_buf_A->x[i] << shift + | rnd_buf_A->x[i+1] >> ( 8 - shift ); - rnd_buf_A[rnd_info_A.length-1] <<= shift; + rnd_buf_A->x[rnd_info_A.length-1] <<= shift; } - rnd_info_B.buf = rnd_buf_B; - rnd_info_B.length = rnd_buf_B_len; + rnd_info_B.buf = rnd_buf_B->x; + rnd_info_B.length = rnd_buf_B->len; - /* Fix rnd_buf_B by shifting it left if necessary */ + /* Fix rnd_buf_B->x by shifting it left if necessary */ if( grp.nbits % 8 != 0 ) { unsigned char shift = 8 - ( grp.nbits % 8 ); size_t i; for( i = 0; i < rnd_info_B.length - 1; i++ ) - rnd_buf_B[i] = rnd_buf_B[i] << shift - | rnd_buf_B[i+1] >> ( 8 - shift ); + rnd_buf_B->x[i] = rnd_buf_B->x[i] << shift + | rnd_buf_B->x[i+1] >> ( 8 - shift ); - rnd_buf_B[rnd_info_B.length-1] <<= shift; + rnd_buf_B->x[rnd_info_B.length-1] <<= shift; } TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dA, &qA, diff --git a/tests/suites/test_suite_ecdsa.function b/tests/suites/test_suite_ecdsa.function index 5398ab5be..65d497d53 100644 --- a/tests/suites/test_suite_ecdsa.function +++ b/tests/suites/test_suite_ecdsa.function @@ -41,9 +41,8 @@ exit: /* BEGIN_CASE */ void ecdsa_prim_test_vectors( int id, char * d_str, char * xQ_str, - char * yQ_str, uint8_t * rnd_buf, - uint32_t rnd_buf_len, uint8_t * hash, - uint32_t hlen, char * r_str, char * s_str, + char * yQ_str, HexParam_t * rnd_buf, + HexParam_t * hash, char * r_str, char * s_str, int result ) { mbedtls_ecp_group grp; @@ -61,22 +60,22 @@ void ecdsa_prim_test_vectors( int id, char * d_str, char * xQ_str, TEST_ASSERT( mbedtls_mpi_read_string( &d, 16, d_str ) == 0 ); TEST_ASSERT( mbedtls_mpi_read_string( &r_check, 16, r_str ) == 0 ); TEST_ASSERT( mbedtls_mpi_read_string( &s_check, 16, s_str ) == 0 ); - rnd_info.buf = rnd_buf; - rnd_info.length = rnd_buf_len; + rnd_info.buf = rnd_buf->x; + rnd_info.length = rnd_buf->len; - /* Fix rnd_buf by shifting it left if necessary */ + /* Fix rnd_buf->x by shifting it left if necessary */ if( grp.nbits % 8 != 0 ) { unsigned char shift = 8 - ( grp.nbits % 8 ); size_t i; for( i = 0; i < rnd_info.length - 1; i++ ) - rnd_buf[i] = rnd_buf[i] << shift | rnd_buf[i+1] >> ( 8 - shift ); + rnd_buf->x[i] = rnd_buf->x[i] << shift | rnd_buf->x[i+1] >> ( 8 - shift ); - rnd_buf[rnd_info.length-1] <<= shift; + rnd_buf->x[rnd_info.length-1] <<= shift; } - TEST_ASSERT( mbedtls_ecdsa_sign( &grp, &r, &s, &d, hash, hlen, + TEST_ASSERT( mbedtls_ecdsa_sign( &grp, &r, &s, &d, hash->x, hash->len, rnd_buffer_rand, &rnd_info ) == result ); if ( result == 0) @@ -84,7 +83,7 @@ void ecdsa_prim_test_vectors( int id, char * d_str, char * xQ_str, TEST_ASSERT( mbedtls_mpi_cmp_mpi( &r, &r_check ) == 0 ); TEST_ASSERT( mbedtls_mpi_cmp_mpi( &s, &s_check ) == 0 ); - TEST_ASSERT( mbedtls_ecdsa_verify( &grp, hash, hlen, &Q, &r_check, &s_check ) == 0 ); + TEST_ASSERT( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q, &r_check, &s_check ) == 0 ); } exit: diff --git a/tests/suites/test_suite_ecjpake.function b/tests/suites/test_suite_ecjpake.function index e108a89a7..2579704a7 100644 --- a/tests/suites/test_suite_ecjpake.function +++ b/tests/suites/test_suite_ecjpake.function @@ -106,48 +106,33 @@ void ecjpake_selftest( ) /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C */ -void read_round_one( int role, char * data, int ref_ret ) +void read_round_one( int role, HexParam_t * msg, int ref_ret ) { mbedtls_ecjpake_context ctx; - const unsigned char * pw = NULL; const size_t pw_len = 0; - unsigned char *msg; - size_t len; - mbedtls_ecjpake_init( &ctx ); - msg = unhexify_alloc( data, &len ); - TEST_ASSERT( msg != NULL ); - TEST_ASSERT( mbedtls_ecjpake_setup( &ctx, role, MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, pw_len ) == 0 ); - TEST_ASSERT( mbedtls_ecjpake_read_round_one( &ctx, msg, len ) == ref_ret ); + TEST_ASSERT( mbedtls_ecjpake_read_round_one( &ctx, msg->x, msg->len ) == ref_ret ); exit: mbedtls_ecjpake_free( &ctx ); - mbedtls_free( msg ); } /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C */ -void read_round_two_cli( char * data, int ref_ret ) +void read_round_two_cli( HexParam_t * msg, int ref_ret ) { mbedtls_ecjpake_context ctx; - const unsigned char * pw = NULL; const size_t pw_len = 0; - unsigned char *msg; - size_t len; - mbedtls_ecjpake_init( &ctx ); - msg = unhexify_alloc( data, &len ); - TEST_ASSERT( msg != NULL ); - TEST_ASSERT( mbedtls_ecjpake_setup( &ctx, MBEDTLS_ECJPAKE_CLIENT, MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, pw_len ) == 0 ); @@ -157,30 +142,22 @@ void read_round_two_cli( char * data, int ref_ret ) ADD_SIZE( ecjpake_test_X3 ), ADD_SIZE( ecjpake_test_X4 ) ) == 0 ); - TEST_ASSERT( mbedtls_ecjpake_read_round_two( &ctx, msg, len ) == ref_ret ); + TEST_ASSERT( mbedtls_ecjpake_read_round_two( &ctx, msg->x, msg->len ) == ref_ret ); exit: mbedtls_ecjpake_free( &ctx ); - mbedtls_free( msg ); } /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C */ -void read_round_two_srv( char * data, int ref_ret ) +void read_round_two_srv( HexParam_t * msg, int ref_ret ) { mbedtls_ecjpake_context ctx; - const unsigned char * pw = NULL; const size_t pw_len = 0; - unsigned char *msg; - size_t len; - mbedtls_ecjpake_init( &ctx ); - msg = unhexify_alloc( data, &len ); - TEST_ASSERT( msg != NULL ); - TEST_ASSERT( mbedtls_ecjpake_setup( &ctx, MBEDTLS_ECJPAKE_SERVER, MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, pw_len ) == 0 ); @@ -190,10 +167,9 @@ void read_round_two_srv( char * data, int ref_ret ) ADD_SIZE( ecjpake_test_X1 ), ADD_SIZE( ecjpake_test_X2 ) ) == 0 ); - TEST_ASSERT( mbedtls_ecjpake_read_round_two( &ctx, msg, len ) == ref_ret ); + TEST_ASSERT( mbedtls_ecjpake_read_round_two( &ctx, msg->x, msg->len ) == ref_ret ); exit: mbedtls_ecjpake_free( &ctx ); - mbedtls_free( msg ); } /* END_CASE */ diff --git a/tests/suites/test_suite_ecp.function b/tests/suites/test_suite_ecp.function index 8c8dac04a..d5a092668 100644 --- a/tests/suites/test_suite_ecp.function +++ b/tests/suites/test_suite_ecp.function @@ -193,7 +193,7 @@ exit: /* BEGIN_CASE */ void ecp_write_binary( int id, char * x, char * y, char * z, int format, - uint8_t * out, uint32_t out_len, int blen, int ret ) + HexParam_t * out, int blen, int ret ) { mbedtls_ecp_group grp; mbedtls_ecp_point P; @@ -215,7 +215,7 @@ void ecp_write_binary( int id, char * x, char * y, char * z, int format, if( ret == 0 ) { - TEST_ASSERT( hexcmp( buf, out, olen, out_len ) == 0 ); + TEST_ASSERT( hexcmp( buf, out->x, olen, out->len ) == 0 ); } exit: @@ -224,8 +224,8 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void ecp_read_binary( int id, uint8_t * buf, uint32_t ilen, char * x, - char * y, char * z, int ret ) +void ecp_read_binary( int id, HexParam_t * buf, char * x, char * y, char * z, + int ret ) { mbedtls_ecp_group grp; mbedtls_ecp_point P; @@ -241,7 +241,7 @@ void ecp_read_binary( int id, uint8_t * buf, uint32_t ilen, char * x, TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, y ) == 0 ); TEST_ASSERT( mbedtls_mpi_read_string( &Z, 16, z ) == 0 ); - TEST_ASSERT( mbedtls_ecp_point_read_binary( &grp, &P, buf, ilen ) == ret ); + TEST_ASSERT( mbedtls_ecp_point_read_binary( &grp, &P, buf->x, buf->len ) == ret ); if( ret == 0 ) { @@ -257,13 +257,13 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_ecp_tls_read_point( int id, uint8_t * buf, uint32_t ilen, - char * x, char * y, char * z, int ret ) +void mbedtls_ecp_tls_read_point( int id, HexParam_t * buf, char * x, char * y, + char * z, int ret ) { mbedtls_ecp_group grp; mbedtls_ecp_point P; mbedtls_mpi X, Y, Z; - const unsigned char *vbuf = buf; + const unsigned char *vbuf = buf->x; mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &P ); @@ -275,14 +275,14 @@ void mbedtls_ecp_tls_read_point( int id, uint8_t * buf, uint32_t ilen, TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, y ) == 0 ); TEST_ASSERT( mbedtls_mpi_read_string( &Z, 16, z ) == 0 ); - TEST_ASSERT( mbedtls_ecp_tls_read_point( &grp, &P, &vbuf, ilen ) == ret ); + TEST_ASSERT( mbedtls_ecp_tls_read_point( &grp, &P, &vbuf, buf->len ) == ret ); if( ret == 0 ) { TEST_ASSERT( mbedtls_mpi_cmp_mpi( &P.X, &X ) == 0 ); TEST_ASSERT( mbedtls_mpi_cmp_mpi( &P.Y, &Y ) == 0 ); TEST_ASSERT( mbedtls_mpi_cmp_mpi( &P.Z, &Z ) == 0 ); - TEST_ASSERT( vbuf - buf == ilen ); + TEST_ASSERT( (uint32_t)( vbuf - buf->x ) == buf->len ); } exit: @@ -344,22 +344,22 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_ecp_tls_read_group( uint8_t * buf, uint32_t len, int result, - int bits, int record_len ) +void mbedtls_ecp_tls_read_group( HexParam_t * buf, int result, int bits, + int record_len ) { mbedtls_ecp_group grp; - const unsigned char *vbuf = buf; + const unsigned char *vbuf = buf->x; int ret; mbedtls_ecp_group_init( &grp ); - ret = mbedtls_ecp_tls_read_group( &grp, &vbuf, len ); + ret = mbedtls_ecp_tls_read_group( &grp, &vbuf, buf->len ); TEST_ASSERT( ret == result ); if( ret == 0) { TEST_ASSERT( mbedtls_mpi_bitlen( &grp.P ) == (size_t) bits ); - TEST_ASSERT( vbuf - buf == record_len); + TEST_ASSERT( vbuf - buf->x == record_len); } exit: diff --git a/tests/suites/test_suite_entropy.function b/tests/suites/test_suite_entropy.function index c34c1854a..9b54f3027 100644 --- a/tests/suites/test_suite_entropy.function +++ b/tests/suites/test_suite_entropy.function @@ -302,7 +302,7 @@ void entropy_nv_seed_std_io( ) /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_PLATFORM_NV_SEED_ALT:MBEDTLS_ENTROPY_SHA512_ACCUMULATOR */ -void entropy_nv_seed( uint8_t * read_seed, uint32_t read_seed_len ) +void entropy_nv_seed( HexParam_t * read_seed ) { mbedtls_sha512_context accumulator; mbedtls_entropy_context ctx; @@ -311,7 +311,7 @@ void entropy_nv_seed( uint8_t * read_seed, uint32_t read_seed_len ) unsigned char entropy[MBEDTLS_ENTROPY_BLOCK_SIZE]; unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE]; unsigned char empty[MBEDTLS_ENTROPY_BLOCK_SIZE]; - unsigned char read_seed[MBEDTLS_ENTROPY_BLOCK_SIZE]; + unsigned char read_seed->x[MBEDTLS_ENTROPY_BLOCK_SIZE]; unsigned char check_seed[MBEDTLS_ENTROPY_BLOCK_SIZE]; unsigned char check_entropy[MBEDTLS_ENTROPY_BLOCK_SIZE]; @@ -323,7 +323,7 @@ void entropy_nv_seed( uint8_t * read_seed, uint32_t read_seed_len ) memset( check_entropy, 3, MBEDTLS_ENTROPY_BLOCK_SIZE ); // Set the initial NV seed to read - memcpy( buffer_seed, read_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ); + memcpy( buffer_seed, read_seed->x, MBEDTLS_ENTROPY_BLOCK_SIZE ); // Make sure we read/write NV seed from our buffers mbedtls_platform_set_nv_seed( buffer_nv_seed_read, buffer_nv_seed_write ); @@ -348,7 +348,7 @@ void entropy_nv_seed( uint8_t * read_seed, uint32_t read_seed_len ) // First run for updating write_seed header[0] = 0; mbedtls_sha512_update( &accumulator, header, 2 ); - mbedtls_sha512_update( &accumulator, read_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ); + mbedtls_sha512_update( &accumulator, read_seed->x, MBEDTLS_ENTROPY_BLOCK_SIZE ); mbedtls_sha512_finish( &accumulator, buf ); memset( &accumulator, 0, sizeof( mbedtls_sha512_context ) ); diff --git a/tests/suites/test_suite_gcm.function b/tests/suites/test_suite_gcm.function index 17d79c579..c0e799c19 100644 --- a/tests/suites/test_suite_gcm.function +++ b/tests/suites/test_suite_gcm.function @@ -51,14 +51,11 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void gcm_encrypt_and_tag( int cipher_id, uint8_t * key_str, uint32_t key_len, - uint8_t * src_str, uint32_t pt_len, - uint8_t * iv_str, uint32_t iv_len, - uint8_t * add_str, uint32_t add_len, - uint8_t * hex_dst_string, - uint32_t hex_dst_string_len, int tag_len_bits, - uint8_t * hex_tag_string, - uint32_t hex_tag_string_len, int init_result ) +void gcm_encrypt_and_tag( int cipher_id, HexParam_t * key_str, + HexParam_t * src_str, HexParam_t * iv_str, + HexParam_t * add_str, HexParam_t * hex_dst_string, + int tag_len_bits, HexParam_t * hex_tag_string, + int init_result ) { unsigned char output[128]; unsigned char tag_output[16]; @@ -71,13 +68,13 @@ void gcm_encrypt_and_tag( int cipher_id, uint8_t * key_str, uint32_t key_len, memset(tag_output, 0x00, 16); - TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str, key_len * 8 ) == init_result ); + TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == init_result ); if( init_result == 0 ) { - TEST_ASSERT( mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_ENCRYPT, pt_len, iv_str, iv_len, add_str, add_len, src_str, output, tag_len, tag_output ) == 0 ); + TEST_ASSERT( mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_ENCRYPT, src_str->len, iv_str->x, iv_str->len, add_str->x, add_str->len, src_str->x, output, tag_len, tag_output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, pt_len, hex_dst_string_len ) == 0 ); - TEST_ASSERT( hexcmp( tag_output, hex_tag_string, tag_len, hex_tag_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); + TEST_ASSERT( hexcmp( tag_output, hex_tag_string->x, tag_len, hex_tag_string->len ) == 0 ); } exit: @@ -86,14 +83,11 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void gcm_decrypt_and_verify( int cipher_id, uint8_t * key_str, - uint32_t key_len, uint8_t * src_str, - uint32_t pt_len, uint8_t * iv_str, - uint32_t iv_len, uint8_t * add_str, - uint32_t add_len, int tag_len_bits, - uint8_t * tag_str, uint32_t tag_str_len, - char * result, uint8_t * pt_result, - uint32_t pt_result_len, int init_result ) +void gcm_decrypt_and_verify( int cipher_id, HexParam_t * key_str, + HexParam_t * src_str, HexParam_t * iv_str, + HexParam_t * add_str, int tag_len_bits, + HexParam_t * tag_str, char * result, + HexParam_t * pt_result, int init_result ) { unsigned char output[128]; mbedtls_gcm_context ctx; @@ -105,10 +99,10 @@ void gcm_decrypt_and_verify( int cipher_id, uint8_t * key_str, memset(output, 0x00, 128); - TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str, key_len * 8 ) == init_result ); + TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == init_result ); if( init_result == 0 ) { - ret = mbedtls_gcm_auth_decrypt( &ctx, pt_len, iv_str, iv_len, add_str, add_len, tag_str, tag_len, src_str, output ); + ret = mbedtls_gcm_auth_decrypt( &ctx, src_str->len, iv_str->x, iv_str->len, add_str->x, add_str->len, tag_str->x, tag_len, src_str->x, output ); if( strcmp( "FAIL", result ) == 0 ) { @@ -118,7 +112,7 @@ void gcm_decrypt_and_verify( int cipher_id, uint8_t * key_str, { TEST_ASSERT( ret == 0 ); - TEST_ASSERT( hexcmp( output, pt_result, pt_len, pt_result_len ) == 0 ); + TEST_ASSERT( hexcmp( output, pt_result->x, src_str->len, pt_result->len ) == 0 ); } } diff --git a/tests/suites/test_suite_hmac_drbg.function b/tests/suites/test_suite_hmac_drbg.function index cf1f3683a..aeea62c36 100644 --- a/tests/suites/test_suite_hmac_drbg.function +++ b/tests/suites/test_suite_hmac_drbg.function @@ -161,12 +161,9 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void hmac_drbg_no_reseed( int md_alg, uint8_t * entropy, - uint32_t entropy_len, uint8_t * custom, - uint32_t custom_len, uint8_t * add1, - uint32_t add1_len, uint8_t * add2, - uint32_t add2_len, uint8_t * output, - uint32_t out_len ) +void hmac_drbg_no_reseed( int md_alg, HexParam_t * entropy, + HexParam_t * custom, HexParam_t * add1, + HexParam_t * add2, HexParam_t * output ) { unsigned char data[1024]; unsigned char my_output[512]; @@ -176,35 +173,35 @@ void hmac_drbg_no_reseed( int md_alg, uint8_t * entropy, mbedtls_hmac_drbg_init( &ctx ); - p_entropy.p = entropy; - p_entropy.len = entropy_len; + p_entropy.p = entropy->x; + p_entropy.len = entropy->len; md_info = mbedtls_md_info_from_type( md_alg ); TEST_ASSERT( md_info != NULL ); /* Test the simplified buffer-based variant */ - memcpy( data, entropy, p_entropy.len ); - memcpy( data + p_entropy.len, custom, custom_len ); + memcpy( data, entropy->x, p_entropy.len ); + memcpy( data + p_entropy.len, custom->x, custom->len ); TEST_ASSERT( mbedtls_hmac_drbg_seed_buf( &ctx, md_info, - data, p_entropy.len + custom_len ) == 0 ); - TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len, - add1, add1_len ) == 0 ); - TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len, - add2, add2_len ) == 0 ); + data, p_entropy.len + custom->len ) == 0 ); + TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len, + add1->x, add1->len ) == 0 ); + TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len, + add2->x, add2->len ) == 0 ); /* clear for second run */ mbedtls_hmac_drbg_free( &ctx ); - TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 ); + TEST_ASSERT( memcmp( my_output, output->x, output->len ) == 0 ); /* And now the normal entropy-based variant */ TEST_ASSERT( mbedtls_hmac_drbg_seed( &ctx, md_info, mbedtls_test_entropy_func, &p_entropy, - custom, custom_len ) == 0 ); - TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len, - add1, add1_len ) == 0 ); - TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len, - add2, add2_len ) == 0 ); - TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 ); + custom->x, custom->len ) == 0 ); + TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len, + add1->x, add1->len ) == 0 ); + TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len, + add2->x, add2->len ) == 0 ); + TEST_ASSERT( memcmp( my_output, output->x, output->len ) == 0 ); exit: mbedtls_hmac_drbg_free( &ctx ); @@ -212,11 +209,9 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void hmac_drbg_nopr( int md_alg, uint8_t * entropy, uint32_t entropy_len, - uint8_t * custom, uint32_t custom_len, uint8_t * add1, - uint32_t add1_len, uint8_t * add2, uint32_t add2_len, - uint8_t * add3, uint32_t add3_len, uint8_t * output, - uint32_t out_len ) +void hmac_drbg_nopr( int md_alg, HexParam_t * entropy, HexParam_t * custom, + HexParam_t * add1, HexParam_t * add2, HexParam_t * add3, + HexParam_t * output ) { unsigned char my_output[512]; entropy_ctx p_entropy; @@ -225,21 +220,21 @@ void hmac_drbg_nopr( int md_alg, uint8_t * entropy, uint32_t entropy_len, mbedtls_hmac_drbg_init( &ctx ); - p_entropy.p = entropy; - p_entropy.len = entropy_len; + p_entropy.p = entropy->x; + p_entropy.len = entropy->len; md_info = mbedtls_md_info_from_type( md_alg ); TEST_ASSERT( md_info != NULL ); TEST_ASSERT( mbedtls_hmac_drbg_seed( &ctx, md_info, mbedtls_test_entropy_func, &p_entropy, - custom, custom_len ) == 0 ); - TEST_ASSERT( mbedtls_hmac_drbg_reseed( &ctx, add1, add1_len ) == 0 ); - TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len, - add2, add2_len ) == 0 ); - TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len, - add3, add3_len ) == 0 ); + custom->x, custom->len ) == 0 ); + TEST_ASSERT( mbedtls_hmac_drbg_reseed( &ctx, add1->x, add1->len ) == 0 ); + TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len, + add2->x, add2->len ) == 0 ); + TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len, + add3->x, add3->len ) == 0 ); - TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 ); + TEST_ASSERT( memcmp( my_output, output->x, output->len ) == 0 ); exit: mbedtls_hmac_drbg_free( &ctx ); @@ -247,10 +242,8 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void hmac_drbg_pr( int md_alg, uint8_t * entropy, uint32_t entropy_len, - uint8_t * custom, uint32_t custom_len, uint8_t * add1, - uint32_t add1_len, uint8_t * add2, uint32_t add2_len, - uint8_t * output, uint32_t out_len ) +void hmac_drbg_pr( int md_alg, HexParam_t * entropy, HexParam_t * custom, + HexParam_t * add1, HexParam_t * add2, HexParam_t * output ) { unsigned char my_output[512]; entropy_ctx p_entropy; @@ -259,21 +252,21 @@ void hmac_drbg_pr( int md_alg, uint8_t * entropy, uint32_t entropy_len, mbedtls_hmac_drbg_init( &ctx ); - p_entropy.p = entropy; - p_entropy.len = entropy_len; + p_entropy.p = entropy->x; + p_entropy.len = entropy->len; md_info = mbedtls_md_info_from_type( md_alg ); TEST_ASSERT( md_info != NULL ); TEST_ASSERT( mbedtls_hmac_drbg_seed( &ctx, md_info, mbedtls_test_entropy_func, &p_entropy, - custom, custom_len ) == 0 ); + custom->x, custom->len ) == 0 ); mbedtls_hmac_drbg_set_prediction_resistance( &ctx, MBEDTLS_HMAC_DRBG_PR_ON ); - TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len, - add1, add1_len ) == 0 ); - TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len, - add2, add2_len ) == 0 ); + TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len, + add1->x, add1->len ) == 0 ); + TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len, + add2->x, add2->len ) == 0 ); - TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 ); + TEST_ASSERT( memcmp( my_output, output->x, output->len ) == 0 ); exit: mbedtls_hmac_drbg_free( &ctx ); diff --git a/tests/suites/test_suite_md.function b/tests/suites/test_suite_md.function index 23758ebdd..07e2d5849 100644 --- a/tests/suites/test_suite_md.function +++ b/tests/suites/test_suite_md.function @@ -127,7 +127,7 @@ void md_info( int md_type, char * md_name, int md_size ) /* BEGIN_CASE */ void md_text( char * text_md_name, char * text_src_string, - uint8_t * hex_hash_string, uint32_t hex_hash_string_len ) + HexParam_t * hex_hash_string ) { char md_name[100]; unsigned char src_str[1000]; @@ -145,13 +145,13 @@ void md_text( char * text_md_name, char * text_src_string, TEST_ASSERT ( 0 == mbedtls_md( md_info, src_str, strlen( (char *) src_str ), output ) ); - TEST_ASSERT( hexcmp( output, hex_hash_string, mbedtls_md_get_size( md_info ), hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, mbedtls_md_get_size( md_info ), hex_hash_string->len ) == 0 ); } /* END_CASE */ /* BEGIN_CASE */ -void md_hex( char * text_md_name, uint8_t * src_str, uint32_t src_len, - uint8_t * hex_hash_string, uint32_t hex_hash_string_len ) +void md_hex( char * text_md_name, HexParam_t * src_str, + HexParam_t * hex_hash_string ) { char md_name[100]; unsigned char output[100]; @@ -164,17 +164,17 @@ void md_hex( char * text_md_name, uint8_t * src_str, uint32_t src_len, md_info = mbedtls_md_info_from_string( md_name ); TEST_ASSERT( md_info != NULL ); - 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 ) ); - TEST_ASSERT( hexcmp( output, hex_hash_string, - mbedtls_md_get_size( md_info ), hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, + mbedtls_md_get_size( md_info ), hex_hash_string->len ) == 0 ); } /* END_CASE */ /* BEGIN_CASE */ void md_text_multi( char * text_md_name, char * text_src_string, - uint8_t * hex_hash_string, uint32_t hex_hash_string_len ) + HexParam_t * hex_hash_string ) { char md_name[100]; unsigned char src_str[1000]; @@ -208,15 +208,15 @@ 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 ) ); - TEST_ASSERT( hexcmp( output, hex_hash_string, - mbedtls_md_get_size( md_info ), hex_hash_string_len) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, + mbedtls_md_get_size( md_info ), hex_hash_string->len) == 0 ); /* Test clone */ 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 ) ); - TEST_ASSERT( hexcmp( output, hex_hash_string, mbedtls_md_get_size( md_info ), hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, mbedtls_md_get_size( md_info ), hex_hash_string->len ) == 0 ); exit: mbedtls_md_free( &ctx ); @@ -225,8 +225,8 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void md_hex_multi( char * text_md_name, uint8_t * src_str, uint32_t src_len, - uint8_t * hex_hash_string, uint32_t hex_hash_string_len ) +void md_hex_multi( char * text_md_name, HexParam_t * src_str, + HexParam_t * hex_hash_string ) { char md_name[100]; unsigned char output[100]; @@ -246,23 +246,23 @@ void md_hex_multi( char * text_md_name, uint8_t * src_str, uint32_t src_len, TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx, md_info, 0 ) ); TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx_copy, md_info, 0 ) ); - 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 ) ); - TEST_ASSERT( hexcmp( output, hex_hash_string, mbedtls_md_get_size( md_info ), hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, mbedtls_md_get_size( md_info ), hex_hash_string->len ) == 0 ); /* Test clone */ 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 ) ); - TEST_ASSERT( hexcmp( output, hex_hash_string, mbedtls_md_get_size( md_info ), hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, mbedtls_md_get_size( md_info ), hex_hash_string->len ) == 0 ); exit: mbedtls_md_free( &ctx ); @@ -271,9 +271,9 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_md_hmac( char * text_md_name, int trunc_size, uint8_t * key_str, - uint32_t key_len, uint8_t * src_str, uint32_t src_len, - uint8_t * hex_hash_string, uint32_t hex_hash_string_len ) +void mbedtls_md_hmac( char * text_md_name, int trunc_size, + HexParam_t * key_str, HexParam_t * src_str, + HexParam_t * hex_hash_string ) { char md_name[100]; unsigned char output[100]; @@ -287,16 +287,15 @@ void mbedtls_md_hmac( char * text_md_name, int trunc_size, uint8_t * key_str, TEST_ASSERT( md_info != NULL ); - TEST_ASSERT ( mbedtls_md_hmac( md_info, key_str, key_len, src_str, src_len, output ) == 0 ); + TEST_ASSERT ( mbedtls_md_hmac( md_info, key_str->x, key_str->len, src_str->x, src_str->len, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_hash_string, trunc_size, hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, trunc_size, hex_hash_string->len ) == 0 ); } /* END_CASE */ /* BEGIN_CASE */ -void md_hmac_multi( char * text_md_name, int trunc_size, uint8_t * key_str, - uint32_t key_len, uint8_t * src_str, uint32_t src_len, - uint8_t * hex_hash_string, uint32_t hex_hash_string_len ) +void md_hmac_multi( char * text_md_name, int trunc_size, HexParam_t * key_str, + HexParam_t * src_str, HexParam_t * hex_hash_string ) { char md_name[100]; unsigned char output[100]; @@ -314,25 +313,25 @@ void md_hmac_multi( char * text_md_name, int trunc_size, uint8_t * key_str, TEST_ASSERT( md_info != NULL ); TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx, md_info, 1 ) ); - 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 ) ); - TEST_ASSERT( hexcmp( output, hex_hash_string, trunc_size, hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, trunc_size, hex_hash_string->len ) == 0 ); /* Test again, for reset() */ 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 ) ); - TEST_ASSERT( hexcmp( output, hex_hash_string, trunc_size, hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, trunc_size, hex_hash_string->len ) == 0 ); exit: mbedtls_md_free( &ctx ); @@ -341,8 +340,7 @@ exit: /* BEGIN_CASE depends_on:MBEDTLS_FS_IO */ void mbedtls_md_file( char * text_md_name, char * filename, - uint8_t * hex_hash_string, uint32_t hex_hash_string_len - ) + HexParam_t * hex_hash_string ) { char md_name[100]; unsigned char output[100]; @@ -357,6 +355,6 @@ void mbedtls_md_file( char * text_md_name, char * filename, TEST_ASSERT( mbedtls_md_file( md_info, filename, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_hash_string, mbedtls_md_get_size( md_info ), hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, mbedtls_md_get_size( md_info ), hex_hash_string->len ) == 0 ); } /* END_CASE */ diff --git a/tests/suites/test_suite_mdx.function b/tests/suites/test_suite_mdx.function index 7fe5e06f7..ddfe3697b 100644 --- a/tests/suites/test_suite_mdx.function +++ b/tests/suites/test_suite_mdx.function @@ -6,8 +6,7 @@ /* END_HEADER */ /* BEGIN_CASE depends_on:MBEDTLS_MD2_C */ -void md2_text( char * text_src_string, uint8_t * hex_hash_string, - uint32_t hex_hash_string_len ) +void md2_text( char * text_src_string, HexParam_t * hex_hash_string ) { int ret; unsigned char src_str[100]; @@ -21,13 +20,12 @@ void md2_text( char * text_src_string, uint8_t * hex_hash_string, ret = mbedtls_md2_ret( src_str, strlen( (char *) src_str ), output ); TEST_ASSERT( ret == 0 ) ; - TEST_ASSERT( hexcmp( output, hex_hash_string, sizeof output, hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, sizeof output, hex_hash_string->len ) == 0 ); } /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_MD4_C */ -void md4_text( char * text_src_string, uint8_t * hex_hash_string, - uint32_t hex_hash_string_len ) +void md4_text( char * text_src_string, HexParam_t * hex_hash_string ) { int ret; unsigned char src_str[100]; @@ -41,13 +39,12 @@ void md4_text( char * text_src_string, uint8_t * hex_hash_string, ret = mbedtls_md4_ret( src_str, strlen( (char *) src_str ), output ); TEST_ASSERT( ret == 0 ); - TEST_ASSERT( hexcmp( output, hex_hash_string, sizeof output, hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, sizeof output, hex_hash_string->len ) == 0 ); } /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_MD5_C */ -void md5_text( char * text_src_string, uint8_t * hex_hash_string, - uint32_t hex_hash_string_len ) +void md5_text( char * text_src_string, HexParam_t * hex_hash_string ) { int ret; unsigned char src_str[100]; @@ -61,13 +58,12 @@ void md5_text( char * text_src_string, uint8_t * hex_hash_string, ret = mbedtls_md5_ret( src_str, strlen( (char *) src_str ), output ); TEST_ASSERT( ret == 0 ); - TEST_ASSERT( hexcmp( output, hex_hash_string, sizeof output, hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, sizeof output, hex_hash_string->len ) == 0 ); } /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C */ -void ripemd160_text( char * text_src_string, uint8_t * hex_hash_string, - uint32_t hex_hash_string_len ) +void ripemd160_text( char * text_src_string, HexParam_t * hex_hash_string ) { int ret; unsigned char src_str[100]; @@ -81,7 +77,7 @@ void ripemd160_text( char * text_src_string, uint8_t * hex_hash_string, ret = mbedtls_ripemd160_ret( src_str, strlen( (char *) src_str ), output ); TEST_ASSERT( ret == 0 ); - TEST_ASSERT( hexcmp( output, hex_hash_string, sizeof output, hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, sizeof output, hex_hash_string->len ) == 0 ); } /* END_CASE */ diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function index da0d5e415..4b7a04859 100644 --- a/tests/suites/test_suite_mpi.function +++ b/tests/suites/test_suite_mpi.function @@ -53,8 +53,7 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_mpi_read_binary( uint8_t * buf, uint32_t input_len, int radix_A, - char * input_A ) +void mbedtls_mpi_read_binary( HexParam_t * buf, int radix_A, char * input_A ) { mbedtls_mpi X; unsigned char str[1000]; @@ -63,7 +62,7 @@ void mbedtls_mpi_read_binary( uint8_t * buf, uint32_t input_len, int radix_A, mbedtls_mpi_init( &X ); - TEST_ASSERT( mbedtls_mpi_read_binary( &X, buf, input_len ) == 0 ); + TEST_ASSERT( mbedtls_mpi_read_binary( &X, buf->x, buf->len ) == 0 ); TEST_ASSERT( mbedtls_mpi_write_string( &X, radix_A, (char *) str, sizeof( str ), &len ) == 0 ); TEST_ASSERT( strcmp( (char *) str, input_A ) == 0 ); @@ -73,8 +72,8 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_mpi_write_binary( int radix_X, char * input_X, uint8_t * input_A, - uint32_t input_A_len, int output_size, +void mbedtls_mpi_write_binary( int radix_X, char * input_X, + HexParam_t * input_A, int output_size, int result ) { mbedtls_mpi X; @@ -95,7 +94,7 @@ void mbedtls_mpi_write_binary( int radix_X, char * input_X, uint8_t * input_A, if( result == 0) { - TEST_ASSERT( hexcmp( buf, input_A, buflen, input_A_len ) == 0 ); + TEST_ASSERT( hexcmp( buf, input_A->x, buflen, input_A->len ) == 0 ); } exit: @@ -104,8 +103,8 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_FS_IO */ -void mbedtls_mpi_read_file( int radix_X, char * input_file, uint8_t * input_A, - uint32_t input_A_len, int result ) +void mbedtls_mpi_read_file( int radix_X, char * input_file, + HexParam_t * input_A, int result ) { mbedtls_mpi X; unsigned char buf[1000]; @@ -129,7 +128,7 @@ void mbedtls_mpi_read_file( int radix_X, char * input_file, uint8_t * input_A, TEST_ASSERT( mbedtls_mpi_write_binary( &X, buf, buflen ) == 0 ); - TEST_ASSERT( hexcmp( buf, input_A, buflen, input_A_len ) == 0 ); + TEST_ASSERT( hexcmp( buf, input_A->x, buflen, input_A->len ) == 0 ); } exit: diff --git a/tests/suites/test_suite_pem.function b/tests/suites/test_suite_pem.function index 222d581c0..dcd53d653 100644 --- a/tests/suites/test_suite_pem.function +++ b/tests/suites/test_suite_pem.function @@ -6,21 +6,21 @@ /* END_HEADER */ /* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C */ -void mbedtls_pem_write_buffer( char * start, char * end, uint8_t * buf, - uint32_t buf_len, char * result_str ) +void mbedtls_pem_write_buffer( char * start, char * end, HexParam_t * buf, + char * result_str ) { unsigned char *check_buf = NULL; int ret; size_t olen = 0, olen2 = 0; - ret = mbedtls_pem_write_buffer( start, end, buf, buf_len, NULL, 0, &olen ); + ret = mbedtls_pem_write_buffer( start, end, buf->x, buf->len, NULL, 0, &olen ); TEST_ASSERT( ret == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ); check_buf = (unsigned char *) mbedtls_calloc( 1, olen ); TEST_ASSERT( check_buf != NULL ); - ret = mbedtls_pem_write_buffer( start, end, buf, buf_len, check_buf, olen, &olen2 ); + ret = mbedtls_pem_write_buffer( start, end, buf->x, buf->len, check_buf, olen, &olen2 ); TEST_ASSERT( olen2 <= olen ); TEST_ASSERT( olen > strlen( (char*) result_str ) ); diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function index 4219c9d8d..23e3a69e2 100644 --- a/tests/suites/test_suite_pk.function +++ b/tests/suites/test_suite_pk.function @@ -121,10 +121,9 @@ void mbedtls_pk_check_pair( char * pub_file, char * prv_file, int ret ) /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_RSA_C */ -void pk_rsa_verify_test_vec( uint8_t * message_str, uint32_t msg_len, - int digest, int mod, int radix_N, char * input_N, - int radix_E, char * input_E, - uint8_t * result_str, uint32_t result_str_len, +void pk_rsa_verify_test_vec( HexParam_t * message_str, int digest, int mod, + int radix_N, char * input_N, int radix_E, + char * input_E, HexParam_t * result_str, int result ) { unsigned char hash_result[1000]; @@ -144,10 +143,10 @@ void pk_rsa_verify_test_vec( uint8_t * message_str, uint32_t msg_len, if( mbedtls_md_info_from_type( digest ) != NULL ) - TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str, msg_len, hash_result ) == 0 ); + TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str->x, message_str->len, hash_result ) == 0 ); TEST_ASSERT( mbedtls_pk_verify( &pk, digest, hash_result, 0, - result_str, mbedtls_pk_get_len( &pk ) ) == result ); + result_str->x, mbedtls_pk_get_len( &pk ) ) == result ); exit: mbedtls_pk_free( &pk ); @@ -155,11 +154,10 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_RSA_C */ -void pk_rsa_verify_ext_test_vec( uint8_t * message_str, uint32_t msg_len, - int digest, int mod, int radix_N, - char * input_N, int radix_E, char * input_E, - uint8_t * result_str, - uint32_t result_str_len, int pk_type, +void pk_rsa_verify_ext_test_vec( HexParam_t * message_str, int digest, + int mod, int radix_N, char * input_N, + int radix_E, char * input_E, + HexParam_t * result_str, int pk_type, int mgf1_hash_id, int salt_len, int result ) { unsigned char hash_result[1000]; @@ -184,13 +182,13 @@ void pk_rsa_verify_ext_test_vec( uint8_t * message_str, uint32_t msg_len, if( digest != MBEDTLS_MD_NONE ) { TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), - message_str, msg_len, hash_result ) == 0 ); + message_str->x, message_str->len, hash_result ) == 0 ); hash_len = 0; } else { - memcpy( hash_result, message_str, msg_len ); - hash_len = msg_len; + memcpy( hash_result, message_str->x, message_str->len ); + hash_len = message_str->len; } if( mgf1_hash_id < 0 ) @@ -207,7 +205,7 @@ void pk_rsa_verify_ext_test_vec( uint8_t * message_str, uint32_t msg_len, TEST_ASSERT( mbedtls_pk_verify_ext( pk_type, options, &pk, digest, hash_result, hash_len, - result_str, mbedtls_pk_get_len( &pk ) ) == result ); + result_str->x, mbedtls_pk_get_len( &pk ) ) == result ); exit: mbedtls_pk_free( &pk ); @@ -215,9 +213,8 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_ECDSA_C */ -void pk_ec_test_vec( int type, int id, uint8_t * key, uint32_t key_len, - uint8_t * hash, uint32_t hash_len, uint8_t * sig, - uint32_t sig_len, int ret ) +void pk_ec_test_vec( int type, int id, HexParam_t * key, HexParam_t * hash, + HexParam_t * sig, int ret ) { mbedtls_pk_context pk; mbedtls_ecp_keypair *eckey; @@ -232,10 +229,10 @@ void pk_ec_test_vec( int type, int id, uint8_t * key, uint32_t key_len, TEST_ASSERT( mbedtls_ecp_group_load( &eckey->grp, id ) == 0 ); TEST_ASSERT( mbedtls_ecp_point_read_binary( &eckey->grp, &eckey->Q, - key, key_len ) == 0 ); + key->x, key->len ) == 0 ); TEST_ASSERT( mbedtls_pk_verify( &pk, MBEDTLS_MD_NONE, - hash, hash_len, sig, sig_len ) == ret ); + hash->x, hash->len, sig->x, sig->len ) == ret ); exit: mbedtls_pk_free( &pk ); @@ -269,10 +266,9 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_RSA_C */ -void pk_rsa_encrypt_test_vec( uint8_t * message, uint32_t msg_len, int mod, - int radix_N, char * input_N, int radix_E, - char * input_E, uint8_t * result, - uint32_t res_len, int ret ) +void pk_rsa_encrypt_test_vec( HexParam_t * message, int mod, int radix_N, + char * input_N, int radix_E, char * input_E, + HexParam_t * result, int ret ) { unsigned char output[1000]; rnd_pseudo_info rnd_info; @@ -292,11 +288,11 @@ void pk_rsa_encrypt_test_vec( uint8_t * message, uint32_t msg_len, int mod, TEST_ASSERT( mbedtls_mpi_read_string( &rsa->N, radix_N, input_N ) == 0 ); TEST_ASSERT( mbedtls_mpi_read_string( &rsa->E, radix_E, input_E ) == 0 ); - TEST_ASSERT( mbedtls_pk_encrypt( &pk, message, msg_len, + TEST_ASSERT( mbedtls_pk_encrypt( &pk, message->x, message->len, output, &olen, sizeof( output ), rnd_pseudo_rand, &rnd_info ) == ret ); - TEST_ASSERT( olen == res_len ); - TEST_ASSERT( memcmp( output, result, olen ) == 0 ); + TEST_ASSERT( olen == result->len ); + TEST_ASSERT( memcmp( output, result->x, olen ) == 0 ); exit: mbedtls_pk_free( &pk ); @@ -304,11 +300,10 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_RSA_C */ -void pk_rsa_decrypt_test_vec( uint8_t * cipher, uint32_t cipher_len, int mod, - int radix_P, char * input_P, int radix_Q, - char * input_Q, int radix_N, char * input_N, - int radix_E, char * input_E, uint8_t * clear, - uint32_t clear_len, int ret ) +void pk_rsa_decrypt_test_vec( HexParam_t * cipher, int mod, int radix_P, + char * input_P, int radix_Q, char * input_Q, + int radix_N, char * input_N, int radix_E, + char * input_E, HexParam_t * clear, int ret ) { unsigned char output[1000]; rnd_pseudo_info rnd_info; @@ -342,13 +337,13 @@ void pk_rsa_decrypt_test_vec( uint8_t * cipher, uint32_t cipher_len, int mod, /* decryption test */ memset( output, 0, sizeof( output ) ); olen = 0; - TEST_ASSERT( mbedtls_pk_decrypt( &pk, cipher, cipher_len, + TEST_ASSERT( mbedtls_pk_decrypt( &pk, cipher->x, cipher->len, output, &olen, sizeof( output ), rnd_pseudo_rand, &rnd_info ) == ret ); if( ret == 0 ) { - TEST_ASSERT( olen == clear_len ); - TEST_ASSERT( memcmp( output, clear, olen ) == 0 ); + TEST_ASSERT( olen == clear->len ); + TEST_ASSERT( memcmp( output, clear->x, olen ) == 0 ); } exit: diff --git a/tests/suites/test_suite_pkcs1_v15.function b/tests/suites/test_suite_pkcs1_v15.function index 7b57bee53..9cf3b1934 100644 --- a/tests/suites/test_suite_pkcs1_v15.function +++ b/tests/suites/test_suite_pkcs1_v15.function @@ -11,18 +11,16 @@ /* BEGIN_CASE */ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char * input_N, int radix_E, char * input_E, int hash, - uint8_t * message_str, uint32_t msg_len, - uint8_t * rnd_buf, uint32_t rnd_buf_len, - uint8_t * result_hex_str, - uint32_t result_hex_str_len, int result ) + HexParam_t * message_str, HexParam_t * rnd_buf, + HexParam_t * result_hex_str, int result ) { unsigned char output[1000]; mbedtls_rsa_context ctx; rnd_buf_info info; mbedtls_mpi N, E; - info.buf = rnd_buf; - info.length = rnd_buf_len; + info.buf = rnd_buf->x; + info.length = rnd_buf->len; mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E ); mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash ); @@ -35,11 +33,11 @@ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char * input_N, TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 ); - TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_buffer_rand, &info, MBEDTLS_RSA_PUBLIC, msg_len, message_str, output ) == result ); + TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_buffer_rand, &info, MBEDTLS_RSA_PUBLIC, message_str->len, message_str->x, output ) == result ); if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, ctx.len, result_hex_str->len ) == 0 ); } exit: @@ -52,8 +50,8 @@ exit: void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char * input_P, int radix_Q, char * input_Q, int radix_N, char * input_N, int radix_E, char * input_E, - int hash, uint8_t * result_hex_str, uint32_t result_hex_str_len, - char * seed, uint8_t * message_str, uint32_t message_str_len, + int hash, HexParam_t * result_hex_str, + char * seed, HexParam_t * message_str, int result ) { unsigned char output[1000]; @@ -81,11 +79,11 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char * input_P, TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 ); - TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str, output, 1000 ) == result ); + TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str->x, output, 1000 ) == result ); if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, output_len, result_hex_str_len) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, output_len, result_hex_str->len) == 0 ); } exit: @@ -99,10 +97,8 @@ exit: void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q, char * input_Q, int radix_N, char * input_N, int radix_E, char * input_E, int digest, int hash, - uint8_t * message_str, uint32_t msg_len, - uint8_t * rnd_buf, uint32_t rnd_buf_len, - uint8_t * result_hex_str, - uint32_t result_hex_str_len, int result ) + HexParam_t * message_str, HexParam_t * rnd_buf, + HexParam_t * result_hex_str, int result ) { unsigned char hash_result[1000]; unsigned char output[1000]; @@ -110,8 +106,8 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q, mbedtls_mpi N, P, Q, E; rnd_buf_info info; - info.buf = rnd_buf; - info.length = rnd_buf_len; + info.buf = rnd_buf->x; + info.length = rnd_buf->len; mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E ); @@ -132,13 +128,13 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q, if( mbedtls_md_info_from_type( digest ) != NULL ) - TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str, msg_len, hash_result ) == 0 ); + TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str->x, message_str->len, hash_result ) == 0 ); TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &rnd_buffer_rand, &info, MBEDTLS_RSA_PRIVATE, digest, 0, hash_result, output ) == result ); if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, ctx.len, result_hex_str->len ) == 0 ); } exit: @@ -151,10 +147,8 @@ exit: /* BEGIN_CASE */ void pkcs1_rsassa_v15_verify( int mod, int radix_N, char * input_N, int radix_E, char * input_E, int digest, - int hash, uint8_t * message_str, - uint32_t msg_len, char * salt, - uint8_t * result_str, uint32_t result_str_len, - int result ) + int hash, HexParam_t * message_str, char * salt, + HexParam_t * result_str, int result ) { unsigned char hash_result[1000]; mbedtls_rsa_context ctx; @@ -173,12 +167,9 @@ void pkcs1_rsassa_v15_verify( int mod, int radix_N, char * input_N, if( mbedtls_md_info_from_type( digest ) != NULL ) - TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), - message_str, msg_len, hash_result ) == 0 ); + TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str->x, message_str->len, hash_result ) == 0 ); - TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, - digest, 0, hash_result, - result_str ) == result ); + TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, digest, 0, hash_result, result_str->x ) == result ); exit: mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E ); diff --git a/tests/suites/test_suite_pkcs1_v21.function b/tests/suites/test_suite_pkcs1_v21.function index 4ebeca927..dd408863f 100644 --- a/tests/suites/test_suite_pkcs1_v21.function +++ b/tests/suites/test_suite_pkcs1_v21.function @@ -11,18 +11,16 @@ /* BEGIN_CASE */ void pkcs1_rsaes_oaep_encrypt( int mod, int radix_N, char * input_N, int radix_E, char * input_E, int hash, - uint8_t * message_str, uint32_t msg_len, - uint8_t * rnd_buf, uint32_t rnd_buf_len, - uint8_t * result_hex_str, - uint32_t result_hex_str_len, int result ) + HexParam_t * message_str, HexParam_t * rnd_buf, + HexParam_t * result_hex_str, int result ) { unsigned char output[1000]; mbedtls_rsa_context ctx; rnd_buf_info info; mbedtls_mpi N, E; - info.buf = rnd_buf; - info.length = rnd_buf_len; + info.buf = rnd_buf->x; + info.length = rnd_buf->len; mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E ); mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash ); @@ -35,11 +33,11 @@ void pkcs1_rsaes_oaep_encrypt( int mod, int radix_N, char * input_N, TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 ); - TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_buffer_rand, &info, MBEDTLS_RSA_PUBLIC, msg_len, message_str, output ) == result ); + TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_buffer_rand, &info, MBEDTLS_RSA_PUBLIC, message_str->len, message_str->x, output ) == result ); if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, ctx.len, result_hex_str->len ) == 0 ); } exit: @@ -52,10 +50,9 @@ exit: void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char * input_P, int radix_Q, char * input_Q, int radix_N, char * input_N, int radix_E, char * input_E, - int hash, uint8_t * result_hex_str, - uint32_t result_hex_str_len, char * seed, - uint8_t * message_str, - uint32_t message_str_len, int result ) + int hash, HexParam_t * result_hex_str, + char * seed, HexParam_t * message_str, + int result ) { unsigned char output[1000]; mbedtls_rsa_context ctx; @@ -83,11 +80,11 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char * input_P, TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 ); - TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str, output, 1000 ) == result ); + TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str->x, output, 1000 ) == result ); if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, output_len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, output_len, result_hex_str->len ) == 0 ); } exit: @@ -101,10 +98,8 @@ exit: void pkcs1_rsassa_pss_sign( int mod, int radix_P, char * input_P, int radix_Q, char * input_Q, int radix_N, char * input_N, int radix_E, char * input_E, int digest, int hash, - uint8_t * message_str, uint32_t msg_len, - uint8_t * rnd_buf, uint32_t rnd_buf_len, - uint8_t * result_hex_str, - uint32_t result_hex_str_len, int result ) + HexParam_t * message_str, HexParam_t * rnd_buf, + HexParam_t * result_hex_str, int result ) { unsigned char hash_result[1000]; unsigned char output[1000]; @@ -112,8 +107,8 @@ void pkcs1_rsassa_pss_sign( int mod, int radix_P, char * input_P, int radix_Q, rnd_buf_info info; mbedtls_mpi N, P, Q, E; - info.buf = rnd_buf; - info.length = rnd_buf_len; + info.buf = rnd_buf->x; + info.length = rnd_buf->len; mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E ); @@ -134,15 +129,14 @@ void pkcs1_rsassa_pss_sign( int mod, int radix_P, char * input_P, int radix_Q, if( mbedtls_md_info_from_type( digest ) != NULL ) - TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str, - msg_len, hash_result ) == 0 ); + TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str->x, message_str->len, hash_result ) == 0 ); TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &rnd_buffer_rand, &info, MBEDTLS_RSA_PRIVATE, digest, 0, hash_result, output ) == result ); if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, ctx.len, result_hex_str->len ) == 0 ); } exit: @@ -155,10 +149,8 @@ exit: /* BEGIN_CASE */ void pkcs1_rsassa_pss_verify( int mod, int radix_N, char * input_N, int radix_E, char * input_E, int digest, - int hash, uint8_t * message_str, - uint32_t msg_len, char * salt, - uint8_t * result_str, uint32_t result_str_len, - int result ) + int hash, HexParam_t * message_str, char * salt, + HexParam_t * result_str, int result ) { unsigned char hash_result[1000]; mbedtls_rsa_context ctx; @@ -178,11 +170,9 @@ void pkcs1_rsassa_pss_verify( int mod, int radix_N, char * input_N, if( mbedtls_md_info_from_type( digest ) != NULL ) - TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str, - msg_len, hash_result ) == 0 ); + TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str->x, message_str->len, hash_result ) == 0 ); - TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, - digest, 0, hash_result, result_str ) == result ); + TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, digest, 0, hash_result, result_str->x ) == result ); exit: mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E ); @@ -195,9 +185,8 @@ void pkcs1_rsassa_pss_verify_ext( int mod, int radix_N, char * input_N, int radix_E, char * input_E, int msg_digest_id, int ctx_hash, int mgf_hash, int salt_len, - uint8_t * message_str, uint32_t msg_len, - uint8_t * result_str, - uint32_t result_str_len, int result_simple, + HexParam_t * message_str, + HexParam_t * result_str, int result_simple, int result_full ) { unsigned char hash_result[1000]; @@ -220,23 +209,23 @@ void pkcs1_rsassa_pss_verify_ext( int mod, int radix_N, char * input_N, if( msg_digest_id != MBEDTLS_MD_NONE ) { TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( msg_digest_id ), - message_str, msg_len, hash_result ) == 0 ); + message_str->x, message_str->len, hash_result ) == 0 ); hash_len = 0; } else { - memcpy( hash_result, message_str, msg_len ); - hash_len = msg_len; + memcpy( hash_result, message_str->x, message_str->len ); + hash_len = message_str->len; } TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, msg_digest_id, hash_len, hash_result, - result_str ) == result_simple ); + result_str->x ) == result_simple ); TEST_ASSERT( mbedtls_rsa_rsassa_pss_verify_ext( &ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, msg_digest_id, hash_len, hash_result, mgf_hash, salt_len, - result_str ) == result_full ); + result_str->x ) == result_full ); exit: mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E ); diff --git a/tests/suites/test_suite_pkcs5.function b/tests/suites/test_suite_pkcs5.function index 29e87cbfe..0dcbb0a46 100644 --- a/tests/suites/test_suite_pkcs5.function +++ b/tests/suites/test_suite_pkcs5.function @@ -8,10 +8,8 @@ */ /* BEGIN_CASE */ -void pbkdf2_hmac( int hash, uint8_t * pw_str, uint32_t pw_len, - uint8_t * salt_str, uint32_t salt_len, int it_cnt, - int key_len, uint8_t * result_key_string, - uint32_t result_key_string_len ) +void pbkdf2_hmac( int hash, HexParam_t * pw_str, HexParam_t * salt_str, + int it_cnt, int key_len, HexParam_t * result_key_string ) { mbedtls_md_context_t ctx; const mbedtls_md_info_t *info; @@ -23,10 +21,10 @@ void pbkdf2_hmac( int hash, uint8_t * pw_str, uint32_t pw_len, info = mbedtls_md_info_from_type( hash ); TEST_ASSERT( info != NULL ); TEST_ASSERT( mbedtls_md_setup( &ctx, info, 1 ) == 0 ); - TEST_ASSERT( mbedtls_pkcs5_pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len, + TEST_ASSERT( mbedtls_pkcs5_pbkdf2_hmac( &ctx, pw_str->x, pw_str->len, salt_str->x, salt_str->len, it_cnt, key_len, key ) == 0 ); - TEST_ASSERT( hexcmp( key, result_key_string, key_len, result_key_string_len ) == 0 ); + TEST_ASSERT( hexcmp( key, result_key_string->x, key_len, result_key_string->len ) == 0 ); exit: mbedtls_md_free( &ctx ); @@ -34,34 +32,27 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_ASN1_PARSE_C */ -void mbedtls_pkcs5_pbes2( int params_tag, char *params_hex, char *pw_hex, - char *data_hex, int ref_ret, char *ref_out_hex ) +void mbedtls_pkcs5_pbes2( int params_tag, HexParam_t *params_hex, HexParam_t *pw, + HexParam_t *data, int ref_ret, HexParam_t *ref_out ) { int my_ret; mbedtls_asn1_buf params; - unsigned char *my_out = NULL, *ref_out = NULL, *data = NULL, *pw = NULL; - size_t ref_out_len, data_len, pw_len; + unsigned char *my_out = NULL; params.tag = params_tag; - params.p = unhexify_alloc( params_hex, ¶ms.len ); + params.p = params_hex->x; + params.len = params_hex->len; - data = unhexify_alloc( data_hex, &data_len ); - pw = unhexify_alloc( pw_hex, &pw_len ); - ref_out = unhexify_alloc( ref_out_hex, &ref_out_len ); - my_out = zero_alloc( ref_out_len ); + my_out = zero_alloc( ref_out->len ); my_ret = mbedtls_pkcs5_pbes2( ¶ms, MBEDTLS_PKCS5_DECRYPT, - pw, pw_len, data, data_len, my_out ); + pw->x, pw->len, data->x, data->len, my_out ); TEST_ASSERT( my_ret == ref_ret ); if( ref_ret == 0 ) - TEST_ASSERT( memcmp( my_out, ref_out, ref_out_len ) == 0 ); + TEST_ASSERT( memcmp( my_out, ref_out->x, ref_out->len ) == 0 ); exit: - mbedtls_free( params.p ); - mbedtls_free( data ); - mbedtls_free( pw ); - mbedtls_free( ref_out ); mbedtls_free( my_out ); } /* END_CASE */ diff --git a/tests/suites/test_suite_pkparse.function b/tests/suites/test_suite_pkparse.function index 860730569..920f9369b 100644 --- a/tests/suites/test_suite_pkparse.function +++ b/tests/suites/test_suite_pkparse.function @@ -114,8 +114,7 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_RSA_C */ -void pk_parse_key( uint8_t * buf, uint32_t data_len, char * result_str, - int result ) +void pk_parse_key( HexParam_t * buf, char * result_str, int result ) { mbedtls_pk_context pk; unsigned char output[2000]; @@ -126,7 +125,7 @@ void pk_parse_key( uint8_t * buf, uint32_t data_len, char * result_str, memset( output, 0, 2000 ); - TEST_ASSERT( mbedtls_pk_parse_key( &pk, buf, data_len, NULL, 0 ) == ( result ) ); + TEST_ASSERT( mbedtls_pk_parse_key( &pk, buf->x, buf->len, NULL, 0 ) == ( result ) ); if( ( result ) == 0 ) { TEST_ASSERT( 1 ); diff --git a/tests/suites/test_suite_rsa.data b/tests/suites/test_suite_rsa.data index bfaae6c65..e49515165 100644 --- a/tests/suites/test_suite_rsa.data +++ b/tests/suites/test_suite_rsa.data @@ -237,15 +237,15 @@ mbedtls_rsa_pkcs1_verify:"59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e9 RSA PKCS1 Sign #8 (RAW, 2048 bits RSA) depends_on:MBEDTLS_PKCS1_V15 -rsa_pkcs1_sign_raw:"59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870":"1234567890deadbeef":MBEDTLS_RSA_PKCS_V15:2048:16:"e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17":16:"c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89":16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"605baf947c0de49e4f6a0dfb94a43ae318d5df8ed20ba4ba5a37a73fb009c5c9e5cce8b70a25b1c7580f389f0d7092485cdfa02208b70d33482edf07a7eafebdc54862ca0e0396a5a7d09991b9753eb1ffb6091971bb5789c6b121abbcd0a3cbaa39969fa7c28146fce96c6d03272e3793e5be8f5abfa9afcbebb986d7b3050604a2af4d3a40fa6c003781a539a60259d1e84f13322da9e538a49c369b83e7286bf7d30b64bbb773506705da5d5d5483a563a1ffacc902fb75c9a751b1e83cdc7a6db0470056883f48b5a5446b43b1d180ea12ba11a6a8d93b3b32a30156b6084b7fb142998a2a0d28014b84098ece7d9d5e4d55cc342ca26f5a0167a679dec8" +rsa_pkcs1_sign_raw:"1234567890deadbeef":MBEDTLS_RSA_PKCS_V15:2048:16:"e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17":16:"c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89":16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"605baf947c0de49e4f6a0dfb94a43ae318d5df8ed20ba4ba5a37a73fb009c5c9e5cce8b70a25b1c7580f389f0d7092485cdfa02208b70d33482edf07a7eafebdc54862ca0e0396a5a7d09991b9753eb1ffb6091971bb5789c6b121abbcd0a3cbaa39969fa7c28146fce96c6d03272e3793e5be8f5abfa9afcbebb986d7b3050604a2af4d3a40fa6c003781a539a60259d1e84f13322da9e538a49c369b83e7286bf7d30b64bbb773506705da5d5d5483a563a1ffacc902fb75c9a751b1e83cdc7a6db0470056883f48b5a5446b43b1d180ea12ba11a6a8d93b3b32a30156b6084b7fb142998a2a0d28014b84098ece7d9d5e4d55cc342ca26f5a0167a679dec8" RSA PKCS1 Sign #8 Verify depends_on:MBEDTLS_PKCS1_V15 -rsa_pkcs1_verify_raw:"59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870":"1234567890deadbeef":MBEDTLS_RSA_PKCS_V15:2048:16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"605baf947c0de49e4f6a0dfb94a43ae318d5df8ed20ba4ba5a37a73fb009c5c9e5cce8b70a25b1c7580f389f0d7092485cdfa02208b70d33482edf07a7eafebdc54862ca0e0396a5a7d09991b9753eb1ffb6091971bb5789c6b121abbcd0a3cbaa39969fa7c28146fce96c6d03272e3793e5be8f5abfa9afcbebb986d7b3050604a2af4d3a40fa6c003781a539a60259d1e84f13322da9e538a49c369b83e7286bf7d30b64bbb773506705da5d5d5483a563a1ffacc902fb75c9a751b1e83cdc7a6db0470056883f48b5a5446b43b1d180ea12ba11a6a8d93b3b32a30156b6084b7fb142998a2a0d28014b84098ece7d9d5e4d55cc342ca26f5a0167a679dec8":0 +rsa_pkcs1_verify_raw:"1234567890deadbeef":MBEDTLS_RSA_PKCS_V15:2048:16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"605baf947c0de49e4f6a0dfb94a43ae318d5df8ed20ba4ba5a37a73fb009c5c9e5cce8b70a25b1c7580f389f0d7092485cdfa02208b70d33482edf07a7eafebdc54862ca0e0396a5a7d09991b9753eb1ffb6091971bb5789c6b121abbcd0a3cbaa39969fa7c28146fce96c6d03272e3793e5be8f5abfa9afcbebb986d7b3050604a2af4d3a40fa6c003781a539a60259d1e84f13322da9e538a49c369b83e7286bf7d30b64bbb773506705da5d5d5483a563a1ffacc902fb75c9a751b1e83cdc7a6db0470056883f48b5a5446b43b1d180ea12ba11a6a8d93b3b32a30156b6084b7fb142998a2a0d28014b84098ece7d9d5e4d55cc342ca26f5a0167a679dec8":0 RSA PKCS1 Sign #8 Verify (Wrong raw hash) depends_on:MBEDTLS_PKCS1_V15 -rsa_pkcs1_verify_raw:"59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870":"1234567890deadcafe":MBEDTLS_RSA_PKCS_V15:2048:16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"605baf947c0de49e4f6a0dfb94a43ae318d5df8ed20ba4ba5a37a73fb009c5c9e5cce8b70a25b1c7580f389f0d7092485cdfa02208b70d33482edf07a7eafebdc54862ca0e0396a5a7d09991b9753eb1ffb6091971bb5789c6b121abbcd0a3cbaa39969fa7c28146fce96c6d03272e3793e5be8f5abfa9afcbebb986d7b3050604a2af4d3a40fa6c003781a539a60259d1e84f13322da9e538a49c369b83e7286bf7d30b64bbb773506705da5d5d5483a563a1ffacc902fb75c9a751b1e83cdc7a6db0470056883f48b5a5446b43b1d180ea12ba11a6a8d93b3b32a30156b6084b7fb142998a2a0d28014b84098ece7d9d5e4d55cc342ca26f5a0167a679dec8":MBEDTLS_ERR_RSA_VERIFY_FAILED +rsa_pkcs1_verify_raw:"1234567890deadcafe":MBEDTLS_RSA_PKCS_V15:2048:16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"605baf947c0de49e4f6a0dfb94a43ae318d5df8ed20ba4ba5a37a73fb009c5c9e5cce8b70a25b1c7580f389f0d7092485cdfa02208b70d33482edf07a7eafebdc54862ca0e0396a5a7d09991b9753eb1ffb6091971bb5789c6b121abbcd0a3cbaa39969fa7c28146fce96c6d03272e3793e5be8f5abfa9afcbebb986d7b3050604a2af4d3a40fa6c003781a539a60259d1e84f13322da9e538a49c369b83e7286bf7d30b64bbb773506705da5d5d5483a563a1ffacc902fb75c9a751b1e83cdc7a6db0470056883f48b5a5446b43b1d180ea12ba11a6a8d93b3b32a30156b6084b7fb142998a2a0d28014b84098ece7d9d5e4d55cc342ca26f5a0167a679dec8":MBEDTLS_ERR_RSA_VERIFY_FAILED RSA PKCS1 Sign #9 (Invalid Digest type) depends_on:MBEDTLS_PKCS1_V15 diff --git a/tests/suites/test_suite_rsa.function b/tests/suites/test_suite_rsa.function index 8c9e8fde6..83f735321 100644 --- a/tests/suites/test_suite_rsa.function +++ b/tests/suites/test_suite_rsa.function @@ -18,13 +18,11 @@ */ /* BEGIN_CASE */ -void mbedtls_rsa_pkcs1_sign( uint8_t * message_str, uint32_t msg_len, - int padding_mode, int digest, int mod, - int radix_P, char * input_P, int radix_Q, - char * input_Q, int radix_N, char * input_N, - int radix_E, char * input_E, - uint8_t * result_hex_str, - uint32_t result_hex_str_len, int result ) +void mbedtls_rsa_pkcs1_sign( HexParam_t * message_str, int padding_mode, + int digest, int mod, int radix_P, char * input_P, + int radix_Q, char * input_Q, int radix_N, + char * input_N, int radix_E, char * input_E, + HexParam_t * result_hex_str, int result ) { unsigned char hash_result[1000]; unsigned char output[1000]; @@ -52,8 +50,7 @@ void mbedtls_rsa_pkcs1_sign( uint8_t * message_str, uint32_t msg_len, if( mbedtls_md_info_from_type( digest ) != NULL ) - TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), - message_str, msg_len, hash_result ) == 0 ); + TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str->x, message_str->len, hash_result ) == 0 ); TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, digest, 0, @@ -61,7 +58,7 @@ void mbedtls_rsa_pkcs1_sign( uint8_t * message_str, uint32_t msg_len, if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, ctx.len, result_hex_str->len ) == 0 ); } exit: @@ -72,11 +69,10 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_rsa_pkcs1_verify( uint8_t * message_str, uint32_t msg_len, - int padding_mode, int digest, int mod, - int radix_N, char * input_N, int radix_E, - char * input_E, uint8_t * result_str, - uint32_t result_str_len, int result ) +void mbedtls_rsa_pkcs1_verify( HexParam_t * message_str, int padding_mode, + int digest, int mod, int radix_N, + char * input_N, int radix_E, char * input_E, + HexParam_t * result_str, int result ) { unsigned char hash_result[1000]; mbedtls_rsa_context ctx; @@ -95,9 +91,9 @@ void mbedtls_rsa_pkcs1_verify( uint8_t * message_str, uint32_t msg_len, if( mbedtls_md_info_from_type( digest ) != NULL ) - TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str, msg_len, hash_result ) == 0 ); + TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str->x, message_str->len, hash_result ) == 0 ); - TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, digest, 0, hash_result, result_str ) == result ); + TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, digest, 0, hash_result, result_str->x ) == result ); exit: mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E ); @@ -107,13 +103,11 @@ exit: /* BEGIN_CASE */ -void rsa_pkcs1_sign_raw( uint8_t * message_str, uint32_t message_str_len, - uint8_t * hash_result, uint32_t hash_len, +void rsa_pkcs1_sign_raw( HexParam_t * hash_result, int padding_mode, int mod, int radix_P, char * input_P, int radix_Q, char * input_Q, int radix_N, char * input_N, int radix_E, - char * input_E, uint8_t * result_hex_str, - uint32_t result_hex_str_len ) + char * input_E, HexParam_t * result_hex_str ) { unsigned char output[1000]; mbedtls_rsa_context ctx; @@ -140,10 +134,11 @@ void rsa_pkcs1_sign_raw( uint8_t * message_str, uint32_t message_str_len, TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_NONE, - hash_len, hash_result, output ) == 0 ); + hash_result->len, hash_result->x, + output ) == 0 ); - TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, ctx.len, result_hex_str->len ) == 0 ); #if defined(MBEDTLS_PKCS1_V15) /* For PKCS#1 v1.5, there is an alternative way to generate signatures */ @@ -154,7 +149,7 @@ void rsa_pkcs1_sign_raw( uint8_t * message_str, uint32_t message_str_len, res = mbedtls_rsa_rsaes_pkcs1_v15_encrypt( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, - hash_len, hash_result, output ); + hash_result->len, hash_result->x, output ); #if !defined(MBEDTLS_RSA_ALT) TEST_ASSERT( res == 0 ); @@ -165,7 +160,7 @@ void rsa_pkcs1_sign_raw( uint8_t * message_str, uint32_t message_str_len, if( res == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, ctx.len, result_hex_str->len ) == 0 ); } } #endif /* MBEDTLS_PKCS1_V15 */ @@ -179,12 +174,10 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void rsa_pkcs1_verify_raw( uint8_t * message_str, uint32_t message_str_len, - uint8_t * hash_result, uint32_t hash_len, +void rsa_pkcs1_verify_raw( HexParam_t * hash_result, int padding_mode, int mod, int radix_N, char * input_N, int radix_E, char * input_E, - uint8_t * result_str, uint32_t result_str_len, - int correct ) + HexParam_t * result_str, int correct ) { unsigned char output[1000]; mbedtls_rsa_context ctx; @@ -203,10 +196,7 @@ void rsa_pkcs1_verify_raw( uint8_t * message_str, uint32_t message_str_len, TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 ); - TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, NULL, NULL, - MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_NONE, - hash_len, hash_result, - result_str ) == correct ); + TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_NONE, hash_result->len, hash_result->x, result_str->x ) == correct ); #if defined(MBEDTLS_PKCS1_V15) /* For PKCS#1 v1.5, there is an alternative way to verify signatures */ @@ -218,7 +208,7 @@ void rsa_pkcs1_verify_raw( uint8_t * message_str, uint32_t message_str_len, res = mbedtls_rsa_rsaes_pkcs1_v15_decrypt( &ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, - &olen, result_str, output, sizeof( output ) ); + &olen, result_str->x, output, sizeof( output ) ); #if !defined(MBEDTLS_RSA_ALT) TEST_ASSERT( res == 0 ); @@ -229,7 +219,7 @@ void rsa_pkcs1_verify_raw( uint8_t * message_str, uint32_t message_str_len, if( res == 0 ) { - ok = olen == hash_len && memcmp( output, hash_result, olen ) == 0; + ok = olen == hash_result->len && memcmp( output, hash_result->x, olen ) == 0; if( correct == 0 ) TEST_ASSERT( ok == 1 ); else @@ -245,11 +235,10 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_rsa_pkcs1_encrypt( uint8_t * message_str, uint32_t msg_len, - int padding_mode, int mod, int radix_N, - char * input_N, int radix_E, char * input_E, - uint8_t * result_hex_str, - uint32_t result_hex_str_len, int result ) +void mbedtls_rsa_pkcs1_encrypt( HexParam_t * message_str, int padding_mode, + int mod, int radix_N, char * input_N, + int radix_E, char * input_E, + HexParam_t * result_hex_str, int result ) { unsigned char output[1000]; mbedtls_rsa_context ctx; @@ -272,12 +261,12 @@ void mbedtls_rsa_pkcs1_encrypt( uint8_t * message_str, uint32_t msg_len, TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_pseudo_rand, &rnd_info, - MBEDTLS_RSA_PUBLIC, msg_len, - message_str, output ) == result ); + MBEDTLS_RSA_PUBLIC, message_str->len, + message_str->x, output ) == result ); if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, ctx.len, result_hex_str->len ) == 0 ); } exit: @@ -287,11 +276,10 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void rsa_pkcs1_encrypt_bad_rng( uint8_t * message_str, uint32_t msg_len, - int padding_mode, int mod, int radix_N, - char * input_N, int radix_E, char * input_E, - uint8_t * result_hex_str, - uint32_t result_hex_str_len, int result ) +void rsa_pkcs1_encrypt_bad_rng( HexParam_t * message_str, int padding_mode, + int mod, int radix_N, char * input_N, + int radix_E, char * input_E, + HexParam_t * result_hex_str, int result ) { unsigned char output[1000]; mbedtls_rsa_context ctx; @@ -311,12 +299,12 @@ void rsa_pkcs1_encrypt_bad_rng( uint8_t * message_str, uint32_t msg_len, TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_zero_rand, NULL, - MBEDTLS_RSA_PUBLIC, msg_len, - message_str, output ) == result ); + MBEDTLS_RSA_PUBLIC, message_str->len, + message_str->x, output ) == result ); if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, output_len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, ctx.len, result_hex_str->len ) == 0 ); } exit: @@ -326,13 +314,12 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_rsa_pkcs1_decrypt( uint8_t * message_str, - uint32_t message_str_len, int padding_mode, +void mbedtls_rsa_pkcs1_decrypt( HexParam_t * message_str, int padding_mode, int mod, int radix_P, char * input_P, int radix_Q, char * input_Q, int radix_N, char * input_N, int radix_E, char * input_E, - int max_output, uint8_t * result_hex_str, - uint32_t result_hex_str_len, int result ) + int max_output, HexParam_t * result_hex_str, + int result ) { unsigned char output[1000]; mbedtls_rsa_context ctx; @@ -361,11 +348,11 @@ void mbedtls_rsa_pkcs1_decrypt( uint8_t * message_str, output_len = 0; - TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str, output, max_output ) == result ); + TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str->x, output, max_output ) == result ); if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, output_len, result_hex_str->len ) == 0 ); } exit: @@ -376,10 +363,9 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_rsa_public( uint8_t * message_str, uint32_t message_str_len, - int mod, int radix_N, char * input_N, int radix_E, - char * input_E, uint8_t * result_hex_str, - uint32_t result_hex_str_len, int result ) +void mbedtls_rsa_public( HexParam_t * message_str, int mod, int radix_N, + char * input_N, int radix_E, char * input_E, + HexParam_t * result_hex_str, int result ) { unsigned char output[1000]; mbedtls_rsa_context ctx, ctx2; /* Also test mbedtls_rsa_copy() while at it */ @@ -399,11 +385,11 @@ void mbedtls_rsa_public( uint8_t * message_str, uint32_t message_str_len, TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 ); - TEST_ASSERT( mbedtls_rsa_public( &ctx, message_str, output ) == result ); + TEST_ASSERT( mbedtls_rsa_public( &ctx, message_str->x, output ) == result ); if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, ctx.len, result_hex_str->len ) == 0 ); } /* And now with the copy */ @@ -414,11 +400,11 @@ void mbedtls_rsa_public( uint8_t * message_str, uint32_t message_str_len, TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx2 ) == 0 ); memset( output, 0x00, 1000 ); - TEST_ASSERT( mbedtls_rsa_public( &ctx2, message_str, output ) == result ); + TEST_ASSERT( mbedtls_rsa_public( &ctx2, message_str->x, output ) == result ); if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, ctx.len, result_hex_str->len ) == 0 ); } exit: @@ -429,12 +415,11 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void mbedtls_rsa_private( uint8_t * message_str, uint32_t message_str_len, - int mod, int radix_P, char * input_P, int radix_Q, - char * input_Q, int radix_N, char * input_N, - int radix_E, char * input_E, - uint8_t * result_hex_str, - uint32_t result_hex_str_len, int result ) +void mbedtls_rsa_private( HexParam_t * message_str, int mod, int radix_P, + char * input_P, int radix_Q, char * input_Q, + int radix_N, char * input_N, int radix_E, + char * input_E, HexParam_t * result_hex_str, + int result ) { unsigned char output[1000]; mbedtls_rsa_context ctx, ctx2; /* Also test mbedtls_rsa_copy() while at it */ @@ -465,11 +450,11 @@ void mbedtls_rsa_private( uint8_t * message_str, uint32_t message_str_len, { memset( output, 0x00, 1000 ); TEST_ASSERT( mbedtls_rsa_private( &ctx, rnd_pseudo_rand, &rnd_info, - message_str, output ) == result ); + message_str->x, output ) == result ); if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, ctx.len, result_hex_str->len ) == 0 ); } } @@ -482,11 +467,11 @@ void mbedtls_rsa_private( uint8_t * message_str, uint32_t message_str_len, memset( output, 0x00, 1000 ); TEST_ASSERT( mbedtls_rsa_private( &ctx2, rnd_pseudo_rand, &rnd_info, - message_str, output ) == result ); + message_str->x, output ) == result ); if( result == 0 ) { - TEST_ASSERT( hexcmp( output, result_hex_str, ctx2.len, result_hex_str_len ) == 0 ); + TEST_ASSERT( hexcmp( output, result_hex_str->x, ctx2.len, result_hex_str->len ) == 0 ); } exit: @@ -1138,64 +1123,29 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CTR_DRBG_C:MBEDTLS_ENTROPY_C */ -void mbedtls_rsa_export_raw( char *input_N, char *input_P, - char *input_Q, char *input_D, - char *input_E, int is_priv, +void mbedtls_rsa_export_raw( HexParam_t *input_N, HexParam_t *input_P, + HexParam_t *input_Q, HexParam_t *input_D, + HexParam_t *input_E, int is_priv, int successive ) { - /* Original raw buffers with which we set up the RSA context */ - unsigned char bufN[1000]; - unsigned char bufP[1000]; - unsigned char bufQ[1000]; - unsigned char bufD[1000]; - unsigned char bufE[1000]; - - size_t lenN = 0; - size_t lenP = 0; - size_t lenQ = 0; - size_t lenD = 0; - size_t lenE = 0; - /* Exported buffers */ - unsigned char bufNe[ sizeof( bufN ) ]; - unsigned char bufPe[ sizeof( bufP ) ]; - unsigned char bufQe[ sizeof( bufQ ) ]; - unsigned char bufDe[ sizeof( bufD ) ]; - unsigned char bufEe[ sizeof( bufE ) ]; - - const int have_N = ( strlen( input_N ) > 0 ); - const int have_P = ( strlen( input_P ) > 0 ); - const int have_Q = ( strlen( input_Q ) > 0 ); - const int have_D = ( strlen( input_D ) > 0 ); - const int have_E = ( strlen( input_E ) > 0 ); + unsigned char bufNe[1000]; + unsigned char bufPe[1000]; + unsigned char bufQe[1000]; + unsigned char bufDe[1000]; + unsigned char bufEe[1000]; mbedtls_rsa_context ctx; mbedtls_rsa_init( &ctx, 0, 0 ); /* Setup RSA context */ - - if( have_N ) - lenN = unhexify( bufN, input_N ); - - if( have_P ) - lenP = unhexify( bufP, input_P ); - - if( have_Q ) - lenQ = unhexify( bufQ, input_Q ); - - if( have_D ) - lenD = unhexify( bufD, input_D ); - - if( have_E ) - lenE = unhexify( bufE, input_E ); - TEST_ASSERT( mbedtls_rsa_import_raw( &ctx, - have_N ? bufN : NULL, lenN, - have_P ? bufP : NULL, lenP, - have_Q ? bufQ : NULL, lenQ, - have_D ? bufD : NULL, lenD, - have_E ? bufE : NULL, lenE ) == 0 ); + input_N->len ? input_N->x : NULL, input_N->len, + input_P->len ? input_P->x : NULL, input_P->len, + input_Q->len ? input_Q->x : NULL, input_Q->len, + input_D->len ? input_D->x : NULL, input_D->len, + input_E->len ? input_E->x : NULL, input_E->len ) == 0 ); TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 ); @@ -1206,21 +1156,21 @@ void mbedtls_rsa_export_raw( char *input_N, char *input_P, /* N and E must always be present. */ if( !successive ) { - TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, bufNe, lenN, + TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, bufNe, input_N->len, NULL, 0, NULL, 0, NULL, 0, - bufEe, lenE ) == 0 ); + bufEe, input_E->len ) == 0 ); } else { - TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, bufNe, lenN, + TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, bufNe, input_N->len, NULL, 0, NULL, 0, NULL, 0, NULL, 0 ) == 0 ); TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, NULL, 0, NULL, 0, NULL, 0, NULL, 0, - bufEe, lenE ) == 0 ); + bufEe, input_E->len ) == 0 ); } - TEST_ASSERT( memcmp( bufN, bufNe, lenN ) == 0 ); - TEST_ASSERT( memcmp( bufE, bufEe, lenE ) == 0 ); + TEST_ASSERT( memcmp( input_N->x, bufNe, input_N->len ) == 0 ); + TEST_ASSERT( memcmp( input_E->x, bufEe, input_E->len ) == 0 ); /* If we were providing enough information to setup a complete private context, * we expect to be able to export all core parameters. */ @@ -1230,35 +1180,35 @@ void mbedtls_rsa_export_raw( char *input_N, char *input_P, if( !successive ) { TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, NULL, 0, - bufPe, lenP ? lenP : sizeof( bufPe ), - bufQe, lenQ ? lenQ : sizeof( bufQe ), - bufDe, lenD ? lenD : sizeof( bufDe ), + bufPe, input_P->len ? input_P->len : sizeof( bufPe ), + bufQe, input_Q->len ? input_Q->len : sizeof( bufQe ), + bufDe, input_D->len ? input_D->len : sizeof( bufDe ), NULL, 0 ) == 0 ); } else { TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, NULL, 0, - bufPe, lenP ? lenP : sizeof( bufPe ), + bufPe, input_P->len ? input_P->len : sizeof( bufPe ), NULL, 0, NULL, 0, NULL, 0 ) == 0 ); TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, NULL, 0, NULL, 0, - bufQe, lenQ ? lenQ : sizeof( bufQe ), + bufQe, input_Q->len ? input_Q->len : sizeof( bufQe ), NULL, 0, NULL, 0 ) == 0 ); - TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, NULL, 0, NULL, 0, - NULL, 0, bufDe, lenD ? lenD : sizeof( bufDe ), + TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, NULL, 0, NULL, 0, NULL, 0, + bufDe, input_D->len ? input_D->len : sizeof( bufDe ), NULL, 0 ) == 0 ); } - if( have_P ) - TEST_ASSERT( memcmp( bufP, bufPe, lenP ) == 0 ); + if( input_P->len ) + TEST_ASSERT( memcmp( input_P->x, bufPe, input_P->len ) == 0 ); - if( have_Q ) - TEST_ASSERT( memcmp( bufQ, bufQe, lenQ ) == 0 ); + if( input_Q->len ) + TEST_ASSERT( memcmp( input_Q->x, bufQe, input_Q->len ) == 0 ); - if( have_D ) - TEST_ASSERT( memcmp( bufD, bufDe, lenD ) == 0 ); + if( input_D->len ) + TEST_ASSERT( memcmp( input_D->x, bufDe, input_D->len ) == 0 ); } @@ -1268,31 +1218,19 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CTR_DRBG_C:MBEDTLS_ENTROPY_C:ENTROPY_HAVE_STRONG */ -void mbedtls_rsa_import_raw( char *input_N, - char *input_P, char *input_Q, - char *input_D, char *input_E, +void mbedtls_rsa_import_raw( HexParam_t *input_N, + HexParam_t *input_P, HexParam_t *input_Q, + HexParam_t *input_D, HexParam_t *input_E, int successive, int is_priv, int res_check, int res_complete ) { - unsigned char bufN[1000]; - unsigned char bufP[1000]; - unsigned char bufQ[1000]; - unsigned char bufD[1000]; - unsigned char bufE[1000]; - /* Buffers used for encryption-decryption test */ unsigned char *buf_orig = NULL; unsigned char *buf_enc = NULL; unsigned char *buf_dec = NULL; - size_t lenN = 0; - size_t lenP = 0; - size_t lenQ = 0; - size_t lenD = 0; - size_t lenE = 0; - mbedtls_rsa_context ctx; mbedtls_entropy_context entropy; mbedtls_ctr_drbg_context ctr_drbg; @@ -1307,29 +1245,14 @@ void mbedtls_rsa_import_raw( char *input_N, &entropy, (const unsigned char *) pers, strlen( pers ) ) == 0 ); - if( strlen( input_N ) ) - lenN = unhexify( bufN, input_N ); - - if( strlen( input_P ) ) - lenP = unhexify( bufP, input_P ); - - if( strlen( input_Q ) ) - lenQ = unhexify( bufQ, input_Q ); - - if( strlen( input_D ) ) - lenD = unhexify( bufD, input_D ); - - if( strlen( input_E ) ) - lenE = unhexify( bufE, input_E ); - if( !successive ) { TEST_ASSERT( mbedtls_rsa_import_raw( &ctx, - ( lenN > 0 ) ? bufN : NULL, lenN, - ( lenP > 0 ) ? bufP : NULL, lenP, - ( lenQ > 0 ) ? bufQ : NULL, lenQ, - ( lenD > 0 ) ? bufD : NULL, lenD, - ( lenE > 0 ) ? bufE : NULL, lenE ) == 0 ); + ( input_N->len > 0 ) ? input_N->x : NULL, input_N->len, + ( input_P->len > 0 ) ? input_P->x : NULL, input_P->len, + ( input_Q->len > 0 ) ? input_Q->x : NULL, input_Q->len, + ( input_D->len > 0 ) ? input_D->x : NULL, input_D->len, + ( input_E->len > 0 ) ? input_E->x : NULL, input_E->len ) == 0 ); } else { @@ -1337,27 +1260,27 @@ void mbedtls_rsa_import_raw( char *input_N, * This should make no functional difference. */ TEST_ASSERT( mbedtls_rsa_import_raw( &ctx, - ( lenN > 0 ) ? bufN : NULL, lenN, + ( input_N->len > 0 ) ? input_N->x : NULL, input_N->len, NULL, 0, NULL, 0, NULL, 0, NULL, 0 ) == 0 ); TEST_ASSERT( mbedtls_rsa_import_raw( &ctx, NULL, 0, - ( lenP > 0 ) ? bufP : NULL, lenP, + ( input_P->len > 0 ) ? input_P->x : NULL, input_P->len, NULL, 0, NULL, 0, NULL, 0 ) == 0 ); TEST_ASSERT( mbedtls_rsa_import_raw( &ctx, NULL, 0, NULL, 0, - ( lenQ > 0 ) ? bufQ : NULL, lenQ, + ( input_Q->len > 0 ) ? input_Q->x : NULL, input_Q->len, NULL, 0, NULL, 0 ) == 0 ); TEST_ASSERT( mbedtls_rsa_import_raw( &ctx, NULL, 0, NULL, 0, NULL, 0, - ( lenD > 0 ) ? bufD : NULL, lenD, + ( input_D->len > 0 ) ? input_D->x : NULL, input_D->len, NULL, 0 ) == 0 ); TEST_ASSERT( mbedtls_rsa_import_raw( &ctx, NULL, 0, NULL, 0, NULL, 0, NULL, 0, - ( lenE > 0 ) ? bufE : NULL, lenE ) == 0 ); + ( input_E->len > 0 ) ? input_E->x : NULL, input_E->len ) == 0 ); } TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == res_complete ); diff --git a/tests/suites/test_suite_shax.function b/tests/suites/test_suite_shax.function index 02ac47378..186fb87c2 100644 --- a/tests/suites/test_suite_shax.function +++ b/tests/suites/test_suite_shax.function @@ -5,77 +5,72 @@ /* END_HEADER */ /* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */ -void mbedtls_sha1( uint8_t * src_str, uint32_t src_len, - uint8_t * hex_hash_string, uint32_t hex_hash_string_len ) +void mbedtls_sha1( HexParam_t * src_str, HexParam_t * hex_hash_string ) { unsigned char output[41]; memset(output, 0x00, 41); - TEST_ASSERT( mbedtls_sha1_ret( src_str, src_len, output ) == 0 ); + TEST_ASSERT( mbedtls_sha1_ret( src_str->x, src_str->len, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_hash_string, 20, hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, 20, hex_hash_string->len ) == 0 ); } /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */ -void sha224( uint8_t * src_str, uint32_t src_len, uint8_t * hex_hash_string, - uint32_t hex_hash_string_len ) +void sha224( HexParam_t * src_str, HexParam_t * hex_hash_string ) { unsigned char output[57]; memset(output, 0x00, 57); - TEST_ASSERT( mbedtls_sha256_ret( src_str, src_len, output, 1 ) == 0 ); + TEST_ASSERT( mbedtls_sha256_ret( src_str->x, src_str->len, output, 1 ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_hash_string, 28, hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, 28, hex_hash_string->len ) == 0 ); } /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */ -void mbedtls_sha256( uint8_t * src_str, uint32_t src_len, - uint8_t * hex_hash_string, uint32_t hex_hash_string_len ) +void mbedtls_sha256( HexParam_t * src_str, HexParam_t * hex_hash_string ) { unsigned char output[65]; memset(output, 0x00, 65); - TEST_ASSERT( mbedtls_sha256_ret( src_str, src_len, output, 0 ) == 0 ); + TEST_ASSERT( mbedtls_sha256_ret( src_str->x, src_str->len, output, 0 ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_hash_string, 32, hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, 32, hex_hash_string->len ) == 0 ); } /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */ -void sha384( uint8_t * src_str, uint32_t src_len, uint8_t * hex_hash_string, - uint32_t hex_hash_string_len ) +void sha384( HexParam_t * src_str, HexParam_t * hex_hash_string ) { unsigned char output[97]; memset(output, 0x00, 97); - TEST_ASSERT( mbedtls_sha512_ret( src_str, src_len, output, 1 ) == 0 ); + TEST_ASSERT( mbedtls_sha512_ret( src_str->x, src_str->len, output, 1 ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_hash_string, 48, hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, 48, hex_hash_string->len ) == 0 ); } /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */ -void mbedtls_sha512( uint8_t * src_str, uint32_t src_len, - uint8_t * hex_hash_string, uint32_t hex_hash_string_len ) +void mbedtls_sha512( HexParam_t * src_str, HexParam_t * hex_hash_string ) { unsigned char output[129]; memset(output, 0x00, 129); - TEST_ASSERT( mbedtls_sha512_ret( src_str, src_len, output, 0 ) == 0 ); + TEST_ASSERT( mbedtls_sha512_ret( src_str->x, src_str->len, output, 0 ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_hash_string, 64, hex_hash_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_hash_string->x, 64, hex_hash_string->len ) == 0 ); } /* END_CASE */ diff --git a/tests/suites/test_suite_ssl.data b/tests/suites/test_suite_ssl.data index b92c1fe8a..147350744 100644 --- a/tests/suites/test_suite_ssl.data +++ b/tests/suites/test_suite_ssl.data @@ -8,52 +8,52 @@ SSL DTLS replay: 0 seen, 0 replayed ssl_dtls_replay:"000000000000":"000000000000":-1 SSL DTLS replay: 0-1 seen, 2 arriving -ssl_dtls_replay:"000000000000,000000000001":"000000000002":0 +ssl_dtls_replay:"000000000000000000000001":"000000000002":0 SSL DTLS replay: 0-1 seen, 1 replayed -ssl_dtls_replay:"000000000000,000000000001":"000000000001":-1 +ssl_dtls_replay:"000000000000000000000001":"000000000001":-1 SSL DTLS replay: 0-1 seen, 0 replayed -ssl_dtls_replay:"000000000000,000000000001":"000000000000":-1 +ssl_dtls_replay:"000000000000000000000001":"000000000000":-1 SSL DTLS replay: new -ssl_dtls_replay:"abcd12340000,abcd12340001,abcd12340003":"abcd12340004":0 +ssl_dtls_replay:"abcd12340000abcd12340001abcd12340003":"abcd12340004":0 SSL DTLS replay: way new -ssl_dtls_replay:"abcd12340000,abcd12340001,abcd12340003":"abcd12350000":0 +ssl_dtls_replay:"abcd12340000abcd12340001abcd12340003":"abcd12350000":0 SSL DTLS replay: delayed -ssl_dtls_replay:"abcd12340000,abcd12340001,abcd12340003":"abcd12340002":0 +ssl_dtls_replay:"abcd12340000abcd12340001abcd12340003":"abcd12340002":0 SSL DTLS replay: lastest replayed -ssl_dtls_replay:"abcd12340000,abcd12340001,abcd12340003":"abcd12340003":-1 +ssl_dtls_replay:"abcd12340000abcd12340001abcd12340003":"abcd12340003":-1 SSL DTLS replay: older replayed -ssl_dtls_replay:"abcd12340000,abcd12340001,abcd12340003":"abcd12340001":-1 +ssl_dtls_replay:"abcd12340000abcd12340001abcd12340003":"abcd12340001":-1 SSL DTLS replay: most recent in window, replayed -ssl_dtls_replay:"abcd12340000,abcd12340002,abcd12340003":"abcd12340002":-1 +ssl_dtls_replay:"abcd12340000abcd12340002abcd12340003":"abcd12340002":-1 SSL DTLS replay: oldest in window, replayed -ssl_dtls_replay:"abcd12340000,abcd12340001,abcd1234003f":"abcd12340000":-1 +ssl_dtls_replay:"abcd12340000abcd12340001abcd1234003f":"abcd12340000":-1 SSL DTLS replay: oldest in window, not replayed -ssl_dtls_replay:"abcd12340001,abcd12340002,abcd1234003f":"abcd12340000":0 +ssl_dtls_replay:"abcd12340001abcd12340002abcd1234003f":"abcd12340000":0 SSL DTLS replay: just out of the window -ssl_dtls_replay:"abcd12340001,abcd12340002,abcd1234003f":"abcd1233ffff":-1 +ssl_dtls_replay:"abcd12340001abcd12340002abcd1234003f":"abcd1233ffff":-1 SSL DTLS replay: way out of the window -ssl_dtls_replay:"abcd12340001,abcd12340002,abcd1234003f":"abcd12330000":-1 +ssl_dtls_replay:"abcd12340001abcd12340002abcd1234003f":"abcd12330000":-1 SSL DTLS replay: big jump then replay -ssl_dtls_replay:"abcd12340000,abcd12340100":"abcd12340100":-1 +ssl_dtls_replay:"abcd12340000abcd12340100":"abcd12340100":-1 SSL DTLS replay: big jump then new -ssl_dtls_replay:"abcd12340000,abcd12340100":"abcd12340101":0 +ssl_dtls_replay:"abcd12340000abcd12340100":"abcd12340101":0 SSL DTLS replay: big jump then just delayed -ssl_dtls_replay:"abcd12340000,abcd12340100":"abcd123400ff":0 +ssl_dtls_replay:"abcd12340000abcd12340100":"abcd123400ff":0 SSL SET_HOSTNAME memory leak: call ssl_set_hostname twice ssl_set_hostname_twice:"server0":"server1" diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function index 5cc32ab91..eed518385 100644 --- a/tests/suites/test_suite_ssl.function +++ b/tests/suites/test_suite_ssl.function @@ -9,11 +9,11 @@ */ /* BEGIN_CASE depends_on:MBEDTLS_SSL_DTLS_ANTI_REPLAY */ -void ssl_dtls_replay( char *prevs, char *new, int ret ) +void ssl_dtls_replay( HexParam_t * prevs, HexParam_t * new, int ret ) { + uint32_t len = 0; mbedtls_ssl_context ssl; mbedtls_ssl_config conf; - char *end_prevs = prevs + strlen( prevs ) + 1; mbedtls_ssl_init( &ssl ); mbedtls_ssl_config_init( &conf ); @@ -25,15 +25,14 @@ void ssl_dtls_replay( char *prevs, char *new, int ret ) TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 ); /* Read previous record numbers */ - for( ; end_prevs - prevs >= 13; prevs += 13 ) + for( len = 0; len < prevs->len; len += 6 ) { - prevs[12] = '\0'; - unhexify( ssl.in_ctr + 2, prevs ); + memcpy( ssl.in_ctr + 2, prevs->x + len, 6 ); mbedtls_ssl_dtls_replay_update( &ssl ); } /* Check new number */ - unhexify( ssl.in_ctr + 2, new ); + memcpy( ssl.in_ctr + 2, new->x, 6 ); TEST_ASSERT( mbedtls_ssl_dtls_replay_check( &ssl ) == ret ); mbedtls_ssl_free( &ssl ); diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function index 4d36027f1..2e283087b 100644 --- a/tests/suites/test_suite_x509parse.function +++ b/tests/suites/test_suite_x509parse.function @@ -1,4 +1,5 @@ /* BEGIN_HEADER */ +#include "mbedtls/bignum.h" #include "mbedtls/x509.h" #include "mbedtls/x509_crt.h" #include "mbedtls/x509_crl.h" @@ -439,8 +440,7 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ -void x509parse_crt( uint8_t * buf, uint32_t data_len, char * result_str, - int result ) +void x509parse_crt( HexParam_t * buf, char * result_str, int result ) { mbedtls_x509_crt crt; unsigned char output[2000]; @@ -450,7 +450,7 @@ void x509parse_crt( uint8_t * buf, uint32_t data_len, char * result_str, memset( output, 0, 2000 ); - TEST_ASSERT( mbedtls_x509_crt_parse( &crt, buf, data_len ) == ( result ) ); + TEST_ASSERT( mbedtls_x509_crt_parse( &crt, buf->x, buf->len ) == ( result ) ); if( ( result ) == 0 ) { res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt ); @@ -467,8 +467,7 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_X509_CRL_PARSE_C */ -void x509parse_crl( uint8_t * buf, uint32_t data_len, char * result_str, - int result ) +void x509parse_crl( HexParam_t * buf, char * result_str, int result ) { mbedtls_x509_crl crl; unsigned char output[2000]; @@ -478,7 +477,7 @@ void x509parse_crl( uint8_t * buf, uint32_t data_len, char * result_str, memset( output, 0, 2000 ); - TEST_ASSERT( mbedtls_x509_crl_parse( &crl, buf, data_len ) == ( result ) ); + TEST_ASSERT( mbedtls_x509_crl_parse( &crl, buf->x, buf->len ) == ( result ) ); if( ( result ) == 0 ) { res = mbedtls_x509_crl_info( (char *) output, 2000, "", &crl ); @@ -495,19 +494,16 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_X509_CSR_PARSE_C */ -void mbedtls_x509_csr_parse( char * csr_der_hex, char * ref_out, int ref_ret ) +void mbedtls_x509_csr_parse( HexParam_t * csr_der, char * ref_out, int ref_ret ) { mbedtls_x509_csr csr; - unsigned char *csr_der = NULL; char my_out[1000]; - size_t csr_der_len; int my_ret; mbedtls_x509_csr_init( &csr ); memset( my_out, 0, sizeof( my_out ) ); - csr_der = unhexify_alloc( csr_der_hex, &csr_der_len ); - my_ret = mbedtls_x509_csr_parse_der( &csr, csr_der, csr_der_len ); + my_ret = mbedtls_x509_csr_parse_der( &csr, csr_der->x, csr_der->len ); TEST_ASSERT( my_ret == ref_ret ); if( ref_ret == 0 ) @@ -519,7 +515,6 @@ void mbedtls_x509_csr_parse( char * csr_der_hex, char * ref_out, int ref_ret ) exit: mbedtls_x509_csr_free( &csr ); - mbedtls_free( csr_der ); } /* END_CASE */ @@ -626,7 +621,7 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */ -void x509_oid_desc( uint8_t * buf, uint32_t buf_len, char * ref_desc ) +void x509_oid_desc( HexParam_t * buf, char * ref_desc ) { mbedtls_x509_buf oid; const char *desc = NULL; @@ -634,8 +629,8 @@ void x509_oid_desc( uint8_t * buf, uint32_t buf_len, char * ref_desc ) oid.tag = MBEDTLS_ASN1_OID; - oid.p = buf; - oid.len = buf_len; + oid.p = buf->x; + oid.len = buf->len; ret = mbedtls_oid_get_extended_key_usage( &oid, &desc ); @@ -654,8 +649,7 @@ void x509_oid_desc( uint8_t * buf, uint32_t buf_len, char * ref_desc ) /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */ -void x509_oid_numstr( uint8_t * oid_buf, uint32_t oid_buf_len, char * numstr, - int blen, int ret ) +void x509_oid_numstr( HexParam_t * oid_buf, char * numstr, int blen, int ret ) { mbedtls_x509_buf oid; char num_buf[100]; @@ -663,8 +657,8 @@ void x509_oid_numstr( uint8_t * oid_buf, uint32_t oid_buf_len, char * numstr, memset( num_buf, 0x2a, sizeof num_buf ); oid.tag = MBEDTLS_ASN1_OID; - oid.p = oid_buf; - oid.len = oid_buf_len; + oid.p = oid_buf->x; + oid.len = oid_buf->len; TEST_ASSERT( (size_t) blen <= sizeof num_buf ); @@ -695,8 +689,8 @@ exit: /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */ -void x509_check_extended_key_usage( char * crt_file, uint8_t * oid, - uint32_t len, int ret ) +void x509_check_extended_key_usage( char * crt_file, HexParam_t * oid, int ret + ) { mbedtls_x509_crt crt; @@ -705,7 +699,7 @@ void x509_check_extended_key_usage( char * crt_file, uint8_t * oid, TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 ); - TEST_ASSERT( mbedtls_x509_crt_check_extended_key_usage( &crt, oid, len ) == ret ); + TEST_ASSERT( mbedtls_x509_crt_check_extended_key_usage( &crt, (const char *)oid->x, oid->len ) == ret ); exit: mbedtls_x509_crt_free( &crt ); @@ -743,7 +737,7 @@ void x509_get_time( int tag, char * time_str, int ret, int year, int mon, /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_RSASSA_PSS_SUPPORT */ -void x509_parse_rsassa_pss_params( char * hex_params, int params_tag, +void x509_parse_rsassa_pss_params( HexParam_t * hex_params, int params_tag, int ref_msg_md, int ref_mgf_md, int ref_salt_len, int ref_ret ) { @@ -752,7 +746,8 @@ void x509_parse_rsassa_pss_params( char * hex_params, int params_tag, mbedtls_md_type_t my_msg_md, my_mgf_md; int my_salt_len; - params.p = unhexify_alloc( hex_params, ¶ms.len ); + params.p = hex_params->x; + params.len = hex_params->len; params.tag = params_tag; my_ret = mbedtls_x509_get_rsassa_pss_params( ¶ms, &my_msg_md, &my_mgf_md, @@ -768,7 +763,7 @@ void x509_parse_rsassa_pss_params( char * hex_params, int params_tag, } exit: - mbedtls_free( params.p ); + ;; } /* END_CASE */ diff --git a/tests/suites/test_suite_xtea.function b/tests/suites/test_suite_xtea.function index 7da890acb..94c6ff5e1 100644 --- a/tests/suites/test_suite_xtea.function +++ b/tests/suites/test_suite_xtea.function @@ -8,9 +8,8 @@ */ /* BEGIN_CASE */ -void xtea_encrypt_ecb( uint8_t * key_str, uint32_t key_str_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len ) +void xtea_encrypt_ecb( HexParam_t * key_str, HexParam_t * src_str, + HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_xtea_context ctx; @@ -18,17 +17,16 @@ void xtea_encrypt_ecb( uint8_t * key_str, uint32_t key_str_len, memset(output, 0x00, 100); - mbedtls_xtea_setup( &ctx, key_str ); - TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str, output ) == 0 ); + mbedtls_xtea_setup( &ctx, key_str->x ); + TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 8, hex_dst_string->len ) == 0 ); } /* END_CASE */ /* BEGIN_CASE */ -void xtea_decrypt_ecb( uint8_t * key_str, uint32_t key_str_len, - uint8_t * src_str, uint32_t src_str_len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len ) +void xtea_decrypt_ecb( HexParam_t * key_str, HexParam_t * src_str, + HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_xtea_context ctx; @@ -36,18 +34,16 @@ void xtea_decrypt_ecb( uint8_t * key_str, uint32_t key_str_len, memset(output, 0x00, 100); - mbedtls_xtea_setup( &ctx, key_str ); - TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_DECRYPT, src_str, output ) == 0 ); + mbedtls_xtea_setup( &ctx, key_str->x ); + TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_DECRYPT, src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, 8, hex_dst_string->len ) == 0 ); } /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ -void xtea_encrypt_cbc( uint8_t * key_str, uint32_t key_str_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len ) +void xtea_encrypt_cbc( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_xtea_context ctx; @@ -55,19 +51,17 @@ void xtea_encrypt_cbc( uint8_t * key_str, uint32_t key_str_len, memset(output, 0x00, 100); - mbedtls_xtea_setup( &ctx, key_str ); - TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_ENCRYPT, len, iv_str, - src_str, output ) == 0 ); + mbedtls_xtea_setup( &ctx, key_str->x ); + TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str->len, iv_str->x, + src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); } /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ -void xtea_decrypt_cbc( uint8_t * key_str, uint32_t key_str_len, - uint8_t * iv_str, uint32_t iv_str_len, - uint8_t * src_str, uint32_t len, - uint8_t * hex_dst_string, uint32_t hex_dst_string_len ) +void xtea_decrypt_cbc( HexParam_t * key_str, HexParam_t * iv_str, + HexParam_t * src_str, HexParam_t * hex_dst_string ) { unsigned char output[100]; mbedtls_xtea_context ctx; @@ -75,11 +69,11 @@ void xtea_decrypt_cbc( uint8_t * key_str, uint32_t key_str_len, memset(output, 0x00, 100); - mbedtls_xtea_setup( &ctx, key_str ); - TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_DECRYPT, len, iv_str, - src_str, output ) == 0 ); + mbedtls_xtea_setup( &ctx, key_str->x ); + TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_DECRYPT, src_str->len, iv_str->x, + src_str->x, output ) == 0 ); - TEST_ASSERT( hexcmp( output, hex_dst_string, len, hex_dst_string_len ) == 0 ); + TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); } /* END_CASE */