Intermediate hexify out change

This commit is contained in:
Azim Khan 2017-05-30 14:23:15 +01:00 committed by Mohammad Azim Khan
parent 9079170f6e
commit f1aaec9888
39 changed files with 780 additions and 1563 deletions

View file

@ -12,7 +12,7 @@
*/
/* BEGIN_CASE */
void mbedtls_cipher_list( )
void mbedtls_cipher_list( )
{
const int *cipher_type;
@ -22,7 +22,7 @@ void mbedtls_cipher_list( )
/* END_CASE */
/* BEGIN_CASE */
void cipher_null_args( )
void cipher_null_args( )
{
mbedtls_cipher_context_t ctx;
const mbedtls_cipher_info_t *info = mbedtls_cipher_info_from_type( *( mbedtls_cipher_list() ) );
@ -92,7 +92,7 @@ void cipher_null_args( )
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_AES_C */
void cipher_special_behaviours( )
void cipher_special_behaviours( )
{
const mbedtls_cipher_info_t *cipher_info;
mbedtls_cipher_context_t ctx;
@ -130,7 +130,7 @@ exit:
/* END_CASE */
/* BEGIN_CASE */
void enc_dec_buf( int cipher_id, char *cipher_string, int key_len,
void enc_dec_buf( int cipher_id, char * cipher_string, int key_len,
int length_val, int pad_mode )
{
size_t length = length_val, outlen, total_len, i, block_size;
@ -255,8 +255,8 @@ exit:
/* END_CASE */
/* BEGIN_CASE */
void enc_fail( int cipher_id, int pad_mode, int key_len,
int length_val, int ret )
void enc_fail( int cipher_id, int pad_mode, int key_len, int length_val,
int ret )
{
size_t length = length_val;
unsigned char key[32];
@ -307,7 +307,7 @@ exit:
/* END_CASE */
/* BEGIN_CASE */
void dec_empty_buf()
void dec_empty_buf( )
{
unsigned char key[32];
unsigned char iv[16];
@ -471,44 +471,22 @@ exit:
/* END_CASE */
/* BEGIN_CASE */
void decrypt_test_vec( int cipher_id, int pad_mode,
char *hex_key, char *hex_iv,
char *hex_cipher, char *hex_clear,
char *hex_ad, char *hex_tag,
int finish_result, int tag_result )
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 )
{
unsigned char key[50];
unsigned char iv[50];
unsigned char cipher[265]; /* max length of test data so far */
unsigned char clear[265];
unsigned char output[265];
unsigned char ad[200];
unsigned char tag[20];
size_t key_len, iv_len, cipher_len, clear_len;
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
size_t ad_len, tag_len;
#endif
mbedtls_cipher_context_t ctx;
size_t outlen, total_len;
mbedtls_cipher_init( &ctx );
memset( key, 0x00, sizeof( key ) );
memset( iv, 0x00, sizeof( iv ) );
memset( cipher, 0x00, sizeof( cipher ) );
memset( clear, 0x00, sizeof( clear ) );
memset( ad, 0x00, sizeof( ad ) );
memset( tag, 0x00, sizeof( tag ) );
memset( output, 0x00, sizeof( output ) );
key_len = unhexify( key, hex_key );
iv_len = unhexify( iv, hex_iv );
cipher_len = unhexify( cipher, hex_cipher );
clear_len = unhexify( clear, hex_clear );
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
ad_len = unhexify( ad, hex_ad );
tag_len = unhexify( tag, hex_tag );
#else
#if !defined(MBEDTLS_GCM_C) && !defined(MBEDTLS_CHACHAPOLY_C)
((void) hex_ad);
((void) hex_tag);
#endif
@ -553,39 +531,22 @@ exit:
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_AEAD */
void auth_crypt_tv( int cipher_id, char *hex_key, char *hex_iv,
char *hex_ad, char *hex_cipher,
char *hex_tag, char *hex_clear )
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, uint8_t * clear,
uint32_t clear_len )
{
int ret;
unsigned char key[50];
unsigned char iv[50];
unsigned char cipher[265]; /* max size of test data so far */
unsigned char clear[265];
unsigned char output[267]; /* above + 2 (overwrite check) */
unsigned char ad[200];
unsigned char tag[20];
unsigned char my_tag[20];
size_t key_len, iv_len, cipher_len, clear_len, ad_len, tag_len;
mbedtls_cipher_context_t ctx;
size_t outlen;
mbedtls_cipher_init( &ctx );
memset( key, 0x00, sizeof( key ) );
memset( iv, 0x00, sizeof( iv ) );
memset( cipher, 0x00, sizeof( cipher ) );
memset( clear, 0x00, sizeof( clear ) );
memset( ad, 0x00, sizeof( ad ) );
memset( tag, 0x00, sizeof( tag ) );
memset( my_tag, 0xFF, sizeof( my_tag ) );
memset( output, 0xFF, sizeof( output ) );
key_len = unhexify( key, hex_key );
iv_len = unhexify( iv, hex_iv );
cipher_len = unhexify( cipher, hex_cipher );
ad_len = unhexify( ad, hex_ad );
tag_len = unhexify( tag, hex_tag );
/* Prepare context */
TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx,
@ -602,7 +563,7 @@ void auth_crypt_tv( int cipher_id, char *hex_key, char *hex_iv,
TEST_ASSERT( output[outlen + 1] == 0xFF );
/* make sure the message is rejected if it should be */
if( strcmp( hex_clear, "FAIL" ) == 0 )
if( strcmp( clear, "FAIL" ) == 0 )
{
TEST_ASSERT( ret == MBEDTLS_ERR_CIPHER_AUTH_FAILED );
goto exit;
@ -611,7 +572,6 @@ void auth_crypt_tv( int cipher_id, char *hex_key, char *hex_iv,
/* otherwise, make sure it was decrypted properly */
TEST_ASSERT( ret == 0 );
clear_len = unhexify( clear, hex_clear );
TEST_ASSERT( outlen == clear_len );
TEST_ASSERT( memcmp( output, clear, clear_len ) == 0 );
@ -641,34 +601,22 @@ exit:
/* END_CASE */
/* BEGIN_CASE */
void test_vec_ecb( int cipher_id, int operation, char *hex_key,
char *hex_input, char *hex_result,
int finish_result )
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 )
{
unsigned char key[50];
unsigned char input[16];
unsigned char result[16];
size_t key_len;
mbedtls_cipher_context_t ctx;
unsigned char output[32];
size_t outlen;
mbedtls_cipher_init( &ctx );
memset( key, 0x00, sizeof( key ) );
memset( input, 0x00, sizeof( input ) );
memset( result, 0x00, sizeof( result ) );
memset( output, 0x00, sizeof( output ) );
/* Prepare context */
TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx,
mbedtls_cipher_info_from_type( cipher_id ) ) );
key_len = unhexify( key, hex_key );
TEST_ASSERT( unhexify( input, hex_input ) ==
(int) mbedtls_cipher_get_block_size( &ctx ) );
TEST_ASSERT( unhexify( result, hex_result ) ==
(int) mbedtls_cipher_get_block_size( &ctx ) );
TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key, 8 * key_len, operation ) );
@ -710,12 +658,12 @@ exit:
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
void check_padding( int pad_mode, char *input_str, int ret, int dlen_check )
void check_padding( int pad_mode, uint8_t * input, uint32_t ilen, int ret,
int dlen_check )
{
mbedtls_cipher_info_t cipher_info;
mbedtls_cipher_context_t ctx;
unsigned char input[16];
size_t ilen, dlen;
size_t dlen;
/* build a fake context just for getting access to get_padding */
mbedtls_cipher_init( &ctx );
@ -724,7 +672,6 @@ void check_padding( int pad_mode, char *input_str, int ret, int dlen_check )
TEST_ASSERT( 0 == mbedtls_cipher_set_padding_mode( &ctx, pad_mode ) );
ilen = unhexify( input, input_str );
TEST_ASSERT( ret == ctx.get_padding( input, ilen, &dlen ) );
if( 0 == ret )