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

@ -8,42 +8,28 @@
*/
/* BEGIN_CASE */
void des_check_weak( char *key_hex, int ret )
void des_check_weak( uint8_t * key, uint32_t key_len, int ret )
{
unsigned char key[MBEDTLS_DES_KEY_SIZE];
memset( key, 0, sizeof key );
unhexify( key, key_hex );
TEST_ASSERT( mbedtls_des_key_check_weak( key ) == ret );
}
/* END_CASE */
/* BEGIN_CASE */
void des_encrypt_ecb( char *hex_key_string, char *hex_src_string,
char *hex_dst_string )
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 )
{
unsigned char key_str[100];
unsigned char src_str[100];
unsigned char dst_str[100];
unsigned char output[100];
mbedtls_des_context ctx;
memset(key_str, 0x00, 100);
memset(src_str, 0x00, 100);
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
mbedtls_des_init( &ctx );
unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
mbedtls_des_setkey_enc( &ctx, key_str );
TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str, output ) == 0 );
hexify( dst_str, output, 8 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
exit:
mbedtls_des_free( &ctx );
@ -51,29 +37,21 @@ exit:
/* END_CASE */
/* BEGIN_CASE */
void des_decrypt_ecb( char *hex_key_string, char *hex_src_string,
char *hex_dst_string )
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 )
{
unsigned char key_str[100];
unsigned char src_str[100];
unsigned char dst_str[100];
unsigned char output[100];
mbedtls_des_context ctx;
memset(key_str, 0x00, 100);
memset(src_str, 0x00, 100);
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
mbedtls_des_init( &ctx );
unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
mbedtls_des_setkey_dec( &ctx, key_str );
TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str, output ) == 0 );
hexify( dst_str, output, 8 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
exit:
mbedtls_des_free( &ctx );
@ -81,35 +59,25 @@ exit:
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
void des_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string, int cbc_result )
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,
int cbc_result )
{
unsigned char key_str[100];
unsigned char iv_str[100];
unsigned char src_str[100];
unsigned char dst_str[100];
unsigned char output[100];
mbedtls_des_context ctx;
int src_len;
memset(key_str, 0x00, 100);
memset(iv_str, 0x00, 100);
memset(src_str, 0x00, 100);
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
mbedtls_des_init( &ctx );
unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
src_len = unhexify( src_str, hex_src_string );
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 );
if( cbc_result == 0 )
{
hexify( dst_str, output, src_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
}
exit:
@ -118,35 +86,25 @@ exit:
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
void des_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
char *hex_src_string, char *hex_dst_string, int cbc_result )
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,
int cbc_result )
{
unsigned char key_str[100];
unsigned char iv_str[100];
unsigned char src_str[100];
unsigned char dst_str[100];
unsigned char output[100];
mbedtls_des_context ctx;
int src_len;
memset(key_str, 0x00, 100);
memset(iv_str, 0x00, 100);
memset(src_str, 0x00, 100);
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
mbedtls_des_init( &ctx );
unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
src_len = unhexify( src_str, hex_src_string );
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 );
if( cbc_result == 0 )
{
hexify( dst_str, output, src_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
}
exit:
@ -155,23 +113,16 @@ exit:
/* END_CASE */
/* BEGIN_CASE */
void des3_encrypt_ecb( int key_count, char *hex_key_string,
char *hex_src_string, char *hex_dst_string )
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 )
{
unsigned char key_str[100];
unsigned char src_str[100];
unsigned char dst_str[100];
unsigned char output[100];
mbedtls_des3_context ctx;
memset(key_str, 0x00, 100);
memset(src_str, 0x00, 100);
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
mbedtls_des3_init( &ctx );
unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
if( key_count == 2 )
mbedtls_des3_set2key_enc( &ctx, key_str );
@ -181,9 +132,8 @@ void des3_encrypt_ecb( int key_count, char *hex_key_string,
TEST_ASSERT( 0 );
TEST_ASSERT( mbedtls_des3_crypt_ecb( &ctx, src_str, output ) == 0 );
hexify( dst_str, output, 8 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
exit:
mbedtls_des3_free( &ctx );
@ -191,23 +141,16 @@ exit:
/* END_CASE */
/* BEGIN_CASE */
void des3_decrypt_ecb( int key_count, char *hex_key_string,
char *hex_src_string, char *hex_dst_string )
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 )
{
unsigned char key_str[100];
unsigned char src_str[100];
unsigned char dst_str[100];
unsigned char output[100];
mbedtls_des3_context ctx;
memset(key_str, 0x00, 100);
memset(src_str, 0x00, 100);
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
mbedtls_des3_init( &ctx );
unhexify( key_str, hex_key_string );
unhexify( src_str, hex_src_string );
if( key_count == 2 )
mbedtls_des3_set2key_dec( &ctx, key_str );
@ -217,9 +160,8 @@ void des3_decrypt_ecb( int key_count, char *hex_key_string,
TEST_ASSERT( 0 );
TEST_ASSERT( mbedtls_des3_crypt_ecb( &ctx, src_str, output ) == 0 );
hexify( dst_str, output, 8 );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
exit:
mbedtls_des3_free( &ctx );
@ -227,28 +169,18 @@ exit:
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
void des3_encrypt_cbc( int key_count, char *hex_key_string,
char *hex_iv_string, char *hex_src_string,
char *hex_dst_string, int cbc_result )
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 )
{
unsigned char key_str[100];
unsigned char iv_str[100];
unsigned char src_str[100];
unsigned char dst_str[100];
unsigned char output[100];
mbedtls_des3_context ctx;
int src_len;
memset(key_str, 0x00, 100);
memset(iv_str, 0x00, 100);
memset(src_str, 0x00, 100);
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
mbedtls_des3_init( &ctx );
unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
src_len = unhexify( src_str, hex_src_string );
if( key_count == 2 )
mbedtls_des3_set2key_enc( &ctx, key_str );
@ -261,9 +193,8 @@ void des3_encrypt_cbc( int key_count, char *hex_key_string,
if( cbc_result == 0 )
{
hexify( dst_str, output, src_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
}
exit:
@ -272,28 +203,18 @@ exit:
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
void des3_decrypt_cbc( int key_count, char *hex_key_string,
char *hex_iv_string, char *hex_src_string,
char *hex_dst_string, int cbc_result )
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 )
{
unsigned char key_str[100];
unsigned char iv_str[100];
unsigned char src_str[100];
unsigned char dst_str[100];
unsigned char output[100];
mbedtls_des3_context ctx;
int src_len;
memset(key_str, 0x00, 100);
memset(iv_str, 0x00, 100);
memset(src_str, 0x00, 100);
memset(dst_str, 0x00, 100);
memset(output, 0x00, 100);
mbedtls_des3_init( &ctx );
unhexify( key_str, hex_key_string );
unhexify( iv_str, hex_iv_string );
src_len = unhexify( src_str, hex_src_string );
if( key_count == 2 )
mbedtls_des3_set2key_dec( &ctx, key_str );
@ -306,9 +227,8 @@ void des3_decrypt_cbc( int key_count, char *hex_key_string,
if( cbc_result == 0 )
{
hexify( dst_str, output, src_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
}
exit:
@ -317,7 +237,7 @@ exit:
/* END_CASE */
/* BEGIN_CASE */
void des_key_parity_run()
void des_key_parity_run( )
{
int i, j, cnt;
unsigned char key[MBEDTLS_DES_KEY_SIZE];
@ -360,7 +280,7 @@ void des_key_parity_run()
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void des_selftest()
void des_selftest( )
{
TEST_ASSERT( mbedtls_des_self_test( 1 ) == 0 );
}