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_hash.c b/library/psa_crypto_hash.c
index 3ecc954..f8f7fc6 100644
--- a/library/psa_crypto_hash.c
+++ b/library/psa_crypto_hash.c
@@ -29,51 +29,6 @@
#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_MD5) || \
- ( defined(PSA_CRYPTO_DRIVER_TEST) && \
- defined(MBEDTLS_PSA_CRYPTO_CONFIG) && \
- defined(MBEDTLS_PSA_ACCEL_ALG_MD5) ) )
-#define BUILTIN_ALG_MD5 1
-#endif
-#if( defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) || \
- ( defined(PSA_CRYPTO_DRIVER_TEST) && \
- defined(MBEDTLS_PSA_CRYPTO_CONFIG) && \
- defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160) ) )
-#define BUILTIN_ALG_RIPEMD160 1
-#endif
-#if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) || \
- ( defined(PSA_CRYPTO_DRIVER_TEST) && \
- defined(MBEDTLS_PSA_CRYPTO_CONFIG) && \
- defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1) ) )
-#define BUILTIN_ALG_SHA_1 1
-#endif
-#if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) || \
- ( defined(PSA_CRYPTO_DRIVER_TEST) && \
- defined(MBEDTLS_PSA_CRYPTO_CONFIG) && \
- defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) ) )
-#define BUILTIN_ALG_SHA_224 1
-#endif
-#if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \
- ( defined(PSA_CRYPTO_DRIVER_TEST) && \
- defined(MBEDTLS_PSA_CRYPTO_CONFIG) && \
- defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256) ) )
-#define BUILTIN_ALG_SHA_256 1
-#endif
-#if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) || \
- ( defined(PSA_CRYPTO_DRIVER_TEST) && \
- defined(MBEDTLS_PSA_CRYPTO_CONFIG) && \
- defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) ) )
-#define BUILTIN_ALG_SHA_384 1
-#endif
-#if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) || \
- ( defined(PSA_CRYPTO_DRIVER_TEST) && \
- defined(MBEDTLS_PSA_CRYPTO_CONFIG) && \
- defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) ) )
-#define BUILTIN_ALG_SHA_512 1
-#endif
-
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) || \
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) || \
@@ -121,9 +76,8 @@
/* Implement the PSA driver hash interface on top of mbed TLS if either the
* software driver or the test driver requires it. */
-#if defined(MBEDTLS_PSA_BUILTIN_HASH) || \
- ( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_CRYPTO_CONFIG) )
-static psa_status_t hash_abort(
+#if defined(MBEDTLS_PSA_BUILTIN_HASH)
+psa_status_t mbedtls_psa_hash_abort(
mbedtls_psa_hash_operation_t *operation )
{
switch( operation->alg )
@@ -133,37 +87,37 @@
* in use. It's ok to call abort on such an object, and there's
* nothing to do. */
break;
-#if defined(BUILTIN_ALG_MD5)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5)
case PSA_ALG_MD5:
mbedtls_md5_free( &operation->ctx.md5 );
break;
#endif
-#if defined(BUILTIN_ALG_RIPEMD160)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160)
case PSA_ALG_RIPEMD160:
mbedtls_ripemd160_free( &operation->ctx.ripemd160 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_1)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1)
case PSA_ALG_SHA_1:
mbedtls_sha1_free( &operation->ctx.sha1 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_224)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224)
case PSA_ALG_SHA_224:
mbedtls_sha256_free( &operation->ctx.sha256 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_256)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256)
case PSA_ALG_SHA_256:
mbedtls_sha256_free( &operation->ctx.sha256 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_384)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384)
case PSA_ALG_SHA_384:
mbedtls_sha512_free( &operation->ctx.sha512 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_512)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512)
case PSA_ALG_SHA_512:
mbedtls_sha512_free( &operation->ctx.sha512 );
break;
@@ -175,7 +129,7 @@
return( PSA_SUCCESS );
}
-static psa_status_t hash_setup(
+psa_status_t mbedtls_psa_hash_setup(
mbedtls_psa_hash_operation_t *operation,
psa_algorithm_t alg )
{
@@ -189,43 +143,43 @@
switch( alg )
{
-#if defined(BUILTIN_ALG_MD5)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5)
case PSA_ALG_MD5:
mbedtls_md5_init( &operation->ctx.md5 );
ret = mbedtls_md5_starts( &operation->ctx.md5 );
break;
#endif
-#if defined(BUILTIN_ALG_RIPEMD160)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160)
case PSA_ALG_RIPEMD160:
mbedtls_ripemd160_init( &operation->ctx.ripemd160 );
ret = mbedtls_ripemd160_starts( &operation->ctx.ripemd160 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_1)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1)
case PSA_ALG_SHA_1:
mbedtls_sha1_init( &operation->ctx.sha1 );
ret = mbedtls_sha1_starts( &operation->ctx.sha1 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_224)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224)
case PSA_ALG_SHA_224:
mbedtls_sha256_init( &operation->ctx.sha256 );
ret = mbedtls_sha256_starts( &operation->ctx.sha256, 1 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_256)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256)
case PSA_ALG_SHA_256:
mbedtls_sha256_init( &operation->ctx.sha256 );
ret = mbedtls_sha256_starts( &operation->ctx.sha256, 0 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_384)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384)
case PSA_ALG_SHA_384:
mbedtls_sha512_init( &operation->ctx.sha512 );
ret = mbedtls_sha512_starts( &operation->ctx.sha512, 1 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_512)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512)
case PSA_ALG_SHA_512:
mbedtls_sha512_init( &operation->ctx.sha512 );
ret = mbedtls_sha512_starts( &operation->ctx.sha512, 0 );
@@ -239,11 +193,11 @@
if( ret == 0 )
operation->alg = alg;
else
- hash_abort( operation );
+ mbedtls_psa_hash_abort( operation );
return( mbedtls_to_psa_error( ret ) );
}
-static psa_status_t hash_clone(
+psa_status_t mbedtls_psa_hash_clone(
const mbedtls_psa_hash_operation_t *source_operation,
mbedtls_psa_hash_operation_t *target_operation )
{
@@ -251,43 +205,43 @@
{
case 0:
return( PSA_ERROR_BAD_STATE );
-#if defined(BUILTIN_ALG_MD5)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5)
case PSA_ALG_MD5:
mbedtls_md5_clone( &target_operation->ctx.md5,
&source_operation->ctx.md5 );
break;
#endif
-#if defined(BUILTIN_ALG_RIPEMD160)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160)
case PSA_ALG_RIPEMD160:
mbedtls_ripemd160_clone( &target_operation->ctx.ripemd160,
&source_operation->ctx.ripemd160 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_1)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1)
case PSA_ALG_SHA_1:
mbedtls_sha1_clone( &target_operation->ctx.sha1,
&source_operation->ctx.sha1 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_224)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224)
case PSA_ALG_SHA_224:
mbedtls_sha256_clone( &target_operation->ctx.sha256,
&source_operation->ctx.sha256 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_256)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256)
case PSA_ALG_SHA_256:
mbedtls_sha256_clone( &target_operation->ctx.sha256,
&source_operation->ctx.sha256 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_384)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384)
case PSA_ALG_SHA_384:
mbedtls_sha512_clone( &target_operation->ctx.sha512,
&source_operation->ctx.sha512 );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_512)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512)
case PSA_ALG_SHA_512:
mbedtls_sha512_clone( &target_operation->ctx.sha512,
&source_operation->ctx.sha512 );
@@ -303,7 +257,7 @@
return( PSA_SUCCESS );
}
-static psa_status_t hash_update(
+psa_status_t mbedtls_psa_hash_update(
mbedtls_psa_hash_operation_t *operation,
const uint8_t *input,
size_t input_length )
@@ -312,43 +266,43 @@
switch( operation->alg )
{
-#if defined(BUILTIN_ALG_MD5)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5)
case PSA_ALG_MD5:
ret = mbedtls_md5_update( &operation->ctx.md5,
input, input_length );
break;
#endif
-#if defined(BUILTIN_ALG_RIPEMD160)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160)
case PSA_ALG_RIPEMD160:
ret = mbedtls_ripemd160_update( &operation->ctx.ripemd160,
input, input_length );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_1)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1)
case PSA_ALG_SHA_1:
ret = mbedtls_sha1_update( &operation->ctx.sha1,
input, input_length );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_224)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224)
case PSA_ALG_SHA_224:
ret = mbedtls_sha256_update( &operation->ctx.sha256,
input, input_length );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_256)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256)
case PSA_ALG_SHA_256:
ret = mbedtls_sha256_update( &operation->ctx.sha256,
input, input_length );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_384)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384)
case PSA_ALG_SHA_384:
ret = mbedtls_sha512_update( &operation->ctx.sha512,
input, input_length );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_512)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512)
case PSA_ALG_SHA_512:
ret = mbedtls_sha512_update( &operation->ctx.sha512,
input, input_length );
@@ -363,7 +317,7 @@
return( mbedtls_to_psa_error( ret ) );
}
-static psa_status_t hash_finish(
+psa_status_t mbedtls_psa_hash_finish(
mbedtls_psa_hash_operation_t *operation,
uint8_t *hash,
size_t hash_size,
@@ -390,37 +344,37 @@
switch( operation->alg )
{
-#if defined(BUILTIN_ALG_MD5)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5)
case PSA_ALG_MD5:
ret = mbedtls_md5_finish( &operation->ctx.md5, hash );
break;
#endif
-#if defined(BUILTIN_ALG_RIPEMD160)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160)
case PSA_ALG_RIPEMD160:
ret = mbedtls_ripemd160_finish( &operation->ctx.ripemd160, hash );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_1)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1)
case PSA_ALG_SHA_1:
ret = mbedtls_sha1_finish( &operation->ctx.sha1, hash );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_224)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224)
case PSA_ALG_SHA_224:
ret = mbedtls_sha256_finish( &operation->ctx.sha256, hash );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_256)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256)
case PSA_ALG_SHA_256:
ret = mbedtls_sha256_finish( &operation->ctx.sha256, hash );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_384)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384)
case PSA_ALG_SHA_384:
ret = mbedtls_sha512_finish( &operation->ctx.sha512, hash );
break;
#endif
-#if defined(BUILTIN_ALG_SHA_512)
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512)
case PSA_ALG_SHA_512:
ret = mbedtls_sha512_finish( &operation->ctx.sha512, hash );
break;
@@ -437,7 +391,7 @@
return( status );
}
-static psa_status_t hash_compute(
+psa_status_t mbedtls_psa_hash_compute(
psa_algorithm_t alg,
const uint8_t *input,
size_t input_length,
@@ -450,184 +404,24 @@
psa_status_t abort_status = PSA_ERROR_CORRUPTION_DETECTED;
*hash_length = hash_size;
- status = hash_setup( &operation, alg );
+ status = mbedtls_psa_hash_setup( &operation, alg );
if( status != PSA_SUCCESS )
goto exit;
- status = hash_update( &operation, input, input_length );
+ status = mbedtls_psa_hash_update( &operation, input, input_length );
if( status != PSA_SUCCESS )
goto exit;
- status = hash_finish( &operation, hash, hash_size, hash_length );
+ status = mbedtls_psa_hash_finish( &operation, hash, hash_size, hash_length );
if( status != PSA_SUCCESS )
goto exit;
exit:
- abort_status = hash_abort( &operation );
+ abort_status = mbedtls_psa_hash_abort( &operation );
if( status == PSA_SUCCESS )
return( abort_status );
else
return( status );
}
-#endif /* MBEDTLS_PSA_BUILTIN_HASH ||
- ( PSA_CRYPTO_DRIVER_TEST && MBEDTLS_PSA_CRYPTO_CONFIG ) */
-
-#if defined(MBEDTLS_PSA_BUILTIN_HASH)
-psa_status_t mbedtls_psa_hash_compute(
- psa_algorithm_t alg,
- const uint8_t *input,
- size_t input_length,
- uint8_t *hash,
- size_t hash_size,
- size_t *hash_length)
-{
- return( hash_compute( alg, input, input_length,
- hash, hash_size, hash_length ) );
-}
-
-psa_status_t mbedtls_psa_hash_setup(
- mbedtls_psa_hash_operation_t *operation,
- psa_algorithm_t alg )
-{
- return( hash_setup( operation, alg ) );
-}
-
-psa_status_t mbedtls_psa_hash_clone(
- const mbedtls_psa_hash_operation_t *source_operation,
- mbedtls_psa_hash_operation_t *target_operation )
-{
- return( hash_clone( source_operation, target_operation ) );
-}
-
-psa_status_t mbedtls_psa_hash_update(
- mbedtls_psa_hash_operation_t *operation,
- const uint8_t *input,
- size_t input_length )
-{
- return( hash_update( operation, input, input_length ) );
-}
-
-psa_status_t mbedtls_psa_hash_finish(
- mbedtls_psa_hash_operation_t *operation,
- uint8_t *hash,
- size_t hash_size,
- size_t *hash_length )
-{
- return( hash_finish( operation, hash, hash_size, hash_length ) );
-}
-
-psa_status_t mbedtls_psa_hash_abort(
- mbedtls_psa_hash_operation_t *operation )
-{
- return( hash_abort( operation ) );
-}
#endif /* MBEDTLS_PSA_BUILTIN_HASH */
- /*
- * BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
- */
-#if defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_CRYPTO_CONFIG)
-
-static int is_hash_accelerated( psa_algorithm_t alg )
-{
- switch( alg )
- {
-#if defined(MBEDTLS_PSA_ACCEL_ALG_MD5)
- case PSA_ALG_MD5:
- return( 1 );
-#endif
-#if defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160)
- case PSA_ALG_RIPEMD160:
- return( 1 );
-#endif
-#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1)
- case PSA_ALG_SHA_1:
- return( 1 );
-#endif
-#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224)
- case PSA_ALG_SHA_224:
- return( 1 );
-#endif
-#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
- case PSA_ALG_SHA_256:
- return( 1 );
-#endif
-#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384)
- case PSA_ALG_SHA_384:
- return( 1 );
-#endif
-#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512)
- case PSA_ALG_SHA_512:
- return( 1 );
-#endif
- default:
- return( 0 );
- }
-}
-
-psa_status_t libtestdriver1_mbedtls_psa_hash_compute(
- psa_algorithm_t alg,
- const uint8_t *input,
- size_t input_length,
- uint8_t *hash,
- size_t hash_size,
- size_t *hash_length)
-{
- if( is_hash_accelerated( alg ) )
- return( hash_compute( alg, input, input_length,
- hash, hash_size, hash_length ) );
- else
- return( PSA_ERROR_NOT_SUPPORTED );
-}
-
-psa_status_t libtestdriver1_mbedtls_psa_hash_setup(
- mbedtls_psa_hash_operation_t *operation,
- psa_algorithm_t alg )
-{
- if( is_hash_accelerated( alg ) )
- return( hash_setup( operation, alg ) );
- else
- return( PSA_ERROR_NOT_SUPPORTED );
-}
-
-psa_status_t libtestdriver1_mbedtls_psa_hash_clone(
- const mbedtls_psa_hash_operation_t *source_operation,
- mbedtls_psa_hash_operation_t *target_operation )
-{
- if( is_hash_accelerated( source_operation->alg ) )
- return( hash_clone( source_operation, target_operation ) );
- else
- return( PSA_ERROR_BAD_STATE );
-}
-
-psa_status_t libtestdriver1_mbedtls_psa_hash_update(
- mbedtls_psa_hash_operation_t *operation,
- const uint8_t *input,
- size_t input_length )
-{
- if( is_hash_accelerated( operation->alg ) )
- return( hash_update( operation, input, input_length ) );
- else
- return( PSA_ERROR_BAD_STATE );
-}
-
-psa_status_t libtestdriver1_mbedtls_psa_hash_finish(
- mbedtls_psa_hash_operation_t *operation,
- uint8_t *hash,
- size_t hash_size,
- size_t *hash_length )
-{
- if( is_hash_accelerated( operation->alg ) )
- return( hash_finish( operation, hash, hash_size, hash_length ) );
- else
- return( PSA_ERROR_BAD_STATE );
-}
-
-psa_status_t libtestdriver1_mbedtls_psa_hash_abort(
- mbedtls_psa_hash_operation_t *operation )
-{
- return( hash_abort( operation ) );
-}
-
-#endif /* PSA_CRYPTO_DRIVER_TEST */
-
#endif /* MBEDTLS_PSA_CRYPTO_C */