Intermediate hexify out change
This commit is contained in:
parent
9079170f6e
commit
f1aaec9888
39 changed files with 780 additions and 1563 deletions
|
@ -8,32 +8,23 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void aes_encrypt_ecb( char *hex_key_string, char *hex_src_string,
|
||||
char *hex_dst_string, int setkey_result )
|
||||
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 )
|
||||
{
|
||||
unsigned char key_str[100];
|
||||
unsigned char src_str[100];
|
||||
unsigned char dst_str[100];
|
||||
unsigned char output[100];
|
||||
mbedtls_aes_context ctx;
|
||||
int key_len;
|
||||
|
||||
memset(key_str, 0x00, 100);
|
||||
memset(src_str, 0x00, 100);
|
||||
memset(dst_str, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
mbedtls_aes_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( src_str, hex_src_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str, key_len * 8 ) == setkey_result );
|
||||
if( setkey_result == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_ENCRYPT, src_str, output ) == 0 );
|
||||
hexify( dst_str, output, 16 );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -42,32 +33,23 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void aes_decrypt_ecb( char *hex_key_string, char *hex_src_string,
|
||||
char *hex_dst_string, int setkey_result )
|
||||
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 )
|
||||
{
|
||||
unsigned char key_str[100];
|
||||
unsigned char src_str[100];
|
||||
unsigned char dst_str[100];
|
||||
unsigned char output[100];
|
||||
mbedtls_aes_context ctx;
|
||||
int key_len;
|
||||
|
||||
memset(key_str, 0x00, 100);
|
||||
memset(src_str, 0x00, 100);
|
||||
memset(dst_str, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
mbedtls_aes_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( src_str, hex_src_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_aes_setkey_dec( &ctx, key_str, key_len * 8 ) == setkey_result );
|
||||
if( setkey_result == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_DECRYPT, src_str, output ) == 0 );
|
||||
hexify( dst_str, output, 16 );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -76,36 +58,24 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void aes_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string,
|
||||
int cbc_result )
|
||||
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 )
|
||||
{
|
||||
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_aes_context ctx;
|
||||
int key_len, data_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_aes_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
data_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
hexify( dst_str, output, data_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, data_len, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -114,36 +84,24 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void aes_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string,
|
||||
int cbc_result )
|
||||
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 )
|
||||
{
|
||||
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_aes_context ctx;
|
||||
int key_len, data_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_aes_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
data_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
if( cbc_result == 0)
|
||||
{
|
||||
hexify( dst_str, output, data_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, data_len, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -276,34 +234,24 @@ exit:
|
|||
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void aes_encrypt_cfb128( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string )
|
||||
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
|
||||
)
|
||||
{
|
||||
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_aes_context ctx;
|
||||
size_t iv_offset = 0;
|
||||
int key_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_aes_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
hexify( dst_str, output, 16 );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_aes_free( &ctx );
|
||||
|
@ -311,34 +259,24 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void aes_decrypt_cfb128( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string )
|
||||
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
|
||||
)
|
||||
{
|
||||
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_aes_context ctx;
|
||||
size_t iv_offset = 0;
|
||||
int key_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_aes_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
hexify( dst_str, output, 16 );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_aes_free( &ctx );
|
||||
|
@ -346,33 +284,22 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void aes_encrypt_cfb8( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string )
|
||||
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 )
|
||||
{
|
||||
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_aes_context ctx;
|
||||
int key_len, 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_aes_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
hexify( dst_str, output, src_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_aes_free( &ctx );
|
||||
|
@ -380,33 +307,22 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void aes_decrypt_cfb8( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string )
|
||||
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 )
|
||||
{
|
||||
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_aes_context ctx;
|
||||
int key_len, 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_aes_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
hexify( dst_str, output, src_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_aes_free( &ctx );
|
||||
|
@ -471,7 +387,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void aes_selftest()
|
||||
void aes_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_aes_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -8,30 +8,22 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_arc4_crypt( char *hex_src_string, char *hex_key_string,
|
||||
char *hex_dst_string )
|
||||
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
|
||||
)
|
||||
{
|
||||
unsigned char src_str[1000];
|
||||
unsigned char key_str[1000];
|
||||
unsigned char dst_str[1000];
|
||||
unsigned char dst_hexstr[2000];
|
||||
int src_len, key_len;
|
||||
mbedtls_arc4_context ctx;
|
||||
|
||||
memset(src_str, 0x00, 1000);
|
||||
memset(key_str, 0x00, 1000);
|
||||
memset(dst_str, 0x00, 1000);
|
||||
memset(dst_hexstr, 0x00, 2000);
|
||||
mbedtls_arc4_init( &ctx );
|
||||
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
|
||||
mbedtls_arc4_setup(&ctx, key_str, key_len);
|
||||
TEST_ASSERT( mbedtls_arc4_crypt(&ctx, src_len, src_str, dst_str ) == 0 );
|
||||
hexify( dst_hexstr, dst_str, src_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_hexstr, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( dst_str, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_arc4_free( &ctx );
|
||||
|
@ -39,7 +31,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void arc4_selftest()
|
||||
void arc4_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_arc4_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -11,22 +11,17 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_asn1_write_octet_string( char *hex_str, char *hex_asn1,
|
||||
int buf_len, int result )
|
||||
void mbedtls_asn1_write_octet_string( uint8_t * str, uint32_t str_len,
|
||||
uint8_t * asn1, uint32_t asn1_len,
|
||||
int buf_len, int result )
|
||||
{
|
||||
int ret;
|
||||
unsigned char buf[150];
|
||||
unsigned char str[150] = { 0 };
|
||||
unsigned char asn1[150] = { 0 };
|
||||
size_t str_len;
|
||||
size_t asn1_len;
|
||||
size_t i;
|
||||
unsigned char *p;
|
||||
|
||||
memset( buf, GUARD_VAL, sizeof( buf ) );
|
||||
|
||||
str_len = unhexify( str, hex_str );
|
||||
asn1_len = unhexify( asn1, hex_asn1 );
|
||||
|
||||
p = buf + GUARD_LEN + buf_len;
|
||||
|
||||
|
@ -41,7 +36,6 @@ void mbedtls_asn1_write_octet_string( char *hex_str, char *hex_asn1,
|
|||
|
||||
if( result >= 0 )
|
||||
{
|
||||
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 );
|
||||
|
@ -50,21 +44,19 @@ void mbedtls_asn1_write_octet_string( char *hex_str, char *hex_asn1,
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_asn1_write_ia5_string( char *str, char *hex_asn1,
|
||||
int buf_len, int result )
|
||||
void mbedtls_asn1_write_ia5_string( char * str, uint8_t * asn1,
|
||||
uint32_t asn1_len, int buf_len, int result
|
||||
)
|
||||
{
|
||||
int ret;
|
||||
unsigned char buf[150];
|
||||
unsigned char asn1[150] = { 0 };
|
||||
size_t str_len;
|
||||
size_t asn1_len;
|
||||
size_t i;
|
||||
unsigned char *p;
|
||||
|
||||
memset( buf, GUARD_VAL, sizeof( buf ) );
|
||||
|
||||
str_len = strlen( str );
|
||||
asn1_len = unhexify( asn1, hex_asn1 );
|
||||
|
||||
p = buf + GUARD_LEN + buf_len;
|
||||
|
||||
|
@ -79,7 +71,6 @@ void mbedtls_asn1_write_ia5_string( char *str, char *hex_asn1,
|
|||
|
||||
if( result >= 0 )
|
||||
{
|
||||
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 );
|
||||
|
@ -88,20 +79,16 @@ void mbedtls_asn1_write_ia5_string( char *str, char *hex_asn1,
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_asn1_write_len( int len, char *check_str, int buf_len,
|
||||
int result )
|
||||
void mbedtls_asn1_write_len( int len, uint8_t * asn1, uint32_t asn1_len,
|
||||
int buf_len, int result )
|
||||
{
|
||||
int ret;
|
||||
unsigned char buf[150];
|
||||
unsigned char asn1[150];
|
||||
unsigned char *p;
|
||||
size_t asn1_len;
|
||||
size_t i;
|
||||
size_t read_len;
|
||||
|
||||
memset( buf, GUARD_VAL, sizeof( buf ) );
|
||||
memset( asn1, 0, sizeof( asn1 ) );
|
||||
asn1_len = unhexify( asn1, check_str );
|
||||
|
||||
p = buf + GUARD_LEN + buf_len;
|
||||
|
||||
|
@ -118,7 +105,6 @@ void mbedtls_asn1_write_len( int len, char *check_str, int buf_len,
|
|||
|
||||
if( result >= 0 )
|
||||
{
|
||||
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 );
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_base64_encode( char *src_string, char *dst_string, int dst_buf_size,
|
||||
int result )
|
||||
void mbedtls_base64_encode( char * src_string, char * dst_string,
|
||||
int dst_buf_size, int result )
|
||||
{
|
||||
unsigned char src_str[1000];
|
||||
unsigned char dst_str[1000];
|
||||
|
@ -28,7 +28,7 @@ void mbedtls_base64_encode( char *src_string, char *dst_string, int dst_buf_size
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_base64_decode( char *src_string, char *dst_string, int result )
|
||||
void mbedtls_base64_decode( char * src_string, char * dst_string, int result )
|
||||
{
|
||||
unsigned char src_str[1000];
|
||||
unsigned char dst_str[1000];
|
||||
|
@ -49,7 +49,7 @@ 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( char * src_hex, char * dst, int dst_buf_size,
|
||||
int result )
|
||||
{
|
||||
unsigned char *src = NULL, *res = NULL;
|
||||
|
@ -72,7 +72,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void base64_decode_hex( char *src, char *dst_hex, int dst_buf_size,
|
||||
void base64_decode_hex( char * src, char * dst_hex, int dst_buf_size,
|
||||
int result )
|
||||
{
|
||||
unsigned char *dst = NULL, *res = NULL;
|
||||
|
@ -96,7 +96,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void base64_decode_hex_src( char *src_hex, char *dst_ref, int result )
|
||||
void base64_decode_hex_src( char * src_hex, char * dst_ref, int result )
|
||||
{
|
||||
unsigned char dst[1000] = { 0 };
|
||||
unsigned char *src;
|
||||
|
@ -117,7 +117,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void base64_selftest()
|
||||
void base64_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_base64_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -8,32 +8,24 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void blowfish_encrypt_ecb( char *hex_key_string, char *hex_src_string,
|
||||
char *hex_dst_string, int setkey_result )
|
||||
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 )
|
||||
{
|
||||
unsigned char key_str[100];
|
||||
unsigned char src_str[100];
|
||||
unsigned char dst_str[100];
|
||||
unsigned char output[100];
|
||||
mbedtls_blowfish_context ctx;
|
||||
int key_len;
|
||||
|
||||
memset(key_str, 0x00, 100);
|
||||
memset(src_str, 0x00, 100);
|
||||
memset(dst_str, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
mbedtls_blowfish_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( src_str, hex_src_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_blowfish_setkey( &ctx, key_str, key_len * 8 ) == setkey_result );
|
||||
if( setkey_result == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_blowfish_crypt_ecb( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, src_str, output ) == 0 );
|
||||
hexify( dst_str, output, 8 );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -42,32 +34,24 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void blowfish_decrypt_ecb( char *hex_key_string, char *hex_src_string,
|
||||
char *hex_dst_string, int setkey_result )
|
||||
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 )
|
||||
{
|
||||
unsigned char key_str[100];
|
||||
unsigned char src_str[100];
|
||||
unsigned char dst_str[100];
|
||||
unsigned char output[100];
|
||||
mbedtls_blowfish_context ctx;
|
||||
int key_len;
|
||||
|
||||
memset(key_str, 0x00, 100);
|
||||
memset(src_str, 0x00, 100);
|
||||
memset(dst_str, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
mbedtls_blowfish_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( src_str, hex_src_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_blowfish_setkey( &ctx, key_str, key_len * 8 ) == setkey_result );
|
||||
if( setkey_result == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_blowfish_crypt_ecb( &ctx, MBEDTLS_BLOWFISH_DECRYPT, src_str, output ) == 0 );
|
||||
hexify( dst_str, output, 8 );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -76,37 +60,26 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void blowfish_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string,
|
||||
int cbc_result )
|
||||
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 )
|
||||
{
|
||||
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_blowfish_context ctx;
|
||||
int key_len, data_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_blowfish_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
data_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
mbedtls_blowfish_setkey( &ctx, key_str, key_len * 8 );
|
||||
|
||||
TEST_ASSERT( mbedtls_blowfish_crypt_cbc( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, data_len , iv_str, src_str, output ) == cbc_result );
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
hexify( dst_str, output, data_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, data_len, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -115,36 +88,25 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void blowfish_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string,
|
||||
int cbc_result )
|
||||
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 )
|
||||
{
|
||||
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_blowfish_context ctx;
|
||||
int key_len, data_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_blowfish_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
data_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
if( cbc_result == 0)
|
||||
{
|
||||
hexify( dst_str, output, data_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, data_len, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -153,34 +115,24 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void blowfish_encrypt_cfb64( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string )
|
||||
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 )
|
||||
{
|
||||
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_blowfish_context ctx;
|
||||
size_t iv_offset = 0;
|
||||
int key_len, 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_blowfish_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
hexify( dst_str, output, src_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_blowfish_free( &ctx );
|
||||
|
@ -188,34 +140,24 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void blowfish_decrypt_cfb64( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string )
|
||||
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 )
|
||||
{
|
||||
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_blowfish_context ctx;
|
||||
size_t iv_offset = 0;
|
||||
int key_len, 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_blowfish_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
hexify( dst_str, output, src_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_blowfish_free( &ctx );
|
||||
|
@ -223,36 +165,26 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
|
||||
void blowfish_encrypt_ctr( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string )
|
||||
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 )
|
||||
{
|
||||
unsigned char key_str[100];
|
||||
unsigned char iv_str[100];
|
||||
unsigned char stream_str[100];
|
||||
unsigned char src_str[100];
|
||||
unsigned char dst_str[100];
|
||||
unsigned char output[100];
|
||||
mbedtls_blowfish_context ctx;
|
||||
size_t iv_offset = 0;
|
||||
int key_len, src_len;
|
||||
|
||||
memset(key_str, 0x00, 100);
|
||||
memset(iv_str, 0x00, 100);
|
||||
memset(stream_str, 0x00, 100);
|
||||
memset(src_str, 0x00, 100);
|
||||
memset(dst_str, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
mbedtls_blowfish_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
hexify( dst_str, output, src_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_blowfish_free( &ctx );
|
||||
|
|
|
@ -8,32 +8,24 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void camellia_encrypt_ecb( char *hex_key_string, char *hex_src_string,
|
||||
char *hex_dst_string, int setkey_result )
|
||||
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 )
|
||||
{
|
||||
unsigned char key_str[100];
|
||||
unsigned char src_str[100];
|
||||
unsigned char dst_str[100];
|
||||
unsigned char output[100];
|
||||
mbedtls_camellia_context ctx;
|
||||
int key_len;
|
||||
|
||||
memset(key_str, 0x00, 100);
|
||||
memset(src_str, 0x00, 100);
|
||||
memset(dst_str, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
mbedtls_camellia_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( src_str, hex_src_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == setkey_result );
|
||||
if( setkey_result == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str, output ) == 0 );
|
||||
hexify( dst_str, output, 16 );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -42,32 +34,24 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void camellia_decrypt_ecb( char *hex_key_string, char *hex_src_string,
|
||||
char *hex_dst_string, int setkey_result )
|
||||
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 )
|
||||
{
|
||||
unsigned char key_str[100];
|
||||
unsigned char src_str[100];
|
||||
unsigned char dst_str[100];
|
||||
unsigned char output[100];
|
||||
mbedtls_camellia_context ctx;
|
||||
int key_len;
|
||||
|
||||
memset(key_str, 0x00, 100);
|
||||
memset(src_str, 0x00, 100);
|
||||
memset(dst_str, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
mbedtls_camellia_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( src_str, hex_src_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_camellia_setkey_dec( &ctx, key_str, key_len * 8 ) == setkey_result );
|
||||
if( setkey_result == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str, output ) == 0 );
|
||||
hexify( dst_str, output, 16 );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -76,36 +60,25 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void camellia_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string,
|
||||
int cbc_result )
|
||||
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 )
|
||||
{
|
||||
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_camellia_context ctx;
|
||||
int key_len, data_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_camellia_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
data_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
hexify( dst_str, output, data_len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, data_len, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -114,36 +87,25 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void camellia_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string,
|
||||
int cbc_result )
|
||||
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 )
|
||||
{
|
||||
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_camellia_context ctx;
|
||||
int key_len, data_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_camellia_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
data_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
hexify( dst_str, output, data_len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, data_len, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -152,34 +114,24 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void camellia_encrypt_cfb128( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string )
|
||||
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 )
|
||||
{
|
||||
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_camellia_context ctx;
|
||||
size_t iv_offset = 0;
|
||||
int key_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_camellia_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
hexify( dst_str, output, 16 );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_camellia_free( &ctx );
|
||||
|
@ -187,34 +139,24 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
||||
void camellia_decrypt_cfb128( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string )
|
||||
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 )
|
||||
{
|
||||
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_camellia_context ctx;
|
||||
size_t iv_offset = 0;
|
||||
int key_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_camellia_init( &ctx );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
unhexify( src_str, hex_src_string );
|
||||
|
||||
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 );
|
||||
hexify( dst_str, output, 16 );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, 16, hex_dst_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_camellia_free( &ctx );
|
||||
|
@ -222,7 +164,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void camellia_selftest()
|
||||
void camellia_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_camellia_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST:MBEDTLS_AES_C */
|
||||
void mbedtls_ccm_self_test( )
|
||||
void mbedtls_ccm_self_test( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_ccm_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
@ -116,32 +116,19 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_ccm_encrypt_and_tag( int cipher_id,
|
||||
char *key_hex, char *msg_hex,
|
||||
char *iv_hex, char *add_hex,
|
||||
char *result_hex )
|
||||
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 )
|
||||
{
|
||||
unsigned char key[32];
|
||||
unsigned char msg[50];
|
||||
unsigned char iv[13];
|
||||
unsigned char add[32];
|
||||
unsigned char result[50];
|
||||
mbedtls_ccm_context ctx;
|
||||
size_t key_len, msg_len, iv_len, add_len, tag_len, result_len;
|
||||
size_t tag_len;
|
||||
|
||||
mbedtls_ccm_init( &ctx );
|
||||
|
||||
memset( key, 0x00, sizeof( key ) );
|
||||
memset( msg, 0x00, sizeof( msg ) );
|
||||
memset( iv, 0x00, sizeof( iv ) );
|
||||
memset( add, 0x00, sizeof( add ) );
|
||||
memset( result, 0x00, sizeof( result ) );
|
||||
|
||||
key_len = unhexify( key, key_hex );
|
||||
msg_len = unhexify( msg, msg_hex );
|
||||
iv_len = unhexify( iv, iv_hex );
|
||||
add_len = unhexify( add, add_hex );
|
||||
result_len = unhexify( result, result_hex );
|
||||
tag_len = result_len - msg_len;
|
||||
|
||||
TEST_ASSERT( mbedtls_ccm_setkey( &ctx, cipher_id, key, key_len * 8 ) == 0 );
|
||||
|
@ -161,38 +148,24 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_ccm_auth_decrypt( int cipher_id,
|
||||
char *key_hex, char *msg_hex,
|
||||
char *iv_hex, char *add_hex,
|
||||
int tag_len, char *result_hex )
|
||||
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,
|
||||
uint8_t * result, uint32_t result_len )
|
||||
{
|
||||
unsigned char key[32];
|
||||
unsigned char msg[50];
|
||||
unsigned char iv[13];
|
||||
unsigned char add[32];
|
||||
unsigned char tag[16];
|
||||
unsigned char result[50];
|
||||
mbedtls_ccm_context ctx;
|
||||
size_t key_len, msg_len, iv_len, add_len, result_len;
|
||||
int ret;
|
||||
|
||||
mbedtls_ccm_init( &ctx );
|
||||
|
||||
memset( key, 0x00, sizeof( key ) );
|
||||
memset( msg, 0x00, sizeof( msg ) );
|
||||
memset( iv, 0x00, sizeof( iv ) );
|
||||
memset( add, 0x00, sizeof( add ) );
|
||||
memset( tag, 0x00, sizeof( tag ) );
|
||||
memset( result, 0x00, sizeof( result ) );
|
||||
|
||||
key_len = unhexify( key, key_hex );
|
||||
msg_len = unhexify( msg, msg_hex );
|
||||
iv_len = unhexify( iv, iv_hex );
|
||||
add_len = unhexify( add, add_hex );
|
||||
msg_len -= tag_len;
|
||||
memcpy( tag, msg + msg_len, tag_len );
|
||||
|
||||
if( strcmp( "FAIL", result_hex ) == 0 )
|
||||
if( strcmp( "FAIL", (char *)result ) == 0 )
|
||||
{
|
||||
ret = MBEDTLS_ERR_CCM_AUTH_FAILED;
|
||||
result_len = -1;
|
||||
|
@ -200,7 +173,6 @@ void mbedtls_ccm_auth_decrypt( int cipher_id,
|
|||
else
|
||||
{
|
||||
ret = 0;
|
||||
result_len = unhexify( result, result_hex );
|
||||
}
|
||||
|
||||
TEST_ASSERT( mbedtls_ccm_setkey( &ctx, cipher_id, key, key_len * 8 ) == 0 );
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -9,14 +9,14 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void mbedtls_cmac_self_test( )
|
||||
void mbedtls_cmac_self_test( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_cmac_self_test( 1 ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_cmac_null_args( )
|
||||
void mbedtls_cmac_null_args( )
|
||||
{
|
||||
mbedtls_cipher_context_t ctx;
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
|
@ -99,8 +99,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_cmac_setkey( int cipher_type, int key_size,
|
||||
int result )
|
||||
void mbedtls_cmac_setkey( int cipher_type, int key_size, int result )
|
||||
{
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
unsigned char key[32];
|
||||
|
@ -120,32 +119,22 @@ void mbedtls_cmac_setkey( int cipher_type, int key_size,
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_cmac_multiple_blocks( int cipher_type,
|
||||
char *key_string, int keybits,
|
||||
int block_size,
|
||||
char *block1_string, int block1_len,
|
||||
char *block2_string, int block2_len,
|
||||
char *block3_string, int block3_len,
|
||||
char *block4_string, int block4_len,
|
||||
char *expected_result_string )
|
||||
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_len, int block1_len,
|
||||
uint8_t * block2, uint32_t block2_len,
|
||||
int block2_len, uint8_t * block3,
|
||||
uint32_t block3_len, int block3_len,
|
||||
uint8_t * block4, uint32_t block4_len,
|
||||
int block4_len, uint8_t * expected_result,
|
||||
uint32_t expected_result_len )
|
||||
{
|
||||
unsigned char key[100];
|
||||
unsigned char block1[100];
|
||||
unsigned char block2[100];
|
||||
unsigned char block3[100];
|
||||
unsigned char block4[100];
|
||||
unsigned char expected_result[100];
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
mbedtls_cipher_context_t ctx;
|
||||
unsigned char output[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
||||
|
||||
/* Convert the test parameters to binary data */
|
||||
unhexify( key, key_string );
|
||||
unhexify( block1, block1_string );
|
||||
unhexify( block2, block2_string );
|
||||
unhexify( block3, block3_string );
|
||||
unhexify( block4, block4_string );
|
||||
unhexify( expected_result, expected_result_string );
|
||||
|
||||
mbedtls_cipher_init( &ctx );
|
||||
|
||||
|
@ -198,41 +187,40 @@ exit:
|
|||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_cmac_multiple_operations_same_key( int cipher_type,
|
||||
char *key_string, int keybits,
|
||||
int block_size,
|
||||
char *block_a1_string, int block_a1_len,
|
||||
char *block_a2_string, int block_a2_len,
|
||||
char *block_a3_string, int block_a3_len,
|
||||
char *expected_result_a_string,
|
||||
char *block_b1_string, int block_b1_len,
|
||||
char *block_b2_string, int block_b2_len,
|
||||
char *block_b3_string, int block_b3_len,
|
||||
char *expected_result_b_string )
|
||||
uint8_t * key,
|
||||
uint32_t key_len, int keybits,
|
||||
int block_size,
|
||||
uint8_t * block_a1,
|
||||
uint32_t block_a1_len,
|
||||
int block_a1_len,
|
||||
uint8_t * block_a2,
|
||||
uint32_t block_a2_len,
|
||||
int block_a2_len,
|
||||
uint8_t * block_a3,
|
||||
uint32_t block_a3_len,
|
||||
int block_a3_len,
|
||||
uint8_t * expected_result_a,
|
||||
uint32_t expected_result_a_len,
|
||||
uint8_t * block_b1,
|
||||
uint32_t block_b1_len,
|
||||
int block_b1_len,
|
||||
uint8_t * block_b2,
|
||||
uint32_t block_b2_len,
|
||||
int block_b2_len,
|
||||
uint8_t * block_b3,
|
||||
uint32_t block_b3_len,
|
||||
int block_b3_len,
|
||||
uint8_t * expected_result_b,
|
||||
uint32_t expected_result_b_len
|
||||
)
|
||||
{
|
||||
unsigned char key[100];
|
||||
unsigned char block_a1[100];
|
||||
unsigned char block_a2[100];
|
||||
unsigned char block_a3[100];
|
||||
unsigned char block_b1[100];
|
||||
unsigned char block_b2[100];
|
||||
unsigned char block_b3[100];
|
||||
unsigned char expected_result_a[100], expected_result_b[100];
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
mbedtls_cipher_context_t ctx;
|
||||
unsigned char output[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
||||
|
||||
/* Convert the test parameters to binary data */
|
||||
unhexify( key, key_string );
|
||||
unhexify( block_a1, block_a1_string );
|
||||
unhexify( block_a2, block_a2_string );
|
||||
unhexify( block_a3, block_a3_string );
|
||||
|
||||
unhexify( block_b1, block_b1_string );
|
||||
unhexify( block_b2, block_b2_string );
|
||||
unhexify( block_b3, block_b3_string );
|
||||
|
||||
unhexify( expected_result_a, expected_result_a_string );
|
||||
unhexify( expected_result_b, expected_result_b_string );
|
||||
|
||||
mbedtls_cipher_init( &ctx );
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ static int mbedtls_test_entropy_func( void *data, unsigned char *buf, size_t len
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ctr_drbg_special_behaviours( )
|
||||
void ctr_drbg_special_behaviours( )
|
||||
{
|
||||
mbedtls_ctr_drbg_context ctx;
|
||||
unsigned char output[512];
|
||||
|
@ -51,26 +51,17 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ctr_drbg_validate_pr( char *add_init_string, char *entropy_string,
|
||||
char *add1_string, char *add2_string,
|
||||
char *result_str )
|
||||
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 )
|
||||
{
|
||||
unsigned char entropy[512];
|
||||
unsigned char add_init[512];
|
||||
unsigned char add1[512];
|
||||
unsigned char add2[512];
|
||||
mbedtls_ctr_drbg_context ctx;
|
||||
unsigned char buf[512];
|
||||
unsigned char output_str[512];
|
||||
int add_init_len, add1_len, add2_len;
|
||||
|
||||
mbedtls_ctr_drbg_init( &ctx );
|
||||
memset( output_str, 0, 512 );
|
||||
|
||||
unhexify( entropy, entropy_string );
|
||||
add_init_len = unhexify( add_init, add_init_string );
|
||||
add1_len = unhexify( add1, add1_string );
|
||||
add2_len = unhexify( add2, add2_string );
|
||||
|
||||
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 );
|
||||
|
@ -78,8 +69,7 @@ void ctr_drbg_validate_pr( char *add_init_string, char *entropy_string,
|
|||
|
||||
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 );
|
||||
hexify( output_str, buf, 16 );
|
||||
TEST_ASSERT( strcmp( (char *) output_str, result_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( buf, result_str, 16, result_str_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_ctr_drbg_free( &ctx );
|
||||
|
@ -87,28 +77,18 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ctr_drbg_validate_nopr( char *add_init_string, char *entropy_string,
|
||||
char *add1_string, char *add_reseed_string,
|
||||
char *add2_string, char *result_str )
|
||||
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 )
|
||||
{
|
||||
unsigned char entropy[512];
|
||||
unsigned char add_init[512];
|
||||
unsigned char add1[512];
|
||||
unsigned char add_reseed[512];
|
||||
unsigned char add2[512];
|
||||
mbedtls_ctr_drbg_context ctx;
|
||||
unsigned char buf[512];
|
||||
unsigned char output_str[512];
|
||||
int add_init_len, add1_len, add_reseed_len, add2_len;
|
||||
|
||||
mbedtls_ctr_drbg_init( &ctx );
|
||||
memset( output_str, 0, 512 );
|
||||
|
||||
unhexify( entropy, entropy_string );
|
||||
add_init_len = unhexify( add_init, add_init_string );
|
||||
add1_len = unhexify( add1, add1_string );
|
||||
add_reseed_len = unhexify( add_reseed, add_reseed_string );
|
||||
add2_len = unhexify( add2, add2_string );
|
||||
|
||||
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 );
|
||||
|
@ -116,8 +96,7 @@ void ctr_drbg_validate_nopr( char *add_init_string, char *entropy_string,
|
|||
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 );
|
||||
hexify( output_str, buf, 16 );
|
||||
TEST_ASSERT( strcmp( (char *) output_str, result_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( buf, result_str, 16, result_str_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_ctr_drbg_free( &ctx );
|
||||
|
@ -125,7 +104,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ctr_drbg_entropy_usage( )
|
||||
void ctr_drbg_entropy_usage( )
|
||||
{
|
||||
unsigned char out[16];
|
||||
unsigned char add[16];
|
||||
|
@ -204,7 +183,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
||||
void ctr_drbg_seed_file( char *path, int ret )
|
||||
void ctr_drbg_seed_file( char * path, int ret )
|
||||
{
|
||||
mbedtls_ctr_drbg_context ctx;
|
||||
|
||||
|
@ -220,7 +199,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void ctr_drbg_selftest( )
|
||||
void ctr_drbg_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_ctr_drbg_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ void string_debug(void *data, int level, const char *file, int line, const char
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void debug_print_msg_threshold( int threshold, int level, char *file, int line,
|
||||
char *result_str )
|
||||
void debug_print_msg_threshold( int threshold, int level, char * file,
|
||||
int line, char * result_str )
|
||||
{
|
||||
mbedtls_ssl_context ssl;
|
||||
mbedtls_ssl_config conf;
|
||||
|
@ -77,8 +77,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_debug_print_ret( char *file, int line, char *text, int value,
|
||||
char *result_str )
|
||||
void mbedtls_debug_print_ret( char * file, int line, char * text, int value,
|
||||
char * result_str )
|
||||
{
|
||||
mbedtls_ssl_context ssl;
|
||||
mbedtls_ssl_config conf;
|
||||
|
@ -104,28 +104,24 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_debug_print_buf( char *file, int line, char *text,
|
||||
char *data_string, char *result_str )
|
||||
void mbedtls_debug_print_buf( char * file, int line, char * text,
|
||||
uint8_t * data, uint32_t data_len,
|
||||
char * result_str )
|
||||
{
|
||||
unsigned char data[10000];
|
||||
mbedtls_ssl_context ssl;
|
||||
mbedtls_ssl_config conf;
|
||||
struct buffer_data buffer;
|
||||
size_t data_len;
|
||||
|
||||
mbedtls_ssl_init( &ssl );
|
||||
mbedtls_ssl_config_init( &conf );
|
||||
memset( &data, 0, sizeof( data ) );
|
||||
memset( buffer.buf, 0, 2000 );
|
||||
buffer.ptr = buffer.buf;
|
||||
|
||||
data_len = unhexify( data, data_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
|
||||
|
||||
mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
|
||||
|
||||
mbedtls_debug_print_buf( &ssl, 0, file, line, text, data, data_len );
|
||||
|
||||
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
||||
|
||||
|
@ -136,8 +132,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
|
||||
void mbedtls_debug_print_crt( char *crt_file, char *file, int line,
|
||||
char *prefix, char *result_str )
|
||||
void mbedtls_debug_print_crt( char * crt_file, char * file, int line,
|
||||
char * prefix, char * result_str )
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
mbedtls_ssl_context ssl;
|
||||
|
@ -167,8 +163,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_BIGNUM_C */
|
||||
void mbedtls_debug_print_mpi( int radix, char *value, char *file, int line,
|
||||
char *prefix, char *result_str )
|
||||
void mbedtls_debug_print_mpi( int radix, char * value, char * file, int line,
|
||||
char * prefix, char * result_str )
|
||||
{
|
||||
mbedtls_ssl_context ssl;
|
||||
mbedtls_ssl_config conf;
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
||||
void dhm_file( char *filename, char *p, char *g, int len )
|
||||
void dhm_file( char * filename, char * p, char * g, int len )
|
||||
{
|
||||
mbedtls_dhm_context ctx;
|
||||
mbedtls_mpi P, G;
|
||||
|
@ -124,7 +124,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void dhm_selftest()
|
||||
void dhm_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_dhm_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -43,15 +43,15 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecdh_primitive_testvec( int id, char *dA_str, char *xA_str, char *yA_str,
|
||||
char *dB_str, char *xB_str, char *yB_str,
|
||||
char *z_str )
|
||||
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 )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point qA, qB;
|
||||
mbedtls_mpi dA, dB, zA, zB, check;
|
||||
unsigned char rnd_buf_A[MBEDTLS_ECP_MAX_BYTES];
|
||||
unsigned char rnd_buf_B[MBEDTLS_ECP_MAX_BYTES];
|
||||
rnd_buf_info rnd_info_A, rnd_info_B;
|
||||
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
|
@ -62,7 +62,7 @@ void ecdh_primitive_testvec( int id, char *dA_str, char *xA_str, char *yA_str,
|
|||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
rnd_info_A.buf = rnd_buf_A;
|
||||
rnd_info_A.length = unhexify( rnd_buf_A, dA_str );
|
||||
rnd_info_A.length = rnd_buf_A_len;
|
||||
|
||||
/* Fix rnd_buf_A by shifting it left if necessary */
|
||||
if( grp.nbits % 8 != 0 )
|
||||
|
@ -78,7 +78,7 @@ void ecdh_primitive_testvec( int id, char *dA_str, char *xA_str, char *yA_str,
|
|||
}
|
||||
|
||||
rnd_info_B.buf = rnd_buf_B;
|
||||
rnd_info_B.length = unhexify( rnd_buf_B, dB_str );
|
||||
rnd_info_B.length = rnd_buf_B_len;
|
||||
|
||||
/* Fix rnd_buf_B by shifting it left if necessary */
|
||||
if( grp.nbits % 8 != 0 )
|
||||
|
|
|
@ -40,32 +40,29 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecdsa_prim_test_vectors( int id, char *d_str, char *xQ_str, char *yQ_str,
|
||||
char *k_str, char *hash_str, char *r_str,
|
||||
char *s_str, int result )
|
||||
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,
|
||||
int result )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point Q;
|
||||
mbedtls_mpi d, r, s, r_check, s_check;
|
||||
unsigned char hash[66], rnd_buf[66];
|
||||
size_t hlen;
|
||||
rnd_buf_info rnd_info;
|
||||
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
mbedtls_ecp_point_init( &Q );
|
||||
mbedtls_mpi_init( &d ); mbedtls_mpi_init( &r ); mbedtls_mpi_init( &s );
|
||||
mbedtls_mpi_init( &r_check ); mbedtls_mpi_init( &s_check );
|
||||
memset( hash, 0, sizeof( hash ) );
|
||||
memset( rnd_buf, 0, sizeof( rnd_buf ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_point_read_string( &Q, 16, xQ_str, yQ_str ) == 0 );
|
||||
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 );
|
||||
hlen = unhexify(hash, hash_str);
|
||||
rnd_info.buf = rnd_buf;
|
||||
rnd_info.length = unhexify( rnd_buf, k_str );
|
||||
rnd_info.length = rnd_buf_len;
|
||||
|
||||
/* Fix rnd_buf by shifting it left if necessary */
|
||||
if( grp.nbits % 8 != 0 )
|
||||
|
@ -99,8 +96,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_ECDSA_DETERMINISTIC */
|
||||
void ecdsa_det_test_vectors( int id, char *d_str, int md_alg,
|
||||
char *msg, char *r_str, char *s_str )
|
||||
void ecdsa_det_test_vectors( int id, char * d_str, int md_alg, char * msg,
|
||||
char * r_str, char * s_str )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_mpi d, r, s, r_check, s_check;
|
||||
|
|
|
@ -99,14 +99,14 @@ cleanup:
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void ecjpake_selftest()
|
||||
void ecjpake_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_ecjpake_self_test( 1 ) == 0 );
|
||||
}
|
||||
/* 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, char * data, int ref_ret )
|
||||
{
|
||||
mbedtls_ecjpake_context ctx;
|
||||
|
||||
|
@ -133,7 +133,7 @@ exit:
|
|||
/* 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( char * data, int ref_ret )
|
||||
{
|
||||
mbedtls_ecjpake_context ctx;
|
||||
|
||||
|
@ -166,7 +166,7 @@ exit:
|
|||
/* 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( char * data, int ref_ret )
|
||||
{
|
||||
mbedtls_ecjpake_context ctx;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_ecp_curve_info( int id, int tls_id, int size, char *name )
|
||||
void mbedtls_ecp_curve_info( int id, int tls_id, int size, char * name )
|
||||
{
|
||||
const mbedtls_ecp_curve_info *by_id, *by_tls, *by_name;
|
||||
|
||||
|
@ -29,7 +29,8 @@ void mbedtls_ecp_curve_info( int id, int tls_id, int size, char *name )
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecp_check_pub( int grp_id, char *x_hex, char *y_hex, char *z_hex, int ret )
|
||||
void ecp_check_pub( int grp_id, char * x_hex, char * y_hex, char * z_hex,
|
||||
int ret )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point P;
|
||||
|
@ -52,9 +53,9 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecp_test_vect( int id, char *dA_str, char *xA_str, char *yA_str,
|
||||
char *dB_str, char *xB_str, char *yB_str, char *xZ_str,
|
||||
char *yZ_str )
|
||||
void ecp_test_vect( int id, char * dA_str, char * xA_str, char * yA_str,
|
||||
char * dB_str, char * xB_str, char * yB_str,
|
||||
char * xZ_str, char * yZ_str )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point R;
|
||||
|
@ -107,8 +108,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecp_test_vec_x( int id, char *dA_hex, char *xA_hex,
|
||||
char *dB_hex, char *xB_hex, char *xS_hex )
|
||||
void ecp_test_vec_x( int id, char * dA_hex, char * xA_hex, char * dB_hex,
|
||||
char * xB_hex, char * xS_hex )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point R;
|
||||
|
@ -158,7 +159,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecp_fast_mod( int id, char *N_str )
|
||||
void ecp_fast_mod( int id, char * N_str )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_mpi N, R;
|
||||
|
@ -191,16 +192,15 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecp_write_binary( int id, char *x, char *y, char *z, int format,
|
||||
char *out, int blen, int ret )
|
||||
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 )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point P;
|
||||
unsigned char buf[256], str[512];
|
||||
unsigned char buf[256];
|
||||
size_t olen;
|
||||
|
||||
memset( buf, 0, sizeof( buf ) );
|
||||
memset( str, 0, sizeof( str ) );
|
||||
|
||||
mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &P );
|
||||
|
||||
|
@ -215,8 +215,7 @@ void ecp_write_binary( int id, char *x, char *y, char *z, int format,
|
|||
|
||||
if( ret == 0 )
|
||||
{
|
||||
hexify( str, buf, olen );
|
||||
TEST_ASSERT( strcasecmp( (char *) str, out ) == 0 );
|
||||
TEST_ASSERT( hexcmp( buf, out, olen, out_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -225,16 +224,13 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecp_read_binary( int id, char *input, char *x, char *y, char *z,
|
||||
int ret )
|
||||
void ecp_read_binary( int id, uint8_t * buf, uint32_t ilen, char * x,
|
||||
char * y, char * z, int ret )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point P;
|
||||
mbedtls_mpi X, Y, Z;
|
||||
int ilen;
|
||||
unsigned char buf[256];
|
||||
|
||||
memset( buf, 0, sizeof( buf ) );
|
||||
|
||||
mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &P );
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z );
|
||||
|
@ -245,9 +241,7 @@ void ecp_read_binary( int id, char *input, char *x, char *y, char *z,
|
|||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Z, 16, z ) == 0 );
|
||||
|
||||
ilen = unhexify( buf, input );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_point_read_binary( &grp, &P, buf, ilen ) == ret );
|
||||
|
||||
if( ret == 0 )
|
||||
{
|
||||
|
@ -263,17 +257,14 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_ecp_tls_read_point( int id, char *input, char *x, char *y, char *z,
|
||||
int ret )
|
||||
void mbedtls_ecp_tls_read_point( int id, uint8_t * buf, uint32_t ilen,
|
||||
char * x, char * y, char * z, int ret )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point P;
|
||||
mbedtls_mpi X, Y, Z;
|
||||
size_t ilen;
|
||||
unsigned char buf[256];
|
||||
const unsigned char *vbuf = buf;
|
||||
|
||||
memset( buf, 0, sizeof( buf ) );
|
||||
|
||||
mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &P );
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z );
|
||||
|
@ -284,9 +275,7 @@ void mbedtls_ecp_tls_read_point( int id, char *input, char *x, char *y, char *z,
|
|||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Z, 16, z ) == 0 );
|
||||
|
||||
ilen = unhexify( buf, input );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_tls_read_point( &grp, &P, &vbuf, ilen ) == ret );
|
||||
|
||||
if( ret == 0 )
|
||||
{
|
||||
|
@ -355,17 +344,15 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_ecp_tls_read_group( char *record, int result, int bits )
|
||||
void mbedtls_ecp_tls_read_group( uint8_t * buf, uint32_t len, int result,
|
||||
int bits )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
unsigned char buf[10];
|
||||
const unsigned char *vbuf = buf;
|
||||
int len, ret;
|
||||
int ret;
|
||||
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
memset( buf, 0x00, sizeof( buf ) );
|
||||
|
||||
len = unhexify( buf, record );
|
||||
|
||||
ret = mbedtls_ecp_tls_read_group( &grp, &vbuf, len );
|
||||
|
||||
|
@ -413,7 +400,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_ecp_check_privkey( int id, char *key_hex, int ret )
|
||||
void mbedtls_ecp_check_privkey( int id, char * key_hex, int ret )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_mpi d;
|
||||
|
@ -433,8 +420,9 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_ecp_check_pub_priv( int id_pub, char *Qx_pub, char *Qy_pub,
|
||||
int id, char *d, char *Qx, char *Qy, int ret )
|
||||
void mbedtls_ecp_check_pub_priv( int id_pub, char * Qx_pub, char * Qy_pub,
|
||||
int id, char * d, char * Qx, char * Qy,
|
||||
int ret )
|
||||
{
|
||||
mbedtls_ecp_keypair pub, prv;
|
||||
|
||||
|
@ -506,7 +494,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void ecp_selftest()
|
||||
void ecp_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_ecp_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ static int read_nv_seed( unsigned char *buf, size_t buf_len )
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
|
||||
void entropy_seed_file( char *path, int ret )
|
||||
void entropy_seed_file( char * path, int ret )
|
||||
{
|
||||
mbedtls_entropy_context ctx;
|
||||
|
||||
|
@ -140,7 +140,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void entropy_too_many_sources( )
|
||||
void entropy_too_many_sources( )
|
||||
{
|
||||
mbedtls_entropy_context ctx;
|
||||
size_t i;
|
||||
|
@ -194,7 +194,7 @@ void entropy_func_len( int len, int ret )
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void entropy_source_fail( char *path )
|
||||
void entropy_source_fail( char * path )
|
||||
{
|
||||
mbedtls_entropy_context ctx;
|
||||
int fail = -1;
|
||||
|
@ -261,7 +261,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
|
||||
void nv_seed_file_create()
|
||||
void nv_seed_file_create( )
|
||||
{
|
||||
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
|
||||
|
||||
|
@ -272,7 +272,7 @@ void nv_seed_file_create()
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO:MBEDTLS_PLATFORM_NV_SEED_ALT */
|
||||
void entropy_nv_seed_std_io()
|
||||
void entropy_nv_seed_std_io( )
|
||||
{
|
||||
unsigned char io_seed[MBEDTLS_ENTROPY_BLOCK_SIZE];
|
||||
unsigned char check_seed[MBEDTLS_ENTROPY_BLOCK_SIZE];
|
||||
|
@ -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( char *read_seed_str )
|
||||
void entropy_nv_seed( uint8_t * read_seed, uint32_t read_seed_len )
|
||||
{
|
||||
mbedtls_sha512_context accumulator;
|
||||
mbedtls_entropy_context ctx;
|
||||
|
@ -323,7 +323,6 @@ void entropy_nv_seed( char *read_seed_str )
|
|||
memset( check_entropy, 3, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||
|
||||
// Set the initial NV seed to read
|
||||
unhexify( read_seed, read_seed_str );
|
||||
memcpy( buffer_seed, read_seed, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||
|
||||
// Make sure we read/write NV seed from our buffers
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void error_strerror( int code, char *result_str )
|
||||
void error_strerror( int code, char * result_str )
|
||||
{
|
||||
char buf[500];
|
||||
|
||||
|
|
|
@ -51,49 +51,33 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void gcm_encrypt_and_tag( int cipher_id,
|
||||
char *hex_key_string, char *hex_src_string,
|
||||
char *hex_iv_string, char *hex_add_string,
|
||||
char *hex_dst_string, int tag_len_bits,
|
||||
char *hex_tag_string, int init_result )
|
||||
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 )
|
||||
{
|
||||
unsigned char key_str[128];
|
||||
unsigned char src_str[128];
|
||||
unsigned char dst_str[257];
|
||||
unsigned char iv_str[128];
|
||||
unsigned char add_str[128];
|
||||
unsigned char tag_str[128];
|
||||
unsigned char output[128];
|
||||
unsigned char tag_output[16];
|
||||
mbedtls_gcm_context ctx;
|
||||
unsigned int key_len;
|
||||
size_t pt_len, iv_len, add_len, tag_len = tag_len_bits / 8;
|
||||
size_t tag_len = tag_len_bits / 8;
|
||||
|
||||
mbedtls_gcm_init( &ctx );
|
||||
|
||||
memset(key_str, 0x00, 128);
|
||||
memset(src_str, 0x00, 128);
|
||||
memset(dst_str, 0x00, 257);
|
||||
memset(iv_str, 0x00, 128);
|
||||
memset(add_str, 0x00, 128);
|
||||
memset(tag_str, 0x00, 128);
|
||||
memset(output, 0x00, 128);
|
||||
memset(tag_output, 0x00, 16);
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
pt_len = unhexify( src_str, hex_src_string );
|
||||
iv_len = unhexify( iv_str, hex_iv_string );
|
||||
add_len = unhexify( add_str, hex_add_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str, key_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 );
|
||||
hexify( dst_str, output, pt_len );
|
||||
hexify( tag_str, tag_output, tag_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( strcmp( (char *) tag_str, hex_tag_string ) == 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 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -102,39 +86,24 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void gcm_decrypt_and_verify( int cipher_id,
|
||||
char *hex_key_string, char *hex_src_string,
|
||||
char *hex_iv_string, char *hex_add_string,
|
||||
int tag_len_bits, char *hex_tag_string,
|
||||
char *pt_result, int init_result )
|
||||
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,
|
||||
uint8_t * pt_result, uint32_t pt_result_len,
|
||||
int init_result )
|
||||
{
|
||||
unsigned char key_str[128];
|
||||
unsigned char src_str[128];
|
||||
unsigned char dst_str[257];
|
||||
unsigned char iv_str[128];
|
||||
unsigned char add_str[128];
|
||||
unsigned char tag_str[128];
|
||||
unsigned char output[128];
|
||||
mbedtls_gcm_context ctx;
|
||||
unsigned int key_len;
|
||||
size_t pt_len, iv_len, add_len, tag_len = tag_len_bits / 8;
|
||||
int ret;
|
||||
size_t tag_len = tag_len_bits / 8;
|
||||
|
||||
mbedtls_gcm_init( &ctx );
|
||||
|
||||
memset(key_str, 0x00, 128);
|
||||
memset(src_str, 0x00, 128);
|
||||
memset(dst_str, 0x00, 257);
|
||||
memset(iv_str, 0x00, 128);
|
||||
memset(add_str, 0x00, 128);
|
||||
memset(tag_str, 0x00, 128);
|
||||
memset(output, 0x00, 128);
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
pt_len = unhexify( src_str, hex_src_string );
|
||||
iv_len = unhexify( iv_str, hex_iv_string );
|
||||
add_len = unhexify( add_str, hex_add_string );
|
||||
unhexify( tag_str, hex_tag_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str, key_len * 8 ) == init_result );
|
||||
if( init_result == 0 )
|
||||
|
@ -148,9 +117,8 @@ void gcm_decrypt_and_verify( int cipher_id,
|
|||
else
|
||||
{
|
||||
TEST_ASSERT( ret == 0 );
|
||||
hexify( dst_str, output, pt_len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, pt_result ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, pt_result, pt_len, pt_result_len ) == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,7 +128,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void gcm_selftest()
|
||||
void gcm_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_gcm_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
||||
void hmac_drbg_seed_file( int md_alg, char *path, int ret )
|
||||
void hmac_drbg_seed_file( int md_alg, char * path, int ret )
|
||||
{
|
||||
const mbedtls_md_info_t *md_info;
|
||||
mbedtls_hmac_drbg_context ctx;
|
||||
|
@ -161,32 +161,23 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void hmac_drbg_no_reseed( int md_alg,
|
||||
char *entropy_hex, char *custom_hex,
|
||||
char *add1_hex, char *add2_hex,
|
||||
char *output_hex )
|
||||
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 )
|
||||
{
|
||||
unsigned char data[1024];
|
||||
unsigned char entropy[512];
|
||||
unsigned char custom[512];
|
||||
unsigned char add1[512];
|
||||
unsigned char add2[512];
|
||||
unsigned char output[512];
|
||||
unsigned char my_output[512];
|
||||
size_t custom_len, add1_len, add2_len, out_len;
|
||||
entropy_ctx p_entropy;
|
||||
const mbedtls_md_info_t *md_info;
|
||||
mbedtls_hmac_drbg_context ctx;
|
||||
|
||||
mbedtls_hmac_drbg_init( &ctx );
|
||||
memset( my_output, 0, sizeof my_output );
|
||||
|
||||
custom_len = unhexify( custom, custom_hex );
|
||||
add1_len = unhexify( add1, add1_hex );
|
||||
add2_len = unhexify( add2, add2_hex );
|
||||
out_len = unhexify( output, output_hex );
|
||||
p_entropy.len = unhexify( entropy, entropy_hex );
|
||||
p_entropy.p = entropy;
|
||||
p_entropy.len = entropy_len;
|
||||
|
||||
md_info = mbedtls_md_info_from_type( md_alg );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
@ -221,33 +212,21 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void hmac_drbg_nopr( int md_alg,
|
||||
char *entropy_hex, char *custom_hex,
|
||||
char *add1_hex, char *add2_hex, char *add3_hex,
|
||||
char *output_hex )
|
||||
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 )
|
||||
{
|
||||
unsigned char entropy[512];
|
||||
unsigned char custom[512];
|
||||
unsigned char add1[512];
|
||||
unsigned char add2[512];
|
||||
unsigned char add3[512];
|
||||
unsigned char output[512];
|
||||
unsigned char my_output[512];
|
||||
size_t custom_len, add1_len, add2_len, add3_len, out_len;
|
||||
entropy_ctx p_entropy;
|
||||
const mbedtls_md_info_t *md_info;
|
||||
mbedtls_hmac_drbg_context ctx;
|
||||
|
||||
mbedtls_hmac_drbg_init( &ctx );
|
||||
memset( my_output, 0, sizeof my_output );
|
||||
|
||||
custom_len = unhexify( custom, custom_hex );
|
||||
add1_len = unhexify( add1, add1_hex );
|
||||
add2_len = unhexify( add2, add2_hex );
|
||||
add3_len = unhexify( add3, add3_hex );
|
||||
out_len = unhexify( output, output_hex );
|
||||
p_entropy.len = unhexify( entropy, entropy_hex );
|
||||
p_entropy.p = entropy;
|
||||
p_entropy.len = entropy_len;
|
||||
|
||||
md_info = mbedtls_md_info_from_type( md_alg );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
@ -268,31 +247,20 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void hmac_drbg_pr( int md_alg,
|
||||
char *entropy_hex, char *custom_hex,
|
||||
char *add1_hex, char *add2_hex,
|
||||
char *output_hex )
|
||||
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 )
|
||||
{
|
||||
unsigned char entropy[512];
|
||||
unsigned char custom[512];
|
||||
unsigned char add1[512];
|
||||
unsigned char add2[512];
|
||||
unsigned char output[512];
|
||||
unsigned char my_output[512];
|
||||
size_t custom_len, add1_len, add2_len, out_len;
|
||||
entropy_ctx p_entropy;
|
||||
const mbedtls_md_info_t *md_info;
|
||||
mbedtls_hmac_drbg_context ctx;
|
||||
|
||||
mbedtls_hmac_drbg_init( &ctx );
|
||||
memset( my_output, 0, sizeof my_output );
|
||||
|
||||
custom_len = unhexify( custom, custom_hex );
|
||||
add1_len = unhexify( add1, add1_hex );
|
||||
add2_len = unhexify( add2, add2_hex );
|
||||
out_len = unhexify( output, output_hex );
|
||||
p_entropy.len = unhexify( entropy, entropy_hex );
|
||||
p_entropy.p = entropy;
|
||||
p_entropy.len = entropy_len;
|
||||
|
||||
md_info = mbedtls_md_info_from_type( md_alg );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
@ -313,7 +281,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void hmac_drbg_selftest( )
|
||||
void hmac_drbg_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_md_process( )
|
||||
void mbedtls_md_process( )
|
||||
{
|
||||
const int *md_type_ptr;
|
||||
const mbedtls_md_info_t *info;
|
||||
|
@ -40,7 +40,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_null_args( )
|
||||
void md_null_args( )
|
||||
{
|
||||
mbedtls_md_context_t ctx;
|
||||
const mbedtls_md_info_t *info = mbedtls_md_info_from_type( *( mbedtls_md_list() ) );
|
||||
|
@ -103,7 +103,7 @@ void md_null_args( )
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_info( int md_type, char *md_name, int md_size )
|
||||
void md_info( int md_type, char * md_name, int md_size )
|
||||
{
|
||||
const mbedtls_md_info_t *md_info;
|
||||
const int *md_type_ptr;
|
||||
|
@ -126,17 +126,16 @@ void md_info( int md_type, char *md_name, int md_size )
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_text( char *text_md_name, char *text_src_string, char *hex_hash_string )
|
||||
void md_text( char * text_md_name, char * text_src_string,
|
||||
uint8_t * hex_hash_string, uint32_t hex_hash_string_len )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[1000];
|
||||
unsigned char hash_str[1000];
|
||||
unsigned char output[100];
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( src_str, 0x00, 1000 );
|
||||
memset( hash_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) src_str, text_src_string, sizeof( src_str ) - 1 );
|
||||
|
@ -145,47 +144,40 @@ void md_text( char *text_md_name, char *text_src_string, char *hex_hash_string )
|
|||
TEST_ASSERT( md_info != NULL );
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md( md_info, src_str, strlen( (char *) src_str ), output ) );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, mbedtls_md_get_size( md_info ), hex_hash_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_hex( char *text_md_name, char *hex_src_string, char *hex_hash_string )
|
||||
void md_hex( char * text_md_name, uint8_t * src_str, uint32_t src_len,
|
||||
uint8_t * hex_hash_string, uint32_t hex_hash_string_len )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[10000];
|
||||
unsigned char hash_str[10000];
|
||||
unsigned char output[100];
|
||||
int src_len;
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( src_str, 0x00, 10000 );
|
||||
memset( hash_str, 0x00, 10000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
|
||||
md_info = mbedtls_md_info_from_string( md_name );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
TEST_ASSERT ( 0 == mbedtls_md( md_info, src_str, src_len, output ) );
|
||||
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string,
|
||||
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,
|
||||
char *hex_hash_string )
|
||||
void md_text_multi( char * text_md_name, char * text_src_string,
|
||||
uint8_t * hex_hash_string, uint32_t hex_hash_string_len )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[1000];
|
||||
unsigned char hash_str[1000];
|
||||
unsigned char output[100];
|
||||
int halfway, len;
|
||||
|
||||
|
@ -197,7 +189,6 @@ void md_text_multi( char *text_md_name, char *text_src_string,
|
|||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( src_str, 0x00, 1000 );
|
||||
memset( hash_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
|
||||
|
@ -217,17 +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 ) );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string,
|
||||
mbedtls_md_get_size( md_info ), hex_hash_string_len) == 0 );
|
||||
|
||||
/* Test clone */
|
||||
memset( hash_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx_copy, src_str + halfway, len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx_copy, output ) );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, mbedtls_md_get_size( md_info ), hex_hash_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_md_free( &ctx );
|
||||
|
@ -236,23 +225,19 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_hex_multi( char *text_md_name, char *hex_src_string,
|
||||
char *hex_hash_string )
|
||||
void md_hex_multi( char * text_md_name, uint8_t * src_str, uint32_t src_len,
|
||||
uint8_t * hex_hash_string, uint32_t hex_hash_string_len )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[10000];
|
||||
unsigned char hash_str[10000];
|
||||
unsigned char output[100];
|
||||
int src_len, halfway;
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
mbedtls_md_context_t ctx, ctx_copy;
|
||||
int halfway;
|
||||
|
||||
mbedtls_md_init( &ctx );
|
||||
mbedtls_md_init( &ctx_copy );
|
||||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( src_str, 0x00, 10000 );
|
||||
memset( hash_str, 0x00, 10000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
|
||||
|
@ -261,7 +246,6 @@ void md_hex_multi( char *text_md_name, char *hex_src_string,
|
|||
TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx, md_info, 0 ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx_copy, md_info, 0 ) );
|
||||
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
halfway = src_len / 2;
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_starts( &ctx ) );
|
||||
|
@ -271,17 +255,14 @@ void md_hex_multi( char *text_md_name, char *hex_src_string,
|
|||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str + halfway, src_len - halfway) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx, output ) );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, mbedtls_md_get_size( md_info ), hex_hash_string_len ) == 0 );
|
||||
|
||||
/* Test clone */
|
||||
memset( hash_str, 0x00, 10000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_update( &ctx_copy, src_str + halfway, src_len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx_copy, output ) );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, mbedtls_md_get_size( md_info ), hex_hash_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_md_free( &ctx );
|
||||
|
@ -290,56 +271,42 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_md_hmac( char *text_md_name, int trunc_size, char *hex_key_string,
|
||||
char *hex_src_string, char *hex_hash_string )
|
||||
void mbedtls_md_hmac( char * text_md_name, int trunc_size, 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 )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[10000];
|
||||
unsigned char key_str[10000];
|
||||
unsigned char hash_str[10000];
|
||||
unsigned char output[100];
|
||||
int key_len, src_len;
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( src_str, 0x00, 10000 );
|
||||
memset( key_str, 0x00, 10000 );
|
||||
memset( hash_str, 0x00, 10000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
|
||||
md_info = mbedtls_md_info_from_string( md_name );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
TEST_ASSERT ( mbedtls_md_hmac( md_info, key_str, key_len, src_str, src_len, output ) == 0 );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
|
||||
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, trunc_size * 2, hex_hash_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_hmac_multi( char *text_md_name, int trunc_size, char *hex_key_string,
|
||||
char *hex_src_string, char *hex_hash_string )
|
||||
void md_hmac_multi( char * text_md_name, int trunc_size, 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 )
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[10000];
|
||||
unsigned char key_str[10000];
|
||||
unsigned char hash_str[10000];
|
||||
unsigned char output[100];
|
||||
int key_len, src_len, halfway;
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
mbedtls_md_context_t ctx;
|
||||
int halfway;
|
||||
|
||||
mbedtls_md_init( &ctx );
|
||||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( src_str, 0x00, 10000 );
|
||||
memset( key_str, 0x00, 10000 );
|
||||
memset( hash_str, 0x00, 10000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
|
||||
|
@ -347,8 +314,6 @@ void md_hmac_multi( char *text_md_name, int trunc_size, char *hex_key_string,
|
|||
TEST_ASSERT( md_info != NULL );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx, md_info, 1 ) );
|
||||
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
halfway = src_len / 2;
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_starts( &ctx, key_str, key_len ) );
|
||||
|
@ -357,11 +322,9 @@ void md_hmac_multi( char *text_md_name, int trunc_size, char *hex_key_string,
|
|||
TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str + halfway, src_len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_finish( &ctx, output ) );
|
||||
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, trunc_size * 2, hex_hash_string_len ) == 0 );
|
||||
|
||||
/* Test again, for reset() */
|
||||
memset( hash_str, 0x00, 10000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_reset( &ctx ) );
|
||||
|
@ -369,8 +332,7 @@ void md_hmac_multi( char *text_md_name, int trunc_size, char *hex_key_string,
|
|||
TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str + halfway, src_len - halfway ) );
|
||||
TEST_ASSERT ( 0 == mbedtls_md_hmac_finish( &ctx, output ) );
|
||||
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, trunc_size * 2, hex_hash_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_md_free( &ctx );
|
||||
|
@ -378,15 +340,15 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
||||
void mbedtls_md_file( char *text_md_name, char *filename, char *hex_hash_string )
|
||||
void mbedtls_md_file( char * text_md_name, char * filename,
|
||||
uint8_t * hex_hash_string, uint32_t hex_hash_string_len
|
||||
)
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char hash_str[1000];
|
||||
unsigned char output[100];
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
|
||||
memset( md_name, 0x00, 100 );
|
||||
memset( hash_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 100 );
|
||||
|
||||
strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
|
||||
|
@ -394,8 +356,7 @@ void mbedtls_md_file( char *text_md_name, char *filename, char *hex_hash_string
|
|||
TEST_ASSERT( md_info != NULL );
|
||||
|
||||
TEST_ASSERT( mbedtls_md_file( md_info, filename, output ) == 0 );
|
||||
hexify( hash_str, output, mbedtls_md_get_size( md_info ) );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, mbedtls_md_get_size( md_info ), hex_hash_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
|
|
@ -6,116 +6,108 @@
|
|||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MD2_C */
|
||||
void md2_text( char *text_src_string, char *hex_hash_string )
|
||||
void md2_text( char * text_src_string, uint8_t * hex_hash_string,
|
||||
uint32_t hex_hash_string_len )
|
||||
{
|
||||
int ret;
|
||||
unsigned char src_str[100];
|
||||
unsigned char hash_str[33];
|
||||
unsigned char output[16];
|
||||
|
||||
memset( src_str, 0x00, sizeof src_str );
|
||||
memset( hash_str, 0x00, sizeof hash_str );
|
||||
memset( output, 0x00, sizeof output );
|
||||
|
||||
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
|
||||
|
||||
ret = mbedtls_md2_ret( src_str, strlen( (char *) src_str ), output );
|
||||
TEST_ASSERT( ret == 0 ) ;
|
||||
hexify( hash_str, output, sizeof output );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, sizeof output, hex_hash_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MD4_C */
|
||||
void md4_text( char *text_src_string, char *hex_hash_string )
|
||||
void md4_text( char * text_src_string, uint8_t * hex_hash_string,
|
||||
uint32_t hex_hash_string_len )
|
||||
{
|
||||
int ret;
|
||||
unsigned char src_str[100];
|
||||
unsigned char hash_str[33];
|
||||
unsigned char output[16];
|
||||
|
||||
memset( src_str, 0x00, sizeof src_str );
|
||||
memset( hash_str, 0x00, sizeof hash_str );
|
||||
memset( output, 0x00, sizeof output );
|
||||
|
||||
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
|
||||
|
||||
ret = mbedtls_md4_ret( src_str, strlen( (char *) src_str ), output );
|
||||
TEST_ASSERT( ret == 0 );
|
||||
hexify( hash_str, output, sizeof output );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, sizeof output, hex_hash_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MD5_C */
|
||||
void md5_text( char *text_src_string, char *hex_hash_string )
|
||||
void md5_text( char * text_src_string, uint8_t * hex_hash_string,
|
||||
uint32_t hex_hash_string_len )
|
||||
{
|
||||
int ret;
|
||||
unsigned char src_str[100];
|
||||
unsigned char hash_str[33];
|
||||
unsigned char output[16];
|
||||
|
||||
memset( src_str, 0x00, sizeof src_str );
|
||||
memset( hash_str, 0x00, sizeof hash_str );
|
||||
memset( output, 0x00, sizeof output );
|
||||
|
||||
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
|
||||
|
||||
ret = mbedtls_md5_ret( src_str, strlen( (char *) src_str ), output );
|
||||
TEST_ASSERT( ret == 0 );
|
||||
hexify( hash_str, output, sizeof output );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, sizeof output, hex_hash_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C */
|
||||
void ripemd160_text( char *text_src_string, char *hex_hash_string )
|
||||
void ripemd160_text( char * text_src_string, uint8_t * hex_hash_string,
|
||||
uint32_t hex_hash_string_len )
|
||||
{
|
||||
int ret;
|
||||
unsigned char src_str[100];
|
||||
unsigned char hash_str[41];
|
||||
unsigned char output[20];
|
||||
|
||||
memset(src_str, 0x00, sizeof src_str);
|
||||
memset(hash_str, 0x00, sizeof hash_str);
|
||||
memset(output, 0x00, sizeof output);
|
||||
|
||||
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
|
||||
|
||||
ret = mbedtls_ripemd160_ret( src_str, strlen( (char *) src_str ), output );
|
||||
TEST_ASSERT( ret == 0 );
|
||||
hexify( hash_str, output, sizeof output );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, sizeof output, hex_hash_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MD2_C:MBEDTLS_SELF_TEST */
|
||||
void md2_selftest()
|
||||
void md2_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_md2_self_test( 1 ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MD4_C:MBEDTLS_SELF_TEST */
|
||||
void md4_selftest()
|
||||
void md4_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_md4_self_test( 1 ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MD5_C:MBEDTLS_SELF_TEST */
|
||||
void md5_selftest()
|
||||
void md5_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_md5_self_test( 1 ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C:MBEDTLS_SELF_TEST */
|
||||
void ripemd160_selftest()
|
||||
void ripemd160_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_ripemd160_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ static int check_pointer( void *p )
|
|||
/* END_SUITE_HELPERS */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void mbedtls_memory_buffer_alloc_self_test( )
|
||||
void mbedtls_memory_buffer_alloc_self_test( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_memory_buffer_alloc_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
@ -31,10 +31,9 @@ void mbedtls_memory_buffer_alloc_self_test( )
|
|||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
|
||||
void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
|
||||
int d_bytes,
|
||||
int free_a, int free_b, int free_c,
|
||||
int free_d,
|
||||
int e_bytes, int f_bytes )
|
||||
int d_bytes, int free_a, int free_b,
|
||||
int free_c, int free_d, int e_bytes,
|
||||
int f_bytes )
|
||||
{
|
||||
unsigned char buf[1024];
|
||||
unsigned char *ptr_a = NULL, *ptr_b = NULL, *ptr_c = NULL, *ptr_d = NULL,
|
||||
|
@ -190,7 +189,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
|
||||
void memory_buffer_alloc_oom_test()
|
||||
void memory_buffer_alloc_oom_test( )
|
||||
{
|
||||
unsigned char buf[1024];
|
||||
unsigned char *ptr_a = NULL, *ptr_b = NULL, *ptr_c = NULL;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_null( )
|
||||
void mpi_null( )
|
||||
{
|
||||
mbedtls_mpi X, Y, Z;
|
||||
|
||||
|
@ -27,8 +27,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_read_write_string( int radix_X, char *input_X, int radix_A,
|
||||
char *input_A, int output_size, int result_read,
|
||||
void mpi_read_write_string( int radix_X, char * input_X, int radix_A,
|
||||
char * input_A, int output_size, int result_read,
|
||||
int result_write )
|
||||
{
|
||||
mbedtls_mpi X;
|
||||
|
@ -53,17 +53,15 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_read_binary( char *input_X, int radix_A, char *input_A )
|
||||
void mbedtls_mpi_read_binary( uint8_t * buf, uint32_t input_len, int radix_A,
|
||||
char * input_A )
|
||||
{
|
||||
mbedtls_mpi X;
|
||||
unsigned char str[1000];
|
||||
unsigned char buf[1000];
|
||||
size_t len;
|
||||
size_t input_len;
|
||||
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
input_len = unhexify( buf, input_X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &X, buf, input_len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_write_string( &X, radix_A, (char *) str, sizeof( str ), &len ) == 0 );
|
||||
|
@ -75,16 +73,15 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_write_binary( int radix_X, char *input_X, char *input_A,
|
||||
int output_size, int result )
|
||||
void mbedtls_mpi_write_binary( int radix_X, char * input_X, uint8_t * input_A,
|
||||
uint32_t input_A_len, int output_size,
|
||||
int result )
|
||||
{
|
||||
mbedtls_mpi X;
|
||||
unsigned char str[1000];
|
||||
unsigned char buf[1000];
|
||||
size_t buflen;
|
||||
|
||||
memset( buf, 0x00, 1000 );
|
||||
memset( str, 0x00, 1000 );
|
||||
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
|
@ -97,9 +94,8 @@ void mbedtls_mpi_write_binary( int radix_X, char *input_X, char *input_A,
|
|||
TEST_ASSERT( mbedtls_mpi_write_binary( &X, buf, buflen ) == result );
|
||||
if( result == 0)
|
||||
{
|
||||
hexify( str, buf, buflen );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) str, input_A ) == 0 );
|
||||
TEST_ASSERT( hexcmp( buf, input_A, buflen, input_A_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -108,18 +104,16 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
||||
void mbedtls_mpi_read_file( int radix_X, char *input_file, char *input_A,
|
||||
int result )
|
||||
void mbedtls_mpi_read_file( int radix_X, char * input_file, uint8_t * input_A,
|
||||
uint32_t input_A_len, int result )
|
||||
{
|
||||
mbedtls_mpi X;
|
||||
unsigned char str[1000];
|
||||
unsigned char buf[1000];
|
||||
size_t buflen;
|
||||
FILE *file;
|
||||
int ret;
|
||||
|
||||
memset( buf, 0x00, 1000 );
|
||||
memset( str, 0x00, 1000 );
|
||||
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
|
@ -134,9 +128,8 @@ void mbedtls_mpi_read_file( int radix_X, char *input_file, char *input_A,
|
|||
buflen = mbedtls_mpi_size( &X );
|
||||
TEST_ASSERT( mbedtls_mpi_write_binary( &X, buf, buflen ) == 0 );
|
||||
|
||||
hexify( str, buf, buflen );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) str, input_A ) == 0 );
|
||||
TEST_ASSERT( hexcmp( buf, input_A, buflen, input_A_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -145,8 +138,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
||||
void mbedtls_mpi_write_file( int radix_X, char *input_X, int output_radix,
|
||||
char *output_file )
|
||||
void mbedtls_mpi_write_file( int radix_X, char * input_X, int output_radix,
|
||||
char * output_file )
|
||||
{
|
||||
mbedtls_mpi X, Y;
|
||||
FILE *file_out, *file_in;
|
||||
|
@ -176,7 +169,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_get_bit( int radix_X, char *input_X, int pos, int val )
|
||||
void mbedtls_mpi_get_bit( int radix_X, char * input_X, int pos, int val )
|
||||
{
|
||||
mbedtls_mpi X;
|
||||
mbedtls_mpi_init( &X );
|
||||
|
@ -189,8 +182,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_set_bit( int radix_X, char *input_X, int pos, int val,
|
||||
int radix_Y, char *output_Y, int result )
|
||||
void mbedtls_mpi_set_bit( int radix_X, char * input_X, int pos, int val,
|
||||
int radix_Y, char * output_Y, int result )
|
||||
{
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
@ -210,7 +203,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_lsb( int radix_X, char *input_X, int nr_bits )
|
||||
void mbedtls_mpi_lsb( int radix_X, char * input_X, int nr_bits )
|
||||
{
|
||||
mbedtls_mpi X;
|
||||
mbedtls_mpi_init( &X );
|
||||
|
@ -224,7 +217,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_bitlen( int radix_X, char *input_X, int nr_bits )
|
||||
void mbedtls_mpi_bitlen( int radix_X, char * input_X, int nr_bits )
|
||||
{
|
||||
mbedtls_mpi X;
|
||||
mbedtls_mpi_init( &X );
|
||||
|
@ -238,8 +231,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_gcd( int radix_X, char *input_X, int radix_Y, char *input_Y,
|
||||
int radix_A, char *input_A )
|
||||
void mbedtls_mpi_gcd( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int radix_A, char * input_A )
|
||||
{
|
||||
mbedtls_mpi A, X, Y, Z;
|
||||
mbedtls_mpi_init( &A ); mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z );
|
||||
|
@ -270,8 +263,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_cmp_mpi( int radix_X, char *input_X, int radix_Y, char *input_Y,
|
||||
int input_A )
|
||||
void mbedtls_mpi_cmp_mpi( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int input_A )
|
||||
{
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
@ -286,8 +279,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_cmp_abs( int radix_X, char *input_X, int radix_Y, char *input_Y,
|
||||
int input_A )
|
||||
void mbedtls_mpi_cmp_abs( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int input_A )
|
||||
{
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
@ -354,8 +347,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_safe_cond_assign( int x_sign, char *x_str,
|
||||
int y_sign, char *y_str )
|
||||
void mbedtls_mpi_safe_cond_assign( int x_sign, char * x_str, int y_sign,
|
||||
char * y_str )
|
||||
{
|
||||
mbedtls_mpi X, Y, XX;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &XX );
|
||||
|
@ -378,8 +371,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_safe_cond_swap( int x_sign, char *x_str,
|
||||
int y_sign, char *y_str )
|
||||
void mbedtls_mpi_safe_cond_swap( int x_sign, char * x_str, int y_sign,
|
||||
char * y_str )
|
||||
{
|
||||
mbedtls_mpi X, Y, XX, YY;
|
||||
|
||||
|
@ -409,7 +402,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_swap( int input_X, int input_Y )
|
||||
void mbedtls_mpi_swap( int input_X, int input_Y )
|
||||
{
|
||||
mbedtls_mpi X, Y, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &A );
|
||||
|
@ -429,8 +422,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_add_mpi( int radix_X, char *input_X, int radix_Y, char *input_Y,
|
||||
int radix_A, char *input_A )
|
||||
void mbedtls_mpi_add_mpi( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int radix_A, char * input_A )
|
||||
{
|
||||
mbedtls_mpi X, Y, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
@ -447,7 +440,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_add_mpi_inplace( int radix_X, char *input_X, int radix_A, char *input_A )
|
||||
void mbedtls_mpi_add_mpi_inplace( int radix_X, char * input_X, int radix_A,
|
||||
char * input_A )
|
||||
{
|
||||
mbedtls_mpi X, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &A );
|
||||
|
@ -473,8 +467,8 @@ exit:
|
|||
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_add_abs( int radix_X, char *input_X, int radix_Y, char *input_Y,
|
||||
int radix_A, char *input_A )
|
||||
void mbedtls_mpi_add_abs( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int radix_A, char * input_A )
|
||||
{
|
||||
mbedtls_mpi X, Y, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
@ -491,8 +485,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_add_abs_add_first( int radix_X, char *input_X, int radix_Y,
|
||||
char *input_Y, int radix_A, char *input_A )
|
||||
void mpi_add_abs_add_first( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int radix_A, char * input_A )
|
||||
{
|
||||
mbedtls_mpi X, Y, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &A );
|
||||
|
@ -509,8 +503,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_add_abs_add_second( int radix_X, char *input_X, int radix_Y,
|
||||
char *input_Y, int radix_A, char *input_A )
|
||||
void mpi_add_abs_add_second( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int radix_A, char * input_A )
|
||||
{
|
||||
mbedtls_mpi X, Y, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &A );
|
||||
|
@ -527,8 +521,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_add_int( int radix_X, char *input_X, int input_Y, int radix_A,
|
||||
char *input_A )
|
||||
void mbedtls_mpi_add_int( int radix_X, char * input_X, int input_Y,
|
||||
int radix_A, char * input_A )
|
||||
{
|
||||
mbedtls_mpi X, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
@ -544,8 +538,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_sub_mpi( int radix_X, char *input_X, int radix_Y, char *input_Y,
|
||||
int radix_A, char *input_A )
|
||||
void mbedtls_mpi_sub_mpi( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int radix_A, char * input_A )
|
||||
{
|
||||
mbedtls_mpi X, Y, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
@ -562,8 +556,9 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_sub_abs( int radix_X, char *input_X, int radix_Y, char *input_Y,
|
||||
int radix_A, char *input_A, int sub_result )
|
||||
void mbedtls_mpi_sub_abs( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int radix_A, char * input_A,
|
||||
int sub_result )
|
||||
{
|
||||
mbedtls_mpi X, Y, Z, A;
|
||||
int res;
|
||||
|
@ -584,8 +579,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_sub_int( int radix_X, char *input_X, int input_Y, int radix_A,
|
||||
char *input_A )
|
||||
void mbedtls_mpi_sub_int( int radix_X, char * input_X, int input_Y,
|
||||
int radix_A, char * input_A )
|
||||
{
|
||||
mbedtls_mpi X, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
@ -601,8 +596,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_mul_mpi( int radix_X, char *input_X, int radix_Y, char *input_Y,
|
||||
int radix_A, char *input_A )
|
||||
void mbedtls_mpi_mul_mpi( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int radix_A, char * input_A )
|
||||
{
|
||||
mbedtls_mpi X, Y, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
@ -619,8 +614,9 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_mul_int( int radix_X, char *input_X, int input_Y, int radix_A,
|
||||
char *input_A, char *result_comparison )
|
||||
void mbedtls_mpi_mul_int( int radix_X, char * input_X, int input_Y,
|
||||
int radix_A, char * input_A,
|
||||
char * result_comparison )
|
||||
{
|
||||
mbedtls_mpi X, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
@ -641,9 +637,9 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_div_mpi( int radix_X, char *input_X, int radix_Y, char *input_Y,
|
||||
int radix_A, char *input_A, int radix_B, char *input_B,
|
||||
int div_result )
|
||||
void mbedtls_mpi_div_mpi( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int radix_A, char * input_A,
|
||||
int radix_B, char * input_B, int div_result )
|
||||
{
|
||||
mbedtls_mpi X, Y, Q, R, A, B;
|
||||
int res;
|
||||
|
@ -669,8 +665,9 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_div_int( int radix_X, char *input_X, int input_Y, int radix_A,
|
||||
char *input_A, int radix_B, char *input_B, int div_result )
|
||||
void mbedtls_mpi_div_int( int radix_X, char * input_X, int input_Y,
|
||||
int radix_A, char * input_A, int radix_B,
|
||||
char * input_B, int div_result )
|
||||
{
|
||||
mbedtls_mpi X, Q, R, A, B;
|
||||
int res;
|
||||
|
@ -695,8 +692,9 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_mod_mpi( int radix_X, char *input_X, int radix_Y, char *input_Y,
|
||||
int radix_A, char *input_A, int div_result )
|
||||
void mbedtls_mpi_mod_mpi( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int radix_A, char * input_A,
|
||||
int div_result )
|
||||
{
|
||||
mbedtls_mpi X, Y, A;
|
||||
int res;
|
||||
|
@ -718,8 +716,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_mod_int( int radix_X, char *input_X, int input_Y, int input_A,
|
||||
int div_result )
|
||||
void mbedtls_mpi_mod_int( int radix_X, char * input_X, int input_Y,
|
||||
int input_A, int div_result )
|
||||
{
|
||||
mbedtls_mpi X;
|
||||
int res;
|
||||
|
@ -740,9 +738,10 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_exp_mod( int radix_A, char *input_A, int radix_E, char *input_E,
|
||||
int radix_N, char *input_N, int radix_RR, char *input_RR,
|
||||
int radix_X, char *input_X, int div_result )
|
||||
void mbedtls_mpi_exp_mod( int radix_A, char * input_A, int radix_E,
|
||||
char * input_E, int radix_N, char * input_N,
|
||||
int radix_RR, char * input_RR, int radix_X,
|
||||
char * input_X, int div_result )
|
||||
{
|
||||
mbedtls_mpi A, E, N, RR, Z, X;
|
||||
int res;
|
||||
|
@ -771,8 +770,9 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_inv_mod( int radix_X, char *input_X, int radix_Y, char *input_Y,
|
||||
int radix_A, char *input_A, int div_result )
|
||||
void mbedtls_mpi_inv_mod( int radix_X, char * input_X, int radix_Y,
|
||||
char * input_Y, int radix_A, char * input_A,
|
||||
int div_result )
|
||||
{
|
||||
mbedtls_mpi X, Y, Z, A;
|
||||
int res;
|
||||
|
@ -794,7 +794,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_GENPRIME */
|
||||
void mbedtls_mpi_is_prime( int radix_X, char *input_X, int div_result )
|
||||
void mbedtls_mpi_is_prime( int radix_X, char * input_X, int div_result )
|
||||
{
|
||||
mbedtls_mpi X;
|
||||
int res;
|
||||
|
@ -842,8 +842,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_shift_l( int radix_X, char *input_X, int shift_X, int radix_A,
|
||||
char *input_A)
|
||||
void mbedtls_mpi_shift_l( int radix_X, char * input_X, int shift_X,
|
||||
int radix_A, char * input_A )
|
||||
{
|
||||
mbedtls_mpi X, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &A );
|
||||
|
@ -859,8 +859,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_shift_r( int radix_X, char *input_X, int shift_X, int radix_A,
|
||||
char *input_A )
|
||||
void mbedtls_mpi_shift_r( int radix_X, char * input_X, int shift_X,
|
||||
int radix_A, char * input_A )
|
||||
{
|
||||
mbedtls_mpi X, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &A );
|
||||
|
@ -876,7 +876,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void mpi_selftest()
|
||||
void mpi_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -6,16 +6,13 @@
|
|||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C */
|
||||
void mbedtls_pem_write_buffer( char *start, char *end, char *buf_str, char *result_str )
|
||||
void mbedtls_pem_write_buffer( char * start, char * end, uint8_t * buf,
|
||||
uint32_t buf_len, char * result_str )
|
||||
{
|
||||
unsigned char buf[5000];
|
||||
unsigned char *check_buf = NULL;
|
||||
int ret;
|
||||
size_t buf_len, olen = 0, olen2 = 0;
|
||||
size_t olen = 0, olen2 = 0;
|
||||
|
||||
memset( buf, 0, sizeof( buf ) );
|
||||
|
||||
buf_len = unhexify( buf, buf_str );
|
||||
|
||||
ret = mbedtls_pem_write_buffer( start, end, buf, buf_len, NULL, 0, &olen );
|
||||
TEST_ASSERT( ret == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
|
||||
|
@ -23,7 +20,6 @@ void mbedtls_pem_write_buffer( char *start, char *end, char *buf_str, char *resu
|
|||
check_buf = (unsigned char *) mbedtls_calloc( 1, olen );
|
||||
TEST_ASSERT( check_buf != NULL );
|
||||
|
||||
memset( check_buf, 0, olen );
|
||||
ret = mbedtls_pem_write_buffer( start, end, buf, buf_len, check_buf, olen, &olen2 );
|
||||
|
||||
TEST_ASSERT( olen2 <= olen );
|
||||
|
|
|
@ -70,7 +70,7 @@ size_t mbedtls_rsa_key_len_func( void *ctx )
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void pk_utils( int type, int size, int len, char *name )
|
||||
void pk_utils( int type, int size, int len, char * name )
|
||||
{
|
||||
mbedtls_pk_context pk;
|
||||
|
||||
|
@ -91,7 +91,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_PK_PARSE_C:MBEDTLS_FS_IO */
|
||||
void mbedtls_pk_check_pair( char *pub_file, char *prv_file, int ret )
|
||||
void mbedtls_pk_check_pair( char * pub_file, char * prv_file, int ret )
|
||||
{
|
||||
mbedtls_pk_context pub, prv, alt;
|
||||
|
||||
|
@ -121,22 +121,19 @@ 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( char *message_hex_string, int digest,
|
||||
int mod, int radix_N, char *input_N, int radix_E,
|
||||
char *input_E, char *result_hex_str, int result )
|
||||
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,
|
||||
int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
mbedtls_rsa_context *rsa;
|
||||
mbedtls_pk_context pk;
|
||||
int msg_len;
|
||||
|
||||
mbedtls_pk_init( &pk );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
|
||||
rsa = mbedtls_pk_rsa( pk );
|
||||
|
@ -145,8 +142,6 @@ void pk_rsa_verify_test_vec( char *message_hex_string, int digest,
|
|||
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 );
|
||||
|
||||
msg_len = unhexify( message_str, message_hex_string );
|
||||
unhexify( result_str, result_hex_str );
|
||||
|
||||
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 );
|
||||
|
@ -160,27 +155,23 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C */
|
||||
void pk_rsa_verify_ext_test_vec( char *message_hex_string, int digest,
|
||||
int mod, int radix_N, char *input_N, int radix_E,
|
||||
char *input_E, char *result_hex_str,
|
||||
int pk_type, int mgf1_hash_id, int salt_len,
|
||||
int result )
|
||||
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,
|
||||
int mgf1_hash_id, int salt_len, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
mbedtls_rsa_context *rsa;
|
||||
mbedtls_pk_context pk;
|
||||
mbedtls_pk_rsassa_pss_options pss_opts;
|
||||
void *options;
|
||||
int msg_len;
|
||||
size_t hash_len;
|
||||
|
||||
mbedtls_pk_init( &pk );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
|
||||
rsa = mbedtls_pk_rsa( pk );
|
||||
|
@ -189,8 +180,6 @@ void pk_rsa_verify_ext_test_vec( char *message_hex_string, int digest,
|
|||
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 );
|
||||
|
||||
msg_len = unhexify( message_str, message_hex_string );
|
||||
unhexify( result_str, result_hex_str );
|
||||
|
||||
if( digest != MBEDTLS_MD_NONE )
|
||||
{
|
||||
|
@ -226,19 +215,15 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_ECDSA_C */
|
||||
void pk_ec_test_vec( int type, int id, char *key_str,
|
||||
char *hash_str, char * sig_str, int ret )
|
||||
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 )
|
||||
{
|
||||
mbedtls_pk_context pk;
|
||||
mbedtls_ecp_keypair *eckey;
|
||||
unsigned char hash[100], sig[500], key[500];
|
||||
size_t hash_len, sig_len, key_len;
|
||||
|
||||
mbedtls_pk_init( &pk );
|
||||
|
||||
memset( hash, 0, sizeof( hash ) ); hash_len = unhexify(hash, hash_str);
|
||||
memset( sig, 0, sizeof( sig ) ); sig_len = unhexify(sig, sig_str);
|
||||
memset( key, 0, sizeof( key ) ); key_len = unhexify(key, key_str);
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( type ) ) == 0 );
|
||||
|
||||
|
@ -284,26 +269,20 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C */
|
||||
void pk_rsa_encrypt_test_vec( char *message_hex, int mod,
|
||||
int radix_N, char *input_N,
|
||||
int radix_E, char *input_E,
|
||||
char *result_hex, int ret )
|
||||
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 )
|
||||
{
|
||||
unsigned char message[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char result[1000];
|
||||
size_t msg_len, olen, res_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_rsa_context *rsa;
|
||||
mbedtls_pk_context pk;
|
||||
size_t olen;
|
||||
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
memset( message, 0, sizeof( message ) );
|
||||
memset( output, 0, sizeof( output ) );
|
||||
memset( result, 0, sizeof( result ) );
|
||||
|
||||
msg_len = unhexify( message, message_hex );
|
||||
res_len = unhexify( result, result_hex );
|
||||
|
||||
mbedtls_pk_init( &pk );
|
||||
TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
|
||||
|
@ -325,32 +304,25 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C */
|
||||
void pk_rsa_decrypt_test_vec( char *cipher_hex, 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,
|
||||
char *clear_hex, int ret )
|
||||
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 )
|
||||
{
|
||||
unsigned char clear[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char cipher[1000];
|
||||
size_t clear_len, olen, cipher_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
mbedtls_rsa_context *rsa;
|
||||
mbedtls_pk_context pk;
|
||||
size_t olen;
|
||||
|
||||
mbedtls_pk_init( &pk );
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
memset( clear, 0, sizeof( clear ) );
|
||||
memset( cipher, 0, sizeof( cipher ) );
|
||||
|
||||
clear_len = unhexify( clear, clear_hex );
|
||||
cipher_len = unhexify( cipher, cipher_hex );
|
||||
|
||||
/* init pk-rsa context */
|
||||
TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
|
||||
|
@ -453,7 +425,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C:MBEDTLS_PK_RSA_ALT_SUPPORT */
|
||||
void pk_rsa_alt( )
|
||||
void pk_rsa_alt( )
|
||||
{
|
||||
/*
|
||||
* An rsa_alt context can only do private operations (decrypt, sign).
|
||||
|
|
|
@ -9,28 +9,24 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char *input_N, int radix_E,
|
||||
char *input_E, int hash,
|
||||
char *message_hex_string, char *seed,
|
||||
char *result_hex_str, int result )
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char rnd_buf[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
rnd_buf_info info;
|
||||
mbedtls_mpi N, E;
|
||||
|
||||
info.length = unhexify( rnd_buf, seed );
|
||||
info.buf = rnd_buf;
|
||||
info.length = rnd_buf_len;
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
|
@ -38,14 +34,12 @@ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char *input_N, int radix_E,
|
|||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
||||
msg_len = unhexify( message_str, message_hex_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_buffer_rand, &info, MBEDTLS_RSA_PUBLIC, msg_len, message_str, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -55,15 +49,14 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
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, char *result_hex_str, char *seed,
|
||||
char *message_hex_string, int result )
|
||||
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 result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t output_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
|
@ -74,9 +67,7 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char *input_P,
|
|||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
|
@ -89,14 +80,12 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char *input_P,
|
|||
TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
|
||||
|
||||
unhexify( message_str, message_hex_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str, output, 1000 ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
|
||||
TEST_ASSERT( strncasecmp( (char *) output_str, result_hex_str, strlen( result_hex_str ) ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -107,33 +96,29 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
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,
|
||||
char *message_hex_string, char *salt,
|
||||
char *result_hex_str, int result )
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char rnd_buf[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
size_t msg_len;
|
||||
rnd_buf_info info;
|
||||
|
||||
info.length = unhexify( rnd_buf, salt );
|
||||
info.buf = rnd_buf;
|
||||
info.length = rnd_buf_len;
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
|
@ -145,7 +130,6 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char *input_P, int radix_Q,
|
|||
TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
|
||||
|
||||
msg_len = unhexify( message_str, message_hex_string );
|
||||
|
||||
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 );
|
||||
|
@ -153,9 +137,8 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char *input_P, int radix_Q,
|
|||
TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &rnd_buffer_rand, &info, MBEDTLS_RSA_PRIVATE, digest, 0, hash_result, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len);
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -166,24 +149,21 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* 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,
|
||||
char *message_hex_string, char *salt,
|
||||
char *result_hex_str, int result )
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
mbedtls_mpi N, E;
|
||||
((void) salt);
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
|
@ -191,8 +171,6 @@ void pkcs1_rsassa_v15_verify( int mod, int radix_N, char *input_N, int radix_E,
|
|||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
||||
msg_len = unhexify( message_str, message_hex_string );
|
||||
unhexify( result_str, result_hex_str );
|
||||
|
||||
if( mbedtls_md_info_from_type( digest ) != NULL )
|
||||
TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ),
|
||||
|
|
|
@ -9,28 +9,24 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void pkcs1_rsaes_oaep_encrypt( int mod, int radix_N, char *input_N, int radix_E,
|
||||
char *input_E, int hash,
|
||||
char *message_hex_string, char *seed,
|
||||
char *result_hex_str, int result )
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char rnd_buf[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
rnd_buf_info info;
|
||||
mbedtls_mpi N, E;
|
||||
|
||||
info.length = unhexify( rnd_buf, seed );
|
||||
info.buf = rnd_buf;
|
||||
info.length = rnd_buf_len;
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
|
@ -38,14 +34,12 @@ void pkcs1_rsaes_oaep_encrypt( int mod, int radix_N, char *input_N, int radix_E,
|
|||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
||||
msg_len = unhexify( message_str, message_hex_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_buffer_rand, &info, MBEDTLS_RSA_PUBLIC, msg_len, message_str, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -55,15 +49,15 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
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, char *result_hex_str, char *seed,
|
||||
char *message_hex_string, int result )
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t output_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
|
@ -75,9 +69,7 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char *input_P,
|
|||
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
|
@ -90,14 +82,12 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char *input_P,
|
|||
TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
|
||||
|
||||
unhexify( message_str, message_hex_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str, output, 1000 ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
|
||||
TEST_ASSERT( strncasecmp( (char *) output_str, result_hex_str, strlen( result_hex_str ) ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -108,33 +98,29 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
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,
|
||||
char *message_hex_string, char *salt,
|
||||
char *result_hex_str, int result )
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char rnd_buf[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
rnd_buf_info info;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
|
||||
info.length = unhexify( rnd_buf, salt );
|
||||
info.buf = rnd_buf;
|
||||
info.length = rnd_buf_len;
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
|
@ -146,7 +132,6 @@ void pkcs1_rsassa_pss_sign( int mod, int radix_P, char *input_P, int radix_Q,
|
|||
TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
|
||||
|
||||
msg_len = unhexify( message_str, message_hex_string );
|
||||
|
||||
if( mbedtls_md_info_from_type( digest ) != NULL )
|
||||
TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str,
|
||||
|
@ -156,9 +141,8 @@ void pkcs1_rsassa_pss_sign( int mod, int radix_P, char *input_P, int radix_Q,
|
|||
digest, 0, hash_result, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len);
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -169,24 +153,21 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* 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,
|
||||
char *message_hex_string, char *salt,
|
||||
char *result_hex_str, int result )
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
mbedtls_mpi N, E;
|
||||
((void) salt);
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
|
@ -195,8 +176,6 @@ void pkcs1_rsassa_pss_verify( int mod, int radix_N, char *input_N, int radix_E,
|
|||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
||||
msg_len = unhexify( message_str, message_hex_string );
|
||||
unhexify( result_str, result_hex_str );
|
||||
|
||||
if( mbedtls_md_info_from_type( digest ) != NULL )
|
||||
TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str,
|
||||
|
@ -212,28 +191,23 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void pkcs1_rsassa_pss_verify_ext( int mod,
|
||||
int radix_N, char *input_N,
|
||||
int radix_E, char *input_E,
|
||||
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,
|
||||
char *message_hex_string,
|
||||
char *result_hex_str,
|
||||
int result_simple,
|
||||
uint8_t * message_str, uint32_t msg_len,
|
||||
uint8_t * result_str,
|
||||
uint32_t result_str_len, int result_simple,
|
||||
int result_full )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len, hash_len;
|
||||
size_t hash_len;
|
||||
mbedtls_mpi N, E;
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, ctx_hash );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
|
@ -242,8 +216,6 @@ void pkcs1_rsassa_pss_verify_ext( int mod,
|
|||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
||||
msg_len = unhexify( message_str, message_hex_string );
|
||||
unhexify( result_str, result_hex_str );
|
||||
|
||||
if( msg_digest_id != MBEDTLS_MD_NONE )
|
||||
{
|
||||
|
|
|
@ -8,38 +8,25 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void pbkdf2_hmac( int hash, char *hex_password_string,
|
||||
char *hex_salt_string, int it_cnt, int key_len,
|
||||
char *result_key_string )
|
||||
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 )
|
||||
{
|
||||
unsigned char pw_str[100];
|
||||
unsigned char salt_str[100];
|
||||
unsigned char dst_str[200];
|
||||
|
||||
mbedtls_md_context_t ctx;
|
||||
const mbedtls_md_info_t *info;
|
||||
|
||||
int pw_len, salt_len;
|
||||
unsigned char key[100];
|
||||
|
||||
mbedtls_md_init( &ctx );
|
||||
|
||||
memset(pw_str, 0x00, sizeof(pw_str));
|
||||
memset(salt_str, 0x00, sizeof(salt_str));
|
||||
memset(dst_str, 0x00, sizeof(dst_str));
|
||||
|
||||
pw_len = unhexify( pw_str, hex_password_string );
|
||||
salt_len = unhexify( salt_str, hex_salt_string );
|
||||
|
||||
|
||||
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,
|
||||
it_cnt, key_len, key ) == 0 );
|
||||
|
||||
hexify( dst_str, key, key_len );
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, result_key_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( key, result_key_string, key_len, result_key_string_len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_md_free( &ctx );
|
||||
|
@ -80,7 +67,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void pkcs5_selftest( )
|
||||
void pkcs5_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_pkcs5_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C:MBEDTLS_FS_IO */
|
||||
void pk_parse_keyfile_rsa( char *key_file, char *password, int result )
|
||||
void pk_parse_keyfile_rsa( char * key_file, char * password, int result )
|
||||
{
|
||||
mbedtls_pk_context ctx;
|
||||
int res;
|
||||
|
@ -39,7 +39,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C:MBEDTLS_FS_IO */
|
||||
void pk_parse_public_keyfile_rsa( char *key_file, int result )
|
||||
void pk_parse_public_keyfile_rsa( char * key_file, int result )
|
||||
{
|
||||
mbedtls_pk_context ctx;
|
||||
int res;
|
||||
|
@ -64,7 +64,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_ECP_C */
|
||||
void pk_parse_public_keyfile_ec( char *key_file, int result )
|
||||
void pk_parse_public_keyfile_ec( char * key_file, int result )
|
||||
{
|
||||
mbedtls_pk_context ctx;
|
||||
int res;
|
||||
|
@ -89,7 +89,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_ECP_C */
|
||||
void pk_parse_keyfile_ec( char *key_file, char *password, int result )
|
||||
void pk_parse_keyfile_ec( char * key_file, char * password, int result )
|
||||
{
|
||||
mbedtls_pk_context ctx;
|
||||
int res;
|
||||
|
@ -113,21 +113,18 @@ exit:
|
|||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void pk_parse_key( char *key_data, char *result_str, int result )
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C */
|
||||
void pk_parse_key( uint8_t * buf, uint32_t data_len, char * result_str,
|
||||
int result )
|
||||
{
|
||||
mbedtls_pk_context pk;
|
||||
unsigned char buf[2000];
|
||||
unsigned char output[2000];
|
||||
int data_len;
|
||||
((void) result_str);
|
||||
|
||||
mbedtls_pk_init( &pk );
|
||||
|
||||
memset( buf, 0, 2000 );
|
||||
memset( output, 0, 2000 );
|
||||
|
||||
data_len = unhexify( buf, key_data );
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_parse_key( &pk, buf, data_len, NULL, 0 ) == ( result ) );
|
||||
if( ( result ) == 0 )
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C */
|
||||
void pk_write_pubkey_check( char *key_file )
|
||||
void pk_write_pubkey_check( char * key_file )
|
||||
{
|
||||
mbedtls_pk_context key;
|
||||
unsigned char buf[5000];
|
||||
|
@ -42,7 +42,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C */
|
||||
void pk_write_key_check( char *key_file )
|
||||
void pk_write_key_check( char * key_file )
|
||||
{
|
||||
mbedtls_pk_context key;
|
||||
unsigned char buf[5000];
|
||||
|
|
|
@ -18,28 +18,26 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_rsa_pkcs1_sign( char *message_hex_string, 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, char *result_hex_str, int result )
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
int msg_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
|
@ -52,7 +50,6 @@ void mbedtls_rsa_pkcs1_sign( char *message_hex_string, int padding_mode, int dig
|
|||
TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
|
||||
|
||||
msg_len = unhexify( message_str, message_hex_string );
|
||||
|
||||
if( mbedtls_md_info_from_type( digest ) != NULL )
|
||||
TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ),
|
||||
|
@ -63,9 +60,8 @@ void mbedtls_rsa_pkcs1_sign( char *message_hex_string, int padding_mode, int dig
|
|||
hash_result, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -76,23 +72,20 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_rsa_pkcs1_verify( char *message_hex_string, int padding_mode, int digest,
|
||||
int mod, int radix_N, char *input_N, int radix_E,
|
||||
char *input_E, char *result_hex_str, int result )
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
int msg_len;
|
||||
|
||||
mbedtls_mpi N, E;
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
|
@ -100,8 +93,6 @@ void mbedtls_rsa_pkcs1_verify( char *message_hex_string, int padding_mode, int d
|
|||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
||||
msg_len = unhexify( message_str, message_hex_string );
|
||||
unhexify( result_str, result_hex_str );
|
||||
|
||||
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 );
|
||||
|
@ -116,29 +107,24 @@ exit:
|
|||
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void rsa_pkcs1_sign_raw( char *message_hex_string, char *hash_result_string,
|
||||
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,
|
||||
char *result_hex_str )
|
||||
void rsa_pkcs1_sign_raw( uint8_t * message_str, uint32_t message_str_len,
|
||||
uint8_t * hash_result, uint32_t hash_len,
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
int hash_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
|
@ -151,16 +137,13 @@ void rsa_pkcs1_sign_raw( char *message_hex_string, char *hash_result_string,
|
|||
TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
|
||||
|
||||
unhexify( message_str, message_hex_string );
|
||||
hash_len = unhexify( hash_result, hash_result_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &rnd_pseudo_rand, &rnd_info,
|
||||
MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_NONE,
|
||||
hash_len, hash_result, output ) == 0 );
|
||||
|
||||
hexify( output_str, output, ctx.len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, 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 */
|
||||
|
@ -168,7 +151,6 @@ void rsa_pkcs1_sign_raw( char *message_hex_string, char *hash_result_string,
|
|||
{
|
||||
int res;
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
|
||||
res = mbedtls_rsa_rsaes_pkcs1_v15_encrypt( &ctx,
|
||||
&rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE,
|
||||
|
@ -183,8 +165,7 @@ void rsa_pkcs1_sign_raw( char *message_hex_string, char *hash_result_string,
|
|||
|
||||
if( res == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_PKCS1_V15 */
|
||||
|
@ -198,25 +179,20 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void rsa_pkcs1_verify_raw( char *message_hex_string, char *hash_result_string,
|
||||
void rsa_pkcs1_verify_raw( uint8_t * message_str, uint32_t message_str_len,
|
||||
uint8_t * hash_result, uint32_t hash_len,
|
||||
int padding_mode, int mod, int radix_N,
|
||||
char *input_N, int radix_E, char *input_E,
|
||||
char *result_hex_str, int correct )
|
||||
char * input_N, int radix_E, char * input_E,
|
||||
uint8_t * result_str, uint32_t result_str_len,
|
||||
int correct )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
unsigned char output[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t hash_len;
|
||||
|
||||
mbedtls_mpi N, E;
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
|
@ -226,9 +202,6 @@ void rsa_pkcs1_verify_raw( char *message_hex_string, char *hash_result_string,
|
|||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
||||
unhexify( message_str, message_hex_string );
|
||||
hash_len = unhexify( hash_result, hash_result_string );
|
||||
unhexify( result_str, result_hex_str );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, NULL, NULL,
|
||||
MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_NONE,
|
||||
|
@ -272,15 +245,14 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_rsa_pkcs1_encrypt( char *message_hex_string, int padding_mode, int mod,
|
||||
int radix_N, char *input_N, int radix_E, char *input_E,
|
||||
char *result_hex_str, int result )
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_mpi N, E;
|
||||
|
@ -289,9 +261,7 @@ void mbedtls_rsa_pkcs1_encrypt( char *message_hex_string, int padding_mode, int
|
|||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
|
@ -300,16 +270,14 @@ void mbedtls_rsa_pkcs1_encrypt( char *message_hex_string, int padding_mode, int
|
|||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
||||
msg_len = unhexify( message_str, message_hex_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_pseudo_rand, &rnd_info,
|
||||
MBEDTLS_RSA_PUBLIC, msg_len,
|
||||
message_str, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -319,24 +287,20 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void rsa_pkcs1_encrypt_bad_rng( char *message_hex_string, int padding_mode,
|
||||
int mod, int radix_N, char *input_N,
|
||||
int radix_E, char *input_E,
|
||||
char *result_hex_str, int result )
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
|
||||
mbedtls_mpi N, E;
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
|
@ -345,16 +309,14 @@ void rsa_pkcs1_encrypt_bad_rng( char *message_hex_string, int padding_mode,
|
|||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
||||
msg_len = unhexify( message_str, message_hex_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_zero_rand, NULL,
|
||||
MBEDTLS_RSA_PUBLIC, msg_len,
|
||||
message_str, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -364,14 +326,15 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_rsa_pkcs1_decrypt( char *message_hex_string, 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, char *result_hex_str, int result )
|
||||
void mbedtls_rsa_pkcs1_decrypt( uint8_t * message_str,
|
||||
uint32_t message_str_len, 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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t output_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
|
@ -382,9 +345,7 @@ void mbedtls_rsa_pkcs1_decrypt( char *message_hex_string, int padding_mode, int
|
|||
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
|
||||
|
@ -398,15 +359,13 @@ void mbedtls_rsa_pkcs1_decrypt( char *message_hex_string, int padding_mode, int
|
|||
TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
|
||||
|
||||
unhexify( message_str, message_hex_string );
|
||||
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 );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
|
||||
TEST_ASSERT( strncasecmp( (char *) output_str, result_hex_str, strlen( result_hex_str ) ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -417,12 +376,12 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_rsa_public( char *message_hex_string, int mod, int radix_N, char *input_N,
|
||||
int radix_E, char *input_E, char *result_hex_str, int result )
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
mbedtls_rsa_context ctx, ctx2; /* Also test mbedtls_rsa_copy() while at it */
|
||||
|
||||
mbedtls_mpi N, E;
|
||||
|
@ -430,9 +389,7 @@ void mbedtls_rsa_public( char *message_hex_string, int mod, int radix_N, char *i
|
|||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
mbedtls_rsa_init( &ctx2, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
|
@ -441,14 +398,12 @@ void mbedtls_rsa_public( char *message_hex_string, int mod, int radix_N, char *i
|
|||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
||||
unhexify( message_str, message_hex_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_public( &ctx, message_str, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx2.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
|
||||
/* And now with the copy */
|
||||
|
@ -459,13 +414,11 @@ void mbedtls_rsa_public( char *message_hex_string, int mod, int radix_N, char *i
|
|||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx2 ) == 0 );
|
||||
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
TEST_ASSERT( mbedtls_rsa_public( &ctx2, message_str, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx2.len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx2.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -476,13 +429,14 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_rsa_private( char *message_hex_string, 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, char *result_hex_str, int result )
|
||||
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 )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
mbedtls_rsa_context ctx, ctx2; /* Also test mbedtls_rsa_copy() while at it */
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
rnd_pseudo_info rnd_info;
|
||||
|
@ -493,7 +447,6 @@ void mbedtls_rsa_private( char *message_hex_string, int mod, int radix_P, char *
|
|||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
mbedtls_rsa_init( &ctx2, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
|
@ -506,20 +459,17 @@ void mbedtls_rsa_private( char *message_hex_string, int mod, int radix_P, char *
|
|||
TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
|
||||
|
||||
unhexify( message_str, message_hex_string );
|
||||
|
||||
/* repeat three times to test updating of blinding values */
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
TEST_ASSERT( mbedtls_rsa_private( &ctx, rnd_pseudo_rand, &rnd_info,
|
||||
message_str, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx2.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -531,14 +481,12 @@ void mbedtls_rsa_private( char *message_hex_string, int mod, int radix_P, char *
|
|||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx2 ) == 0 );
|
||||
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
TEST_ASSERT( mbedtls_rsa_private( &ctx2, rnd_pseudo_rand, &rnd_info,
|
||||
message_str, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx2.len );
|
||||
|
||||
TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, result_hex_str, ctx2.len, result_hex_str_len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -550,7 +498,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void rsa_check_privkey_null()
|
||||
void rsa_check_privkey_null( )
|
||||
{
|
||||
mbedtls_rsa_context ctx;
|
||||
memset( &ctx, 0x00, sizeof( mbedtls_rsa_context ) );
|
||||
|
@ -560,8 +508,8 @@ void rsa_check_privkey_null()
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_rsa_check_pubkey( int radix_N, char *input_N, int radix_E, char *input_E,
|
||||
int result )
|
||||
void mbedtls_rsa_check_pubkey( int radix_N, char * input_N, int radix_E,
|
||||
char * input_E, int result )
|
||||
{
|
||||
mbedtls_rsa_context ctx;
|
||||
mbedtls_mpi N, E;
|
||||
|
@ -588,12 +536,13 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_rsa_check_privkey( 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 radix_D, char *input_D,
|
||||
int radix_DP, char *input_DP, int radix_DQ,
|
||||
char *input_DQ, int radix_QP, char *input_QP,
|
||||
int result )
|
||||
void mbedtls_rsa_check_privkey( 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 radix_D, char * input_D, int radix_DP,
|
||||
char * input_DP, int radix_DQ,
|
||||
char * input_DQ, int radix_QP,
|
||||
char * input_QP, int result )
|
||||
{
|
||||
mbedtls_rsa_context ctx;
|
||||
|
||||
|
@ -647,13 +596,13 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void rsa_check_pubpriv( int mod, int radix_Npub, char *input_Npub,
|
||||
int radix_Epub, char *input_Epub,
|
||||
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 radix_D, char *input_D,
|
||||
int radix_DP, char *input_DP, int radix_DQ,
|
||||
char *input_DQ, int radix_QP, char *input_QP,
|
||||
void rsa_check_pubpriv( int mod, int radix_Npub, char * input_Npub,
|
||||
int radix_Epub, char * input_Epub, 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 radix_D, char * input_D,
|
||||
int radix_DP, char * input_DP, int radix_DQ,
|
||||
char * input_DQ, int radix_QP, char * input_QP,
|
||||
int result )
|
||||
{
|
||||
mbedtls_rsa_context pub, prv;
|
||||
|
@ -1465,7 +1414,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void rsa_selftest()
|
||||
void rsa_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_rsa_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -5,126 +5,96 @@
|
|||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
|
||||
void mbedtls_sha1( char *hex_src_string, char *hex_hash_string )
|
||||
void mbedtls_sha1( uint8_t * src_str, uint32_t src_len,
|
||||
uint8_t * hex_hash_string, uint32_t hex_hash_string_len )
|
||||
{
|
||||
unsigned char src_str[10000];
|
||||
unsigned char hash_str[10000];
|
||||
unsigned char output[41];
|
||||
int src_len;
|
||||
|
||||
memset(src_str, 0x00, 10000);
|
||||
memset(hash_str, 0x00, 10000);
|
||||
memset(output, 0x00, 41);
|
||||
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_sha1_ret( src_str, src_len, output ) == 0 );
|
||||
hexify( hash_str, output, 20 );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, 20, hex_hash_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
||||
void sha224(char *hex_src_string, char *hex_hash_string )
|
||||
void sha224( uint8_t * src_str, uint32_t src_len, uint8_t * hex_hash_string,
|
||||
uint32_t hex_hash_string_len )
|
||||
{
|
||||
unsigned char src_str[10000];
|
||||
unsigned char hash_str[10000];
|
||||
unsigned char output[57];
|
||||
int src_len;
|
||||
|
||||
memset(src_str, 0x00, 10000);
|
||||
memset(hash_str, 0x00, 10000);
|
||||
memset(output, 0x00, 57);
|
||||
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_sha256_ret( src_str, src_len, output, 1 ) == 0 );
|
||||
hexify( hash_str, output, 28 );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, 28, hex_hash_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
||||
void mbedtls_sha256(char *hex_src_string, char *hex_hash_string )
|
||||
void mbedtls_sha256( uint8_t * src_str, uint32_t src_len,
|
||||
uint8_t * hex_hash_string, uint32_t hex_hash_string_len )
|
||||
{
|
||||
unsigned char src_str[10000];
|
||||
unsigned char hash_str[10000];
|
||||
unsigned char output[65];
|
||||
int src_len;
|
||||
|
||||
memset(src_str, 0x00, 10000);
|
||||
memset(hash_str, 0x00, 10000);
|
||||
memset(output, 0x00, 65);
|
||||
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_sha256_ret( src_str, src_len, output, 0 ) == 0 );
|
||||
hexify( hash_str, output, 32 );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, 32, hex_hash_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
|
||||
void sha384(char *hex_src_string, char *hex_hash_string )
|
||||
void sha384( uint8_t * src_str, uint32_t src_len, uint8_t * hex_hash_string,
|
||||
uint32_t hex_hash_string_len )
|
||||
{
|
||||
unsigned char src_str[10000];
|
||||
unsigned char hash_str[10000];
|
||||
unsigned char output[97];
|
||||
int src_len;
|
||||
|
||||
memset(src_str, 0x00, 10000);
|
||||
memset(hash_str, 0x00, 10000);
|
||||
memset(output, 0x00, 97);
|
||||
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_sha512_ret( src_str, src_len, output, 1 ) == 0 );
|
||||
hexify( hash_str, output, 48 );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, 48, hex_hash_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
|
||||
void mbedtls_sha512(char *hex_src_string, char *hex_hash_string )
|
||||
void mbedtls_sha512( uint8_t * src_str, uint32_t src_len,
|
||||
uint8_t * hex_hash_string, uint32_t hex_hash_string_len )
|
||||
{
|
||||
unsigned char src_str[10000];
|
||||
unsigned char hash_str[10000];
|
||||
unsigned char output[129];
|
||||
int src_len;
|
||||
|
||||
memset(src_str, 0x00, 10000);
|
||||
memset(hash_str, 0x00, 10000);
|
||||
memset(output, 0x00, 129);
|
||||
|
||||
src_len = unhexify( src_str, hex_src_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_sha512_ret( src_str, src_len, output, 0 ) == 0 );
|
||||
hexify( hash_str, output, 64 );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_hash_string, 64, hex_hash_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_SELF_TEST */
|
||||
void sha1_selftest()
|
||||
void sha1_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_sha1_self_test( 1 ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_SELF_TEST */
|
||||
void sha256_selftest()
|
||||
void sha256_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_sha256_self_test( 1 ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_SELF_TEST */
|
||||
void sha512_selftest()
|
||||
void sha512_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_sha512_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ static int timers_are_badly_broken = 0;
|
|||
* END_DEPENDENCIES
|
||||
*/
|
||||
|
||||
<<<<<<< HEAD
|
||||
/* BEGIN_CASE */
|
||||
void timing_timer_simple( )
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void check_compiletime_version( char *version_str )
|
||||
void check_compiletime_version( char * version_str )
|
||||
{
|
||||
char build_str[100];
|
||||
char build_str_full[100];
|
||||
|
@ -35,7 +35,7 @@ void check_compiletime_version( char *version_str )
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void check_runtime_version( char *version_str )
|
||||
void check_runtime_version( char * version_str )
|
||||
{
|
||||
char build_str[100];
|
||||
char get_str[100];
|
||||
|
|
|
@ -162,7 +162,7 @@ int verify_print( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
|
||||
void x509_cert_info( char *crt_file, char *result_str )
|
||||
void x509_cert_info( char * crt_file, char * result_str )
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
char buf[2000];
|
||||
|
@ -185,7 +185,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRL_PARSE_C */
|
||||
void mbedtls_x509_crl_info( char *crl_file, char *result_str )
|
||||
void mbedtls_x509_crl_info( char * crl_file, char * result_str )
|
||||
{
|
||||
mbedtls_x509_crl crl;
|
||||
char buf[2000];
|
||||
|
@ -208,7 +208,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRL_PARSE_C */
|
||||
void mbedtls_x509_crl_parse( char *crl_file, int result )
|
||||
void mbedtls_x509_crl_parse( char * crl_file, int result )
|
||||
{
|
||||
mbedtls_x509_crl crl;
|
||||
char buf[2000];
|
||||
|
@ -224,7 +224,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CSR_PARSE_C */
|
||||
void mbedtls_x509_csr_info( char *csr_file, char *result_str )
|
||||
void mbedtls_x509_csr_info( char * csr_file, char * result_str )
|
||||
{
|
||||
mbedtls_x509_csr csr;
|
||||
char buf[2000];
|
||||
|
@ -247,7 +247,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */
|
||||
void x509_verify_info( int flags, char *prefix, char *result_str )
|
||||
void x509_verify_info( int flags, char * prefix, char * result_str )
|
||||
{
|
||||
char buf[2000];
|
||||
int res;
|
||||
|
@ -355,7 +355,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
|
||||
void mbedtls_x509_dn_gets( char *crt_file, char *entity, char *result_str )
|
||||
void mbedtls_x509_dn_gets( char * crt_file, char * entity, char * result_str )
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
char buf[2000];
|
||||
|
@ -383,7 +383,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
|
||||
void mbedtls_x509_time_is_past( char *crt_file, char *entity, int result )
|
||||
void mbedtls_x509_time_is_past( char * crt_file, char * entity, int result )
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
|
||||
|
@ -404,7 +404,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
|
||||
void mbedtls_x509_time_is_future( char *crt_file, char *entity, int result )
|
||||
void mbedtls_x509_time_is_future( char * crt_file, char * entity, int result )
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
|
||||
|
@ -425,7 +425,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_FS_IO */
|
||||
void x509parse_crt_file( char *crt_file, int result )
|
||||
void x509parse_crt_file( char * crt_file, int result )
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
|
||||
|
@ -439,18 +439,16 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */
|
||||
void x509parse_crt( char *crt_data, char *result_str, int result )
|
||||
void x509parse_crt( uint8_t * buf, uint32_t data_len, char * result_str,
|
||||
int result )
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
unsigned char buf[2000];
|
||||
unsigned char output[2000];
|
||||
int data_len, res;
|
||||
int res;
|
||||
|
||||
mbedtls_x509_crt_init( &crt );
|
||||
memset( buf, 0, 2000 );
|
||||
memset( output, 0, 2000 );
|
||||
|
||||
data_len = unhexify( buf, crt_data );
|
||||
|
||||
TEST_ASSERT( mbedtls_x509_crt_parse( &crt, buf, data_len ) == ( result ) );
|
||||
if( ( result ) == 0 )
|
||||
|
@ -469,18 +467,16 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRL_PARSE_C */
|
||||
void x509parse_crl( char *crl_data, char *result_str, int result )
|
||||
void x509parse_crl( uint8_t * buf, uint32_t data_len, char * result_str,
|
||||
int result )
|
||||
{
|
||||
mbedtls_x509_crl crl;
|
||||
unsigned char buf[2000];
|
||||
unsigned char output[2000];
|
||||
int data_len, res;
|
||||
int res;
|
||||
|
||||
mbedtls_x509_crl_init( &crl );
|
||||
memset( buf, 0, 2000 );
|
||||
memset( output, 0, 2000 );
|
||||
|
||||
data_len = unhexify( buf, crl_data );
|
||||
|
||||
TEST_ASSERT( mbedtls_x509_crl_parse( &crl, buf, data_len ) == ( result ) );
|
||||
if( ( result ) == 0 )
|
||||
|
@ -499,7 +495,7 @@ 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( char * csr_der_hex, char * ref_out, int ref_ret )
|
||||
{
|
||||
mbedtls_x509_csr csr;
|
||||
unsigned char *csr_der = NULL;
|
||||
|
@ -528,7 +524,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
|
||||
void mbedtls_x509_crt_parse_path( char *crt_path, int ret, int nb_crt )
|
||||
void mbedtls_x509_crt_parse_path( char * crt_path, int ret, int nb_crt )
|
||||
{
|
||||
mbedtls_x509_crt chain, *cur;
|
||||
int i;
|
||||
|
@ -630,18 +626,16 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */
|
||||
void x509_oid_desc( char *oid_str, char *ref_desc )
|
||||
void x509_oid_desc( uint8_t * buf, uint32_t buf_len, char * ref_desc )
|
||||
{
|
||||
mbedtls_x509_buf oid;
|
||||
const char *desc = NULL;
|
||||
unsigned char buf[20];
|
||||
int ret;
|
||||
|
||||
memset( buf, 0, sizeof buf );
|
||||
|
||||
oid.tag = MBEDTLS_ASN1_OID;
|
||||
oid.len = unhexify( buf, oid_str );
|
||||
oid.p = buf;
|
||||
oid.len = buf_len;
|
||||
|
||||
ret = mbedtls_oid_get_extended_key_usage( &oid, &desc );
|
||||
|
||||
|
@ -660,18 +654,17 @@ void x509_oid_desc( char *oid_str, char *ref_desc )
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */
|
||||
void x509_oid_numstr( char *oid_str, char *numstr, int blen, int ret )
|
||||
void x509_oid_numstr( uint8_t * oid_buf, uint32_t oid_buf_len, char * numstr,
|
||||
int blen, int ret )
|
||||
{
|
||||
mbedtls_x509_buf oid;
|
||||
unsigned char oid_buf[20];
|
||||
char num_buf[100];
|
||||
|
||||
memset( oid_buf, 0x00, sizeof oid_buf );
|
||||
memset( num_buf, 0x2a, sizeof num_buf );
|
||||
|
||||
oid.tag = MBEDTLS_ASN1_OID;
|
||||
oid.len = unhexify( oid_buf, oid_str );
|
||||
oid.p = oid_buf;
|
||||
oid.len = oid_buf_len;
|
||||
|
||||
TEST_ASSERT( (size_t) blen <= sizeof num_buf );
|
||||
|
||||
|
@ -686,7 +679,7 @@ void x509_oid_numstr( char *oid_str, char *numstr, int blen, int ret )
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CHECK_KEY_USAGE */
|
||||
void x509_check_key_usage( char *crt_file, int usage, int ret )
|
||||
void x509_check_key_usage( char * crt_file, int usage, int ret )
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
|
||||
|
@ -702,15 +695,13 @@ 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, char *usage_hex, int ret )
|
||||
void x509_check_extended_key_usage( char * crt_file, uint8_t * oid,
|
||||
uint32_t len, int ret )
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
char oid[50];
|
||||
size_t len;
|
||||
|
||||
mbedtls_x509_crt_init( &crt );
|
||||
|
||||
len = unhexify( (unsigned char *) oid, usage_hex );
|
||||
|
||||
TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
|
||||
|
||||
|
@ -722,9 +713,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */
|
||||
void x509_get_time( int tag, char *time_str, int ret,
|
||||
int year, int mon, int day,
|
||||
int hour, int min, int sec )
|
||||
void x509_get_time( int tag, char * time_str, int ret, int year, int mon,
|
||||
int day, int hour, int min, int sec )
|
||||
{
|
||||
mbedtls_x509_time time;
|
||||
unsigned char buf[21];
|
||||
|
@ -753,7 +743,7 @@ void x509_get_time( int tag, char *time_str, int ret,
|
|||
/* 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( char * hex_params, int params_tag,
|
||||
int ref_msg_md, int ref_mgf_md,
|
||||
int ref_salt_len, int ref_ret )
|
||||
{
|
||||
|
@ -783,7 +773,7 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_SELF_TEST */
|
||||
void x509_selftest()
|
||||
void x509_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_x509_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ size_t mbedtls_rsa_key_len_func( void *ctx )
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C:MBEDTLS_X509_CSR_WRITE_C */
|
||||
void x509_csr_check( char *key_file, char *cert_req_check_file,
|
||||
int md_type, int key_usage, int cert_type )
|
||||
void x509_csr_check( char * key_file, char * cert_req_check_file, int md_type,
|
||||
int key_usage, int cert_type )
|
||||
{
|
||||
mbedtls_pk_context key;
|
||||
mbedtls_x509write_csr req;
|
||||
|
@ -209,7 +209,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_X509_CREATE_C:MBEDTLS_X509_USE_C */
|
||||
void mbedtls_x509_string_to_names( char *name, char *parsed_name, int result )
|
||||
void mbedtls_x509_string_to_names( char * name, char * parsed_name, int result
|
||||
)
|
||||
{
|
||||
int ret;
|
||||
size_t len = 0;
|
||||
|
|
|
@ -8,121 +8,83 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void xtea_encrypt_ecb( char *hex_key_string, char *hex_src_string,
|
||||
char *hex_dst_string )
|
||||
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 )
|
||||
{
|
||||
unsigned char key_str[100];
|
||||
unsigned char src_str[100];
|
||||
unsigned char dst_str[100];
|
||||
unsigned char output[100];
|
||||
mbedtls_xtea_context ctx;
|
||||
|
||||
memset(key_str, 0x00, 100);
|
||||
memset(src_str, 0x00, 100);
|
||||
memset(dst_str, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
|
||||
unhexify( key_str, hex_key_string );
|
||||
unhexify( src_str, hex_src_string );
|
||||
|
||||
mbedtls_xtea_setup( &ctx, key_str );
|
||||
TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str, output ) == 0 );
|
||||
hexify( dst_str, output, 8 );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void xtea_decrypt_ecb( char *hex_key_string, char *hex_src_string,
|
||||
char *hex_dst_string )
|
||||
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 )
|
||||
{
|
||||
unsigned char key_str[100];
|
||||
unsigned char src_str[100];
|
||||
unsigned char dst_str[100];
|
||||
unsigned char output[100];
|
||||
mbedtls_xtea_context ctx;
|
||||
|
||||
memset(key_str, 0x00, 100);
|
||||
memset(src_str, 0x00, 100);
|
||||
memset(dst_str, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
|
||||
unhexify( key_str, hex_key_string );
|
||||
unhexify( src_str, hex_src_string );
|
||||
|
||||
mbedtls_xtea_setup( &ctx, key_str );
|
||||
TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_DECRYPT, src_str, output ) == 0 );
|
||||
hexify( dst_str, output, 8 );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void xtea_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string )
|
||||
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 )
|
||||
{
|
||||
unsigned char key_str[100];
|
||||
unsigned char src_str[100];
|
||||
unsigned char dst_str[100];
|
||||
unsigned char iv_str[100];
|
||||
unsigned char output[100];
|
||||
size_t len;
|
||||
mbedtls_xtea_context ctx;
|
||||
|
||||
memset(key_str, 0x00, 100);
|
||||
memset(src_str, 0x00, 100);
|
||||
memset(dst_str, 0x00, 100);
|
||||
memset(iv_str, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
|
||||
unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
len = unhexify( src_str, hex_src_string );
|
||||
|
||||
mbedtls_xtea_setup( &ctx, key_str );
|
||||
TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_ENCRYPT, len, iv_str,
|
||||
src_str, output ) == 0 );
|
||||
hexify( dst_str, output, len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, len, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
||||
void xtea_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
|
||||
char *hex_src_string, char *hex_dst_string )
|
||||
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 )
|
||||
{
|
||||
unsigned char key_str[100];
|
||||
unsigned char src_str[100];
|
||||
unsigned char dst_str[100];
|
||||
unsigned char iv_str[100];
|
||||
unsigned char output[100];
|
||||
size_t len;
|
||||
mbedtls_xtea_context ctx;
|
||||
|
||||
memset(key_str, 0x00, 100);
|
||||
memset(src_str, 0x00, 100);
|
||||
memset(dst_str, 0x00, 100);
|
||||
memset(iv_str, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
|
||||
unhexify( key_str, hex_key_string );
|
||||
unhexify( iv_str, hex_iv_string );
|
||||
len = unhexify( src_str, hex_src_string );
|
||||
|
||||
mbedtls_xtea_setup( &ctx, key_str );
|
||||
TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_DECRYPT, len, iv_str,
|
||||
src_str, output ) == 0 );
|
||||
hexify( dst_str, output, len );
|
||||
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
|
||||
TEST_ASSERT( hexcmp( output, hex_dst_string, len, hex_dst_string_len ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void xtea_selftest()
|
||||
void xtea_selftest( )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_xtea_self_test( 1 ) == 0 );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue