PSA: Implement MAC functions
Implement psa_mac_start, psa_mac_update and psa_mac_final.
Implement HMAC anc CMAC.
Smoke tests.
diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data
index f53b1a4..4f4bef1 100644
--- a/tests/suites/test_suite_psa_crypto.data
+++ b/tests/suites/test_suite_psa_crypto.data
@@ -45,6 +45,14 @@
depends_on:MBEDTLS_SHA256_C
hash_verify:PSA_ALG_SHA_256:"bd":"68325720aabd7c82f30f554b313d0570c95accbb7dc4b5aae11204c08ffe732b"
+PSA MAC verify: HMAC-SHA-256
+depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C
+mac_verify:PSA_KEY_TYPE_HMAC:"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f":PSA_ALG_HMAC(PSA_ALG_SHA_256):"":"53616d706c65206d65737361676520666f72206b65796c656e3d626c6f636b6c656e":"8bb9a1db9806f20df7f77b82138c7914d174d59e13dc4d0169c9057b133e1d62"
+
+PSA MAC verify: CMAC-AES-128
+depends_on:MBEDTLS_CMAC_C:MBEDTLS_AES_C
+mac_verify:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":PSA_ALG_CMAC:"":"6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411":"dfa66747de9ae63030ca32611497c827"
+
PSA signature size: RSA keypair, 1024 bits, PKCS#1 v1.5 raw
signature_size:PSA_KEY_TYPE_RSA_KEYPAIR:1024:PSA_ALG_RSA_PKCS1V15_RAW:128
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index 21802d1..d530574 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -1,5 +1,7 @@
/* BEGIN_HEADER */
#include "psa/crypto.h"
+
+#include "mbedtls/md.h"
/* END_HEADER */
/* BEGIN_DEPENDENCIES
@@ -201,6 +203,67 @@
/* END_CASE */
/* BEGIN_CASE */
+void mac_verify( int key_type_arg, char *key_hex,
+ int alg_arg, char *iv_hex,
+ char *input_hex, char *mac_hex )
+{
+ int key_slot = 1;
+ psa_key_type_t key_type = key_type_arg;
+ psa_algorithm_t alg = alg_arg;
+ unsigned char *key = NULL;
+ size_t key_size;
+ unsigned char *iv = NULL;
+ size_t iv_size;
+ unsigned char *input = NULL;
+ size_t input_size;
+ unsigned char *expected_mac = NULL;
+ size_t expected_mac_size;
+ psa_mac_operation_t operation;
+
+ key_size = strlen( key_hex ) / 2;
+ key = mbedtls_calloc( 1, key_size );
+ TEST_ASSERT( key != NULL );
+ key_size = unhexify( key, key_hex );
+ iv_size = strlen( iv_hex ) / 2;
+ if( iv_size != 0 )
+ {
+ iv = mbedtls_calloc( 1, iv_size );
+ TEST_ASSERT( iv != NULL );
+ iv_size = unhexify( iv, iv_hex );
+ }
+ input_size = strlen( input_hex ) / 2;
+ input = mbedtls_calloc( 1, input_size );
+ TEST_ASSERT( input != NULL );
+ input_size = unhexify( input, input_hex );
+ expected_mac_size = strlen( mac_hex ) / 2;
+ expected_mac = mbedtls_calloc( 1, expected_mac_size );
+ TEST_ASSERT( expected_mac != NULL );
+ expected_mac_size = unhexify( expected_mac, mac_hex );
+
+ TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
+
+ TEST_ASSERT( psa_import_key( key_slot, key_type,
+ key, key_size ) == PSA_SUCCESS );
+ // TODO: support IV
+ TEST_ASSERT( psa_mac_start( &operation, key_slot, alg ) == PSA_SUCCESS );
+ TEST_ASSERT( psa_destroy_key( key_slot ) == PSA_SUCCESS );
+ TEST_ASSERT( psa_mac_update( &operation,
+ input, input_size ) == PSA_SUCCESS );
+ TEST_ASSERT( psa_mac_verify( &operation,
+ expected_mac,
+ expected_mac_size ) == PSA_SUCCESS );
+
+exit:
+ mbedtls_free( key );
+ mbedtls_free( iv );
+ mbedtls_free( input );
+ mbedtls_free( expected_mac );
+ psa_destroy_key( key_slot );
+ mbedtls_psa_crypto_free( );
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
void signature_size( int type_arg, int bits, int alg_arg, int expected_size_arg )
{
psa_key_type_t type = type_arg;