early-access version 1503
This commit is contained in:
@@ -8,53 +8,27 @@
|
||||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_chachapoly_enc( char *hex_key_string, char *hex_nonce_string, char *hex_aad_string, char *hex_input_string, char *hex_output_string, char *hex_mac_string )
|
||||
void mbedtls_chachapoly_enc( data_t *key_str, data_t *nonce_str, data_t *aad_str, data_t *input_str, data_t *output_str, data_t *mac_str )
|
||||
{
|
||||
unsigned char key_str[32]; /* size set by the standard */
|
||||
unsigned char nonce_str[12]; /* size set by the standard */
|
||||
unsigned char aad_str[12]; /* max size of test data so far */
|
||||
unsigned char input_str[265]; /* max size of binary input/output so far */
|
||||
unsigned char output_str[265];
|
||||
unsigned char output[265];
|
||||
unsigned char mac_str[16]; /* size set by the standard */
|
||||
unsigned char mac[16]; /* size set by the standard */
|
||||
size_t input_len;
|
||||
size_t output_len;
|
||||
size_t aad_len;
|
||||
size_t key_len;
|
||||
size_t nonce_len;
|
||||
size_t mac_len;
|
||||
mbedtls_chachapoly_context ctx;
|
||||
|
||||
memset( key_str, 0x00, sizeof( key_str ) );
|
||||
memset( nonce_str, 0x00, sizeof( nonce_str ) );
|
||||
memset( aad_str, 0x00, sizeof( aad_str ) );
|
||||
memset( input_str, 0x00, sizeof( input_str ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
memset( mac_str, 0x00, sizeof( mac_str ) );
|
||||
|
||||
aad_len = unhexify( aad_str, hex_aad_string );
|
||||
input_len = unhexify( input_str, hex_input_string );
|
||||
output_len = unhexify( output_str, hex_output_string );
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
nonce_len = unhexify( nonce_str, hex_nonce_string );
|
||||
mac_len = unhexify( mac_str, hex_mac_string );
|
||||
|
||||
TEST_ASSERT( key_len == 32 );
|
||||
TEST_ASSERT( nonce_len == 12 );
|
||||
TEST_ASSERT( mac_len == 16 );
|
||||
TEST_ASSERT( key_str->len == 32 );
|
||||
TEST_ASSERT( nonce_str->len == 12 );
|
||||
TEST_ASSERT( mac_str->len == 16 );
|
||||
|
||||
mbedtls_chachapoly_init( &ctx );
|
||||
|
||||
TEST_ASSERT( mbedtls_chachapoly_setkey( &ctx, key_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_chachapoly_setkey( &ctx, key_str->x ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_chachapoly_encrypt_and_tag( &ctx,
|
||||
input_len, nonce_str,
|
||||
aad_str, aad_len,
|
||||
input_str, output, mac ) == 0 );
|
||||
input_str->len, nonce_str->x,
|
||||
aad_str->x, aad_str->len,
|
||||
input_str->x, output, mac ) == 0 );
|
||||
|
||||
TEST_ASSERT( memcmp( output_str, output, output_len ) == 0 );
|
||||
TEST_ASSERT( memcmp( mac_str, mac, 16U ) == 0 );
|
||||
TEST_ASSERT( memcmp( output_str->x, output, output_str->len ) == 0 );
|
||||
TEST_ASSERT( memcmp( mac_str->x, mac, 16U ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_chachapoly_free( &ctx );
|
||||
@@ -62,55 +36,29 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_chachapoly_dec( char *hex_key_string, char *hex_nonce_string, char *hex_aad_string, char *hex_input_string, char *hex_output_string, char *hex_mac_string, int ret_exp )
|
||||
void mbedtls_chachapoly_dec( data_t *key_str, data_t *nonce_str, data_t *aad_str, data_t *input_str, data_t *output_str, data_t *mac_str, int ret_exp )
|
||||
{
|
||||
unsigned char key_str[32]; /* size set by the standard */
|
||||
unsigned char nonce_str[12]; /* size set by the standard */
|
||||
unsigned char aad_str[12]; /* max size of test data so far */
|
||||
unsigned char input_str[265]; /* max size of binary input/output so far */
|
||||
unsigned char output_str[265];
|
||||
unsigned char output[265];
|
||||
unsigned char mac_str[16]; /* size set by the standard */
|
||||
size_t input_len;
|
||||
size_t output_len;
|
||||
size_t aad_len;
|
||||
size_t key_len;
|
||||
size_t nonce_len;
|
||||
size_t mac_len;
|
||||
int ret;
|
||||
mbedtls_chachapoly_context ctx;
|
||||
|
||||
memset( key_str, 0x00, sizeof( key_str ) );
|
||||
memset( nonce_str, 0x00, sizeof( nonce_str ) );
|
||||
memset( aad_str, 0x00, sizeof( aad_str ) );
|
||||
memset( input_str, 0x00, sizeof( input_str ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
memset( mac_str, 0x00, sizeof( mac_str ) );
|
||||
|
||||
aad_len = unhexify( aad_str, hex_aad_string );
|
||||
input_len = unhexify( input_str, hex_input_string );
|
||||
output_len = unhexify( output_str, hex_output_string );
|
||||
key_len = unhexify( key_str, hex_key_string );
|
||||
nonce_len = unhexify( nonce_str, hex_nonce_string );
|
||||
mac_len = unhexify( mac_str, hex_mac_string );
|
||||
|
||||
TEST_ASSERT( key_len == 32 );
|
||||
TEST_ASSERT( nonce_len == 12 );
|
||||
TEST_ASSERT( mac_len == 16 );
|
||||
TEST_ASSERT( key_str->len == 32 );
|
||||
TEST_ASSERT( nonce_str->len == 12 );
|
||||
TEST_ASSERT( mac_str->len == 16 );
|
||||
|
||||
mbedtls_chachapoly_init( &ctx );
|
||||
|
||||
TEST_ASSERT( mbedtls_chachapoly_setkey( &ctx, key_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_chachapoly_setkey( &ctx, key_str->x ) == 0 );
|
||||
|
||||
ret = mbedtls_chachapoly_auth_decrypt( &ctx,
|
||||
input_len, nonce_str,
|
||||
aad_str, aad_len,
|
||||
mac_str, input_str, output );
|
||||
input_str->len, nonce_str->x,
|
||||
aad_str->x, aad_str->len,
|
||||
mac_str->x, input_str->x, output );
|
||||
|
||||
TEST_ASSERT( ret == ret_exp );
|
||||
if( ret_exp == 0 )
|
||||
{
|
||||
TEST_ASSERT( memcmp( output_str, output, output_len ) == 0 );
|
||||
TEST_ASSERT( memcmp( output_str->x, output, output_str->len ) == 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
@@ -118,7 +66,7 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
|
||||
void chachapoly_bad_params()
|
||||
{
|
||||
unsigned char key[32];
|
||||
@@ -138,124 +86,114 @@ void chachapoly_bad_params()
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( mac, 0x00, sizeof( mac ) );
|
||||
|
||||
mbedtls_chachapoly_init( NULL );
|
||||
mbedtls_chachapoly_free( NULL );
|
||||
TEST_INVALID_PARAM( mbedtls_chachapoly_init( NULL ) );
|
||||
TEST_VALID_PARAM( mbedtls_chachapoly_free( NULL ) );
|
||||
|
||||
mbedtls_chachapoly_init( &ctx );
|
||||
/* setkey */
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_setkey( NULL, key ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_setkey( &ctx, NULL ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_chachapoly_setkey( NULL, key )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_setkey( &ctx, NULL )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
|
||||
TEST_ASSERT( mbedtls_chachapoly_encrypt_and_tag( NULL,
|
||||
/* encrypt_and_tag */
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_encrypt_and_tag( NULL,
|
||||
0, nonce,
|
||||
aad, 0,
|
||||
input, output, mac )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_encrypt_and_tag( &ctx,
|
||||
input, output, mac ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_encrypt_and_tag( &ctx,
|
||||
0, NULL,
|
||||
aad, 0,
|
||||
input, output, mac )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_encrypt_and_tag( &ctx,
|
||||
input, output, mac ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_encrypt_and_tag( &ctx,
|
||||
0, nonce,
|
||||
NULL, aad_len,
|
||||
input, output, mac )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_encrypt_and_tag( &ctx,
|
||||
input, output, mac ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_encrypt_and_tag( &ctx,
|
||||
input_len, nonce,
|
||||
aad, 0,
|
||||
NULL, output, mac )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_encrypt_and_tag( &ctx,
|
||||
NULL, output, mac ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_encrypt_and_tag( &ctx,
|
||||
input_len, nonce,
|
||||
aad, 0,
|
||||
input, NULL, mac )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_encrypt_and_tag( &ctx,
|
||||
input, NULL, mac ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_encrypt_and_tag( &ctx,
|
||||
0, nonce,
|
||||
aad, 0,
|
||||
input, output, NULL )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
input, output, NULL ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( NULL,
|
||||
/* auth_decrypt */
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_auth_decrypt( NULL,
|
||||
0, nonce,
|
||||
aad, 0,
|
||||
mac, input, output )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
|
||||
mac, input, output ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_auth_decrypt( &ctx,
|
||||
0, NULL,
|
||||
aad, 0,
|
||||
mac, input, output )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
|
||||
mac, input, output ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_auth_decrypt( &ctx,
|
||||
0, nonce,
|
||||
NULL, aad_len,
|
||||
mac, input, output )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
|
||||
mac, input, output ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_auth_decrypt( &ctx,
|
||||
0, nonce,
|
||||
aad, 0,
|
||||
NULL, input, output )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
|
||||
NULL, input, output ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_auth_decrypt( &ctx,
|
||||
input_len, nonce,
|
||||
aad, 0,
|
||||
mac, NULL, output )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
|
||||
mac, NULL, output ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_auth_decrypt( &ctx,
|
||||
input_len, nonce,
|
||||
aad, 0,
|
||||
mac, input, NULL )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
mac, input, NULL ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_chachapoly_encrypt_and_tag( &ctx,
|
||||
0, nonce,
|
||||
aad, aad_len,
|
||||
NULL, NULL, mac )
|
||||
== 0 );
|
||||
TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
|
||||
0, nonce,
|
||||
aad, aad_len,
|
||||
mac, NULL, NULL )
|
||||
== 0 );
|
||||
/* starts */
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_starts( NULL, nonce,
|
||||
MBEDTLS_CHACHAPOLY_ENCRYPT ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_starts( &ctx, NULL,
|
||||
MBEDTLS_CHACHAPOLY_ENCRYPT ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_chachapoly_encrypt_and_tag( &ctx,
|
||||
input_len, nonce,
|
||||
NULL, 0,
|
||||
input, output, mac )
|
||||
== 0 );
|
||||
TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
|
||||
input_len, nonce,
|
||||
NULL, 0,
|
||||
mac, input, output )
|
||||
== 0 );
|
||||
/* update_aad */
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_update_aad( NULL, aad,
|
||||
aad_len ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_update_aad( &ctx, NULL,
|
||||
aad_len ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_chachapoly_starts( NULL, nonce, MBEDTLS_CHACHAPOLY_ENCRYPT )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_starts( &ctx, NULL, MBEDTLS_CHACHAPOLY_ENCRYPT )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
/* update */
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_update( NULL, input_len,
|
||||
input, output ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_update( &ctx, input_len,
|
||||
NULL, output ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_update( &ctx, input_len,
|
||||
input, NULL ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_chachapoly_update_aad( NULL, aad, aad_len )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_update_aad( &ctx, NULL, aad_len )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
|
||||
TEST_ASSERT( mbedtls_chachapoly_update( NULL, input_len, input, output )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_update( &ctx, input_len, NULL, output )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_update( &ctx, input_len, input, NULL )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
|
||||
TEST_ASSERT( mbedtls_chachapoly_finish( NULL, mac )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( mbedtls_chachapoly_finish( &ctx, NULL )
|
||||
== MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
|
||||
/* finish */
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_finish( NULL, mac ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
|
||||
mbedtls_chachapoly_finish( &ctx, NULL ) );
|
||||
|
||||
exit:
|
||||
mbedtls_chachapoly_free( &ctx );
|
||||
return;
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
Reference in New Issue
Block a user