psa: Remove test code in the library
The current testing of the PSA configuration is
based on test code located in the library itself.
Remove this code as we are moving to using a
test library instead.
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
diff --git a/library/psa_crypto_mac.c b/library/psa_crypto_mac.c
index fe15e9f..5e78d65 100644
--- a/library/psa_crypto_mac.c
+++ b/library/psa_crypto_mac.c
@@ -30,22 +30,7 @@
#include <mbedtls/error.h>
#include <string.h>
-/* Use builtin defines specific to this compilation unit, since the test driver
- * relies on the software driver. */
-#if( defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || \
- ( defined(PSA_CRYPTO_DRIVER_TEST) && \
- defined(MBEDTLS_PSA_CRYPTO_CONFIG) && \
- defined(MBEDTLS_PSA_ACCEL_ALG_CMAC) ) )
-#define BUILTIN_ALG_CMAC 1
-#endif
-#if( defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || \
- ( defined(PSA_CRYPTO_DRIVER_TEST) && \
- defined(MBEDTLS_PSA_CRYPTO_CONFIG) && \
- defined(MBEDTLS_PSA_ACCEL_ALG_HMAC) ) )
-#define BUILTIN_ALG_HMAC 1
-#endif
-
-#if defined(BUILTIN_ALG_HMAC)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
static psa_status_t psa_hmac_abort_internal(
mbedtls_psa_hmac_operation_t *hmac )
{
@@ -164,9 +149,9 @@
mbedtls_platform_zeroize( tmp, hash_size );
return( status );
}
-#endif /* BUILTIN_ALG_HMAC */
+#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
-#if defined(BUILTIN_ALG_CMAC)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
static psa_status_t cmac_setup( mbedtls_psa_mac_operation_t *operation,
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer )
@@ -202,11 +187,12 @@
exit:
return( mbedtls_to_psa_error( ret ) );
}
-#endif /* BUILTIN_ALG_CMAC */
+#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
/* Implement the PSA driver MAC interface on top of mbed TLS if either the
* software driver or the test driver requires it. */
-#if defined(BUILTIN_ALG_HMAC) || defined(BUILTIN_ALG_CMAC)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || \
+ defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
/* Initialize this driver's MAC operation structure. Once this function has been
* called, mbedtls_psa_mac_abort can run and will do the right thing. */
@@ -218,15 +204,15 @@
operation->alg = alg;
-#if defined(BUILTIN_ALG_CMAC)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
if( PSA_ALG_FULL_LENGTH_MAC( operation->alg ) == PSA_ALG_CMAC )
{
mbedtls_cipher_init( &operation->ctx.cmac );
status = PSA_SUCCESS;
}
else
-#endif /* BUILTIN_ALG_CMAC */
-#if defined(BUILTIN_ALG_HMAC)
+#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
if( PSA_ALG_IS_HMAC( operation->alg ) )
{
/* We'll set up the hash operation later in psa_hmac_setup_internal. */
@@ -234,7 +220,7 @@
status = PSA_SUCCESS;
}
else
-#endif /* BUILTIN_ALG_HMAC */
+#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
{
(void) operation;
status = PSA_ERROR_NOT_SUPPORTED;
@@ -245,7 +231,7 @@
return( status );
}
-static psa_status_t mac_abort( mbedtls_psa_mac_operation_t *operation )
+psa_status_t mbedtls_psa_mac_abort( mbedtls_psa_mac_operation_t *operation )
{
if( operation->alg == 0 )
{
@@ -255,20 +241,20 @@
return( PSA_SUCCESS );
}
else
-#if defined(BUILTIN_ALG_CMAC)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
if( PSA_ALG_FULL_LENGTH_MAC( operation->alg ) == PSA_ALG_CMAC )
{
mbedtls_cipher_free( &operation->ctx.cmac );
}
else
-#endif /* BUILTIN_ALG_CMAC */
-#if defined(BUILTIN_ALG_HMAC)
+#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
if( PSA_ALG_IS_HMAC( operation->alg ) )
{
psa_hmac_abort_internal( &operation->ctx.hmac );
}
else
-#endif /* BUILTIN_ALG_HMAC */
+#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
{
/* Sanity check (shouldn't happen: operation->alg should
* always have been initialized to a valid value). */
@@ -288,11 +274,11 @@
return( PSA_ERROR_BAD_STATE );
}
-static psa_status_t mac_setup( mbedtls_psa_mac_operation_t *operation,
- const psa_key_attributes_t *attributes,
- const uint8_t *key_buffer,
- size_t key_buffer_size,
- psa_algorithm_t alg )
+static psa_status_t psa_mac_setup( mbedtls_psa_mac_operation_t *operation,
+ const psa_key_attributes_t *attributes,
+ const uint8_t *key_buffer,
+ size_t key_buffer_size,
+ psa_algorithm_t alg )
{
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
@@ -304,7 +290,7 @@
if( status != PSA_SUCCESS )
return( status );
-#if defined(BUILTIN_ALG_CMAC)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
if( PSA_ALG_FULL_LENGTH_MAC( alg ) == PSA_ALG_CMAC )
{
/* Key buffer size for CMAC is dictated by the key bits set on the
@@ -313,8 +299,8 @@
status = cmac_setup( operation, attributes, key_buffer );
}
else
-#endif /* BUILTIN_ALG_CMAC */
-#if defined(BUILTIN_ALG_HMAC)
+#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
if( PSA_ALG_IS_HMAC( alg ) )
{
status = psa_hmac_setup_internal( &operation->ctx.hmac,
@@ -323,7 +309,7 @@
PSA_ALG_HMAC_GET_HASH( alg ) );
}
else
-#endif /* BUILTIN_ALG_HMAC */
+#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
{
(void) attributes;
(void) key_buffer;
@@ -332,12 +318,34 @@
}
if( status != PSA_SUCCESS )
- mac_abort( operation );
+ mbedtls_psa_mac_abort( operation );
return( status );
}
-static psa_status_t mac_update(
+psa_status_t mbedtls_psa_mac_sign_setup(
+ mbedtls_psa_mac_operation_t *operation,
+ const psa_key_attributes_t *attributes,
+ const uint8_t *key_buffer,
+ size_t key_buffer_size,
+ psa_algorithm_t alg )
+{
+ return( psa_mac_setup( operation, attributes,
+ key_buffer, key_buffer_size, alg ) );
+}
+
+psa_status_t mbedtls_psa_mac_verify_setup(
+ mbedtls_psa_mac_operation_t *operation,
+ const psa_key_attributes_t *attributes,
+ const uint8_t *key_buffer,
+ size_t key_buffer_size,
+ psa_algorithm_t alg )
+{
+ return( psa_mac_setup( operation, attributes,
+ key_buffer, key_buffer_size, alg ) );
+}
+
+psa_status_t mbedtls_psa_mac_update(
mbedtls_psa_mac_operation_t *operation,
const uint8_t *input,
size_t input_length )
@@ -345,7 +353,7 @@
if( operation->alg == 0 )
return( PSA_ERROR_BAD_STATE );
-#if defined(BUILTIN_ALG_CMAC)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
if( PSA_ALG_FULL_LENGTH_MAC( operation->alg ) == PSA_ALG_CMAC )
{
return( mbedtls_to_psa_error(
@@ -353,15 +361,15 @@
input, input_length ) ) );
}
else
-#endif /* BUILTIN_ALG_CMAC */
-#if defined(BUILTIN_ALG_HMAC)
+#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
if( PSA_ALG_IS_HMAC( operation->alg ) )
{
return( psa_hmac_update_internal( &operation->ctx.hmac,
input, input_length ) );
}
else
-#endif /* BUILTIN_ALG_HMAC */
+#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
{
/* This shouldn't happen if `operation` was initialized by
* a setup function. */
@@ -371,11 +379,11 @@
}
}
-static psa_status_t mac_finish_internal( mbedtls_psa_mac_operation_t *operation,
- uint8_t *mac,
- size_t mac_size )
+static psa_status_t psa_mac_finish_internal(
+ mbedtls_psa_mac_operation_t *operation,
+ uint8_t *mac, size_t mac_size )
{
-#if defined(BUILTIN_ALG_CMAC)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
if( PSA_ALG_FULL_LENGTH_MAC( operation->alg ) == PSA_ALG_CMAC )
{
uint8_t tmp[PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE];
@@ -386,15 +394,15 @@
return( mbedtls_to_psa_error( ret ) );
}
else
-#endif /* BUILTIN_ALG_CMAC */
-#if defined(BUILTIN_ALG_HMAC)
+#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
if( PSA_ALG_IS_HMAC( operation->alg ) )
{
return( psa_hmac_finish_internal( &operation->ctx.hmac,
mac, mac_size ) );
}
else
-#endif /* BUILTIN_ALG_HMAC */
+#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
{
/* This shouldn't happen if `operation` was initialized by
* a setup function. */
@@ -405,7 +413,7 @@
}
}
-static psa_status_t mac_sign_finish(
+psa_status_t mbedtls_psa_mac_sign_finish(
mbedtls_psa_mac_operation_t *operation,
uint8_t *mac,
size_t mac_size,
@@ -416,15 +424,14 @@
if( operation->alg == 0 )
return( PSA_ERROR_BAD_STATE );
- status = mac_finish_internal( operation, mac, mac_size );
-
+ status = psa_mac_finish_internal( operation, mac, mac_size );
if( status == PSA_SUCCESS )
*mac_length = mac_size;
return( status );
}
-static psa_status_t mac_verify_finish(
+psa_status_t mbedtls_psa_mac_verify_finish(
mbedtls_psa_mac_operation_t *operation,
const uint8_t *mac,
size_t mac_length )
@@ -439,7 +446,7 @@
if( mac_length > sizeof( actual_mac ) )
return( PSA_ERROR_INVALID_ARGUMENT );
- status = mac_finish_internal( operation, actual_mac, mac_length );
+ status = psa_mac_finish_internal( operation, actual_mac, mac_length );
if( status != PSA_SUCCESS )
goto cleanup;
@@ -452,7 +459,7 @@
return( status );
}
-static psa_status_t mac_compute(
+psa_status_t mbedtls_psa_mac_compute(
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
@@ -466,212 +473,29 @@
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
mbedtls_psa_mac_operation_t operation = MBEDTLS_PSA_MAC_OPERATION_INIT;
- status = mac_setup( &operation,
- attributes, key_buffer, key_buffer_size,
- alg );
+ status = psa_mac_setup( &operation,
+ attributes, key_buffer, key_buffer_size,
+ alg );
if( status != PSA_SUCCESS )
goto exit;
if( input_length > 0 )
{
- status = mac_update( &operation, input, input_length );
+ status = mbedtls_psa_mac_update( &operation, input, input_length );
if( status != PSA_SUCCESS )
goto exit;
}
- status = mac_finish_internal( &operation, mac, mac_size );
+ status = psa_mac_finish_internal( &operation, mac, mac_size );
if( status == PSA_SUCCESS )
*mac_length = mac_size;
exit:
- mac_abort( &operation );
+ mbedtls_psa_mac_abort( &operation );
return( status );
}
-#endif /* BUILTIN_ALG_HMAC || BUILTIN_ALG_CMAC */
-
-#if defined(MBEDTLS_PSA_BUILTIN_MAC)
-psa_status_t mbedtls_psa_mac_compute(
- const psa_key_attributes_t *attributes,
- const uint8_t *key_buffer,
- size_t key_buffer_size,
- psa_algorithm_t alg,
- const uint8_t *input,
- size_t input_length,
- uint8_t *mac,
- size_t mac_size,
- size_t *mac_length )
-{
- return( mac_compute( attributes, key_buffer, key_buffer_size, alg,
- input, input_length,
- mac, mac_size, mac_length ) );
-}
-
-psa_status_t mbedtls_psa_mac_sign_setup(
- mbedtls_psa_mac_operation_t *operation,
- const psa_key_attributes_t *attributes,
- const uint8_t *key_buffer,
- size_t key_buffer_size,
- psa_algorithm_t alg )
-{
- return( mac_setup( operation, attributes,
- key_buffer, key_buffer_size, alg ) );
-}
-
-psa_status_t mbedtls_psa_mac_verify_setup(
- mbedtls_psa_mac_operation_t *operation,
- const psa_key_attributes_t *attributes,
- const uint8_t *key_buffer,
- size_t key_buffer_size,
- psa_algorithm_t alg )
-{
- return( mac_setup( operation, attributes,
- key_buffer, key_buffer_size, alg ) );
-}
-
-psa_status_t mbedtls_psa_mac_update(
- mbedtls_psa_mac_operation_t *operation,
- const uint8_t *input,
- size_t input_length )
-{
- return( mac_update( operation, input, input_length ) );
-}
-
-psa_status_t mbedtls_psa_mac_sign_finish(
- mbedtls_psa_mac_operation_t *operation,
- uint8_t *mac,
- size_t mac_size,
- size_t *mac_length )
-{
- return( mac_sign_finish( operation, mac, mac_size, mac_length ) );
-}
-
-psa_status_t mbedtls_psa_mac_verify_finish(
- mbedtls_psa_mac_operation_t *operation,
- const uint8_t *mac,
- size_t mac_length )
-{
- return( mac_verify_finish( operation, mac, mac_length ) );
-}
-
-psa_status_t mbedtls_psa_mac_abort(
- mbedtls_psa_mac_operation_t *operation )
-{
- return( mac_abort( operation ) );
-}
-#endif /* MBEDTLS_PSA_BUILTIN_MAC */
-
- /*
- * BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
- */
-#if defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_CRYPTO_CONFIG)
-
-static int is_mac_accelerated( psa_algorithm_t alg )
-{
-#if defined(MBEDTLS_PSA_ACCEL_ALG_HMAC)
- if( PSA_ALG_IS_HMAC( alg ) )
- return( 1 );
-#endif
-
- switch( PSA_ALG_FULL_LENGTH_MAC( alg ) )
- {
-#if defined(MBEDTLS_PSA_ACCEL_ALG_CMAC)
- case PSA_ALG_CMAC:
- return( 1 );
-#endif
- default:
- return( 0 );
- }
-}
-
-psa_status_t libtestdriver1_mbedtls_psa_mac_compute(
- const psa_key_attributes_t *attributes,
- const uint8_t *key_buffer,
- size_t key_buffer_size,
- psa_algorithm_t alg,
- const uint8_t *input,
- size_t input_length,
- uint8_t *mac,
- size_t mac_size,
- size_t *mac_length )
-{
- if( is_mac_accelerated( alg ) )
- return( mac_compute( attributes, key_buffer, key_buffer_size, alg,
- input, input_length,
- mac, mac_size, mac_length ) );
- else
- return( PSA_ERROR_NOT_SUPPORTED );
-}
-
-psa_status_t libtestdriver1_mbedtls_psa_mac_sign_setup(
- mbedtls_psa_mac_operation_t *operation,
- const psa_key_attributes_t *attributes,
- const uint8_t *key_buffer,
- size_t key_buffer_size,
- psa_algorithm_t alg )
-{
- if( is_mac_accelerated( alg ) )
- return( mac_setup( operation, attributes,
- key_buffer, key_buffer_size, alg ) );
- else
- return( PSA_ERROR_NOT_SUPPORTED );
-}
-
-psa_status_t libtestdriver1_mbedtls_psa_mac_verify_setup(
- mbedtls_psa_mac_operation_t *operation,
- const psa_key_attributes_t *attributes,
- const uint8_t *key_buffer,
- size_t key_buffer_size,
- psa_algorithm_t alg )
-{
- if( is_mac_accelerated( alg ) )
- return( mac_setup( operation, attributes,
- key_buffer, key_buffer_size, alg ) );
- else
- return( PSA_ERROR_NOT_SUPPORTED );
-}
-
-psa_status_t libtestdriver1_mbedtls_psa_mac_update(
- mbedtls_psa_mac_operation_t *operation,
- const uint8_t *input,
- size_t input_length )
-{
- if( is_mac_accelerated( operation->alg ) )
- return( mac_update( operation, input, input_length ) );
- else
- return( PSA_ERROR_BAD_STATE );
-}
-
-psa_status_t libtestdriver1_mbedtls_psa_mac_sign_finish(
- mbedtls_psa_mac_operation_t *operation,
- uint8_t *mac,
- size_t mac_size,
- size_t *mac_length )
-{
- if( is_mac_accelerated( operation->alg ) )
- return( mac_sign_finish( operation, mac, mac_size, mac_length ) );
- else
- return( PSA_ERROR_BAD_STATE );
-}
-
-psa_status_t libtestdriver1_mbedtls_psa_mac_verify_finish(
- mbedtls_psa_mac_operation_t *operation,
- const uint8_t *mac,
- size_t mac_length )
-{
- if( is_mac_accelerated( operation->alg ) )
- return( mac_verify_finish( operation, mac, mac_length ) );
- else
- return( PSA_ERROR_BAD_STATE );
-}
-
-psa_status_t libtestdriver1_mbedtls_psa_mac_abort(
- mbedtls_psa_mac_operation_t *operation )
-{
- return( mac_abort( operation ) );
-}
-
-#endif /* PSA_CRYPTO_DRIVER_TEST && MBEDTLS_PSA_CRYPTO_CONFIG */
+#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC || MBEDTLS_PSA_BUILTIN_ALG_CMAC */
#endif /* MBEDTLS_PSA_CRYPTO_C */