From f07db2e919742d760e60409054524c16f387cfda Mon Sep 17 00:00:00 2001 From: mohammad1603 Date: Wed, 9 May 2018 05:41:08 -0700 Subject: [PATCH] Add more test scenario for GCM and failure cases --- tests/suites/test_suite_psa_crypto.data | 19 +++++++++++++++++-- tests/suites/test_suite_psa_crypto.function | 13 +++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data index 3e80c9072..05d579a38 100755 --- a/tests/suites/test_suite_psa_crypto.data +++ b/tests/suites/test_suite_psa_crypto.data @@ -121,5 +121,20 @@ PSA verify ECDSA SECP256R1 SHA-256 depends_on:MBEDTLS_PK_C:MBEDTLS_PK_PARSE_C:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED asymmetric_verify:PSA_KEY_TYPE_ECC_KEYPAIR(PSA_KEY_TYPE_ECC_CURVE_NISTP256R1):"3078020101042100ab45435712649cb30bbddac49197eebf2740ffc7f874d9244c3460f54f322d3aa00a06082a8648ce3d030107a14403420004dea5e45d0ea37fc566232a508f4ad20ea13d47e4bf5fa4d54a57a0ba012042087097496efc583fed8b24a5b9be9a51de063f5a00a8b698a16fd7f29b5485f320":PSA_ALG_SHA_256:"9ac4335b469bbd791439248504dd0d49c71349a295fee5a1c68507f45a9e1c7b":"304502206a3399f69421ffe1490377adf2ea1f117d81a63cf5bf22e918d51175eb259151022100ce95d7c26cc04e25503e2f7a1ec3573e3c2412534bb4a19b3a7811742f49f50f" -PSA AEAD Encrypt-Decrypt, first scenario -aead_encrypt_decrypt:PSA_KEY_TYPE_AES:"C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF":PSA_ALG_CCM:"0C0D0E0F101112131415161718191A1B1C1D1E":"000102030405060708090A0B" +PSA AEAD Encrypt-Decrypt, AES CCM scenario 1 +aead_encrypt_decrypt:PSA_KEY_TYPE_AES:"C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF":PSA_ALG_CCM:"0C0D0E0F101112131415161718191A1B1C1D1E":"000102030405060708090A0B":PSA_SUCCESS + +PSA AEAD Encrypt-Decrypt, AES CCM scenario 2 +aead_encrypt_decrypt:PSA_KEY_TYPE_AES:"D7828D13B2B0BDC325A76236DF93CC6B":PSA_ALG_CCM:"B96B49E21D621741632875DB7F6C9243D2D7C2":"EC46BB63B02520C33C49FD70":PSA_SUCCESS + +PSA AEAD Encrypt-Decrypt, AES GCM scenario 1 +aead_encrypt_decrypt:PSA_KEY_TYPE_AES:"C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF":PSA_ALG_GCM:"0C0D0E0F101112131415161718191A1B1C1D1E":"000102030405060708090A0B":PSA_SUCCESS + +PSA AEAD Encrypt-Decrypt, AES GCM scenario 2 +aead_encrypt_decrypt:PSA_KEY_TYPE_AES:"D7828D13B2B0BDC325A76236DF93CC6B":PSA_ALG_GCM:"B96B49E21D621741632875DB7F6C9243D2D7C2":"EC46BB63B02520C33C49FD70":PSA_SUCCESS + +PSA AEAD Encrypt-Decrypt, Fail Scenario - Invalid key type +aead_encrypt_decrypt:PSA_KEY_TYPE_DES:"D7828D13B2B0BDC325A76236DF93CC6B":PSA_ALG_CCM:"B96B49E21D621741632875DB7F6C9243D2D7C2":"EC46BB63B02520C33C49FD70":PSA_ERROR_INVALID_ARGUMENT + +PSA AEAD Encrypt-Decrypt, Fail Scenario - Invalid algorithm +aead_encrypt_decrypt:PSA_KEY_TYPE_AES:"D7828D13B2B0BDC325A76236DF93CC6B":PSA_ALG_CTR:"B96B49E21D621741632875DB7F6C9243D2D7C2":"EC46BB63B02520C33C49FD70":PSA_ERROR_INVALID_ARGUMENT diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index d366608c8..9a6004a49 100755 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -577,7 +577,7 @@ exit: /* BEGIN_CASE */ void aead_encrypt_decrypt( int key_type_arg, char * key_hex, int alg_arg, char * input_hex, - char * add_data ) + char * add_data, int expected_result ) { int slot = 1; psa_key_type_t key_type = key_type_arg; @@ -625,7 +625,7 @@ void aead_encrypt_decrypt( int key_type_arg, char * key_hex, nonce, nonce_length, additional_data, additional_data_length, input_data, input_size, output_data, - output_size, &output_length ) == PSA_SUCCESS ); + output_size, &output_length ) == ( psa_status_t )expected_result ); output_data2 = mbedtls_calloc( 1, output_length ); TEST_ASSERT( output_data2 != NULL ); @@ -634,16 +634,21 @@ void aead_encrypt_decrypt( int key_type_arg, char * key_hex, nonce, nonce_length, additional_data, additional_data_length, output_data, output_length - tag_length, output_data2, - output_length, &output_length2 ) == PSA_SUCCESS ); + output_length, &output_length2 ) == ( psa_status_t )expected_result ); - TEST_ASSERT( memcmp( input_data, output_data2, + if( expected_result == 0 ) + { + TEST_ASSERT( memcmp( input_data, output_data2, input_size ) == 0 ); + } exit: psa_destroy_key( slot ); mbedtls_free( key_data ); mbedtls_free( input_data ); + mbedtls_free( additional_data ); + mbedtls_free( output_data ); mbedtls_psa_crypto_free( ); } /* END_CASE */