From fa036c802432665c950b80a9e43c973661513018 Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Tue, 23 Mar 2021 09:33:25 +0100 Subject: [PATCH 01/12] tests: Add hash transparent test driver hooks Signed-off-by: Ronald Cron --- library/psa_crypto_driver_wrappers.c | 12 +- tests/include/test/drivers/hash.h | 79 +++++++++++ tests/include/test/drivers/test_driver.h | 5 +- tests/src/drivers/hash.c | 160 +++++++++++++++++++++++ visualc/VS2010/mbedTLS.vcxproj | 1 + 5 files changed, 249 insertions(+), 8 deletions(-) create mode 100644 tests/include/test/drivers/hash.h create mode 100644 tests/src/drivers/hash.c diff --git a/library/psa_crypto_driver_wrappers.c b/library/psa_crypto_driver_wrappers.c index 11160d82d..aeea16d7b 100644 --- a/library/psa_crypto_driver_wrappers.c +++ b/library/psa_crypto_driver_wrappers.c @@ -1059,7 +1059,7 @@ psa_status_t psa_driver_wrapper_hash_compute( /* Try accelerators first */ #if defined(PSA_CRYPTO_DRIVER_TEST) - status = mbedtls_transparent_test_driver_hash_compute( + status = test_transparent_hash_compute( alg, input, input_length, hash, hash_size, hash_length ); if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -1091,7 +1091,7 @@ psa_status_t psa_driver_wrapper_hash_setup( /* Try setup on accelerators first */ #if defined(PSA_CRYPTO_DRIVER_TEST) - status = mbedtls_transparent_test_driver_hash_setup( + status = test_transparent_hash_setup( &operation->ctx.test_driver_ctx, alg ); if( status == PSA_SUCCESS ) operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; @@ -1131,7 +1131,7 @@ psa_status_t psa_driver_wrapper_hash_clone( #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; - return( mbedtls_transparent_test_driver_hash_clone( + return( test_transparent_hash_clone( &source_operation->ctx.test_driver_ctx, &target_operation->ctx.test_driver_ctx ) ); #endif @@ -1155,7 +1155,7 @@ psa_status_t psa_driver_wrapper_hash_update( #endif #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( mbedtls_transparent_test_driver_hash_update( + return( test_transparent_hash_update( &operation->ctx.test_driver_ctx, input, input_length ) ); #endif @@ -1181,7 +1181,7 @@ psa_status_t psa_driver_wrapper_hash_finish( #endif #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( mbedtls_transparent_test_driver_hash_finish( + return( test_transparent_hash_finish( &operation->ctx.test_driver_ctx, hash, hash_size, hash_length ) ); #endif @@ -1204,7 +1204,7 @@ psa_status_t psa_driver_wrapper_hash_abort( #endif #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( mbedtls_transparent_test_driver_hash_abort( + return( test_transparent_hash_abort( &operation->ctx.test_driver_ctx ) ); #endif default: diff --git a/tests/include/test/drivers/hash.h b/tests/include/test/drivers/hash.h new file mode 100644 index 000000000..7be368982 --- /dev/null +++ b/tests/include/test/drivers/hash.h @@ -0,0 +1,79 @@ +/* + * Test driver for hash driver entry points. + */ +/* Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_TEST_DRIVERS_HASH_H +#define PSA_CRYPTO_TEST_DRIVERS_HASH_H + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined(PSA_CRYPTO_DRIVER_TEST) +#include + +typedef struct { + /* If not PSA_SUCCESS, return this error code instead of processing the + * function call. */ + psa_status_t forced_status; + /* Count the amount of times hash driver entry points are called. */ + unsigned long hits; + /* Status returned by the last hash driver entry point call. */ + psa_status_t driver_status; +} test_driver_hash_hooks_t; + +#define TEST_DRIVER_HASH_INIT { 0, 0, 0 } +static inline test_driver_hash_hooks_t test_driver_hash_hooks_init( void ) +{ + const test_driver_hash_hooks_t v = TEST_DRIVER_HASH_INIT; + return( v ); +} + +extern test_driver_hash_hooks_t test_driver_hash_hooks; + +psa_status_t test_transparent_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 ); + +psa_status_t test_transparent_hash_setup( + mbedtls_transparent_test_driver_hash_operation_t *operation, + psa_algorithm_t alg ); + +psa_status_t test_transparent_hash_clone( + const mbedtls_transparent_test_driver_hash_operation_t *source_operation, + mbedtls_transparent_test_driver_hash_operation_t *target_operation ); + +psa_status_t test_transparent_hash_update( + mbedtls_transparent_test_driver_hash_operation_t *operation, + const uint8_t *input, + size_t input_length ); + +psa_status_t test_transparent_hash_finish( + mbedtls_transparent_test_driver_hash_operation_t *operation, + uint8_t *hash, + size_t hash_size, + size_t *hash_length ); + +psa_status_t test_transparent_hash_abort( + mbedtls_psa_hash_operation_t *operation ); + +#endif /* PSA_CRYPTO_DRIVER_TEST */ +#endif /* PSA_CRYPTO_TEST_DRIVERS_HASH_H */ diff --git a/tests/include/test/drivers/test_driver.h b/tests/include/test/drivers/test_driver.h index 84d0caa5e..dc2136a6a 100644 --- a/tests/include/test/drivers/test_driver.h +++ b/tests/include/test/drivers/test_driver.h @@ -23,9 +23,10 @@ #define PSA_CRYPTO_TEST_DRIVER_LOCATION 0x7fffff #include "test/drivers/aead.h" -#include "test/drivers/signature.h" -#include "test/drivers/key_management.h" #include "test/drivers/cipher.h" +#include "test/drivers/hash.h" +#include "test/drivers/key_management.h" +#include "test/drivers/signature.h" #include "test/drivers/size.h" #endif /* PSA_CRYPTO_TEST_DRIVER_H */ diff --git a/tests/src/drivers/hash.c b/tests/src/drivers/hash.c new file mode 100644 index 000000000..d69a1276c --- /dev/null +++ b/tests/src/drivers/hash.c @@ -0,0 +1,160 @@ +/* + * Test driver for hash entry points. + */ +/* Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST) +#include "psa_crypto_hash.h" + +#include "test/drivers/hash.h" + +test_driver_hash_hooks_t test_driver_hash_hooks = TEST_DRIVER_HASH_INIT; + +psa_status_t test_transparent_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 ) +{ + test_driver_hash_hooks.hits++; + + if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_hash_hooks.driver_status = + test_driver_hash_hooks.forced_status; + } + else + { + test_driver_hash_hooks.driver_status = + mbedtls_transparent_test_driver_hash_compute( + alg, input, input_length, + hash, hash_size, hash_length ); + } + + return( test_driver_hash_hooks.driver_status ); +} + +psa_status_t test_transparent_hash_setup( + mbedtls_transparent_test_driver_hash_operation_t *operation, + psa_algorithm_t alg ) +{ + test_driver_hash_hooks.hits++; + + if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_hash_hooks.driver_status = + test_driver_hash_hooks.forced_status; + } + else + { + test_driver_hash_hooks.driver_status = + mbedtls_transparent_test_driver_hash_setup( operation, alg ); + } + + return( test_driver_hash_hooks.driver_status ); +} + +psa_status_t test_transparent_hash_clone( + const mbedtls_transparent_test_driver_hash_operation_t *source_operation, + mbedtls_transparent_test_driver_hash_operation_t *target_operation ) +{ + test_driver_hash_hooks.hits++; + + if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_hash_hooks.driver_status = + test_driver_hash_hooks.forced_status; + } + else + { + test_driver_hash_hooks.driver_status = + mbedtls_transparent_test_driver_hash_clone( source_operation, + target_operation ); + } + + return( test_driver_hash_hooks.driver_status ); +} + +psa_status_t test_transparent_hash_update( + mbedtls_transparent_test_driver_hash_operation_t *operation, + const uint8_t *input, + size_t input_length ) +{ + test_driver_hash_hooks.hits++; + + if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_hash_hooks.driver_status = + test_driver_hash_hooks.forced_status; + } + else + { + test_driver_hash_hooks.driver_status = + mbedtls_transparent_test_driver_hash_update( + operation, input, input_length ); + } + + return( test_driver_hash_hooks.driver_status ); +} + +psa_status_t test_transparent_hash_finish( + mbedtls_transparent_test_driver_hash_operation_t *operation, + uint8_t *hash, + size_t hash_size, + size_t *hash_length ) +{ + test_driver_hash_hooks.hits++; + + if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_hash_hooks.driver_status = + test_driver_hash_hooks.forced_status; + } + else + { + test_driver_hash_hooks.driver_status = + mbedtls_transparent_test_driver_hash_finish( + operation, hash, hash_size, hash_length ); + } + + return( test_driver_hash_hooks.driver_status ); +} + +psa_status_t test_transparent_hash_abort( + mbedtls_transparent_test_driver_hash_operation_t *operation ) +{ + test_driver_hash_hooks.hits++; + + if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_hash_hooks.driver_status = + test_driver_hash_hooks.forced_status; + } + else + { + test_driver_hash_hooks.driver_status = + mbedtls_transparent_test_driver_hash_abort( operation ); + } + + return( test_driver_hash_hooks.driver_status ); +} +#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ diff --git a/visualc/VS2010/mbedTLS.vcxproj b/visualc/VS2010/mbedTLS.vcxproj index eda1caef8..dd36da7ec 100644 --- a/visualc/VS2010/mbedTLS.vcxproj +++ b/visualc/VS2010/mbedTLS.vcxproj @@ -232,6 +232,7 @@ + From 140043a6b9b6e64318acdcf218d17e606ec6ef2d Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Tue, 6 Apr 2021 18:20:29 +0200 Subject: [PATCH 02/12] tests: driver wrapper: Add hash dispatch testing Signed-off-by: Ronald Cron --- ...test_suite_psa_crypto_driver_wrappers.data | 40 ++++ ..._suite_psa_crypto_driver_wrappers.function | 198 ++++++++++++++++++ 2 files changed, 238 insertions(+) diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.data b/tests/suites/test_suite_psa_crypto_driver_wrappers.data index 251388378..64e6023cb 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.data +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.data @@ -267,3 +267,43 @@ builtin_pubkey_export:MBEDTLS_PSA_KEY_ID_BUILTIN_MIN + 1:PSA_KEY_TYPE_ECC_KEY_PA PSA opaque driver builtin pubkey export: not a public key builtin_pubkey_export:MBEDTLS_PSA_KEY_ID_BUILTIN_MIN:PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1):256:PSA_ALG_ECDSA(PSA_ALG_ANY_HASH):"0485f64d89f00be66c88dd937efd6d7c445648dcb701150b8a9509295850f41c1931e571fb8f8c78317a20b380e866584bbc2516c3d2702d792f131a922095fd6c":PSA_ERROR_INVALID_ARGUMENT + +Hash compute: SHA-256, computed by the driver +depends_on:PSA_WANT_ALG_SHA_256 +hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS:PSA_SUCCESS + +Hash compute: SHA-256, fallback +depends_on:MBEDTLS_PSA_BUILTIN_ALG_SHA_256 +hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_SUCCESS + +Hash compute: SHA-256, no fallback +depends_on:!MBEDTLS_PSA_BUILTIN_ALG_SHA_256 +hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_ERROR_NOT_SUPPORTED + +Hash compute: SHA-256, INSUFFICIENT_MEMORY +depends_on:MBEDTLS_PSA_BUILTIN_ALG_SHA_256 +hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY::PSA_ERROR_INSUFFICIENT_MEMORY + +Hash multi-part: SHA-256, computed by the driver +depends_on:PSA_WANT_ALG_SHA_256 +hash_multipart:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS:PSA_SUCCESS + +Hash multi-part: SHA-256, fallback +depends_on:MBEDTLS_PSA_BUILTIN_ALG_SHA_256 +hash_multipart:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_SUCCESS + +Hash multi-part: SHA-256, no fallback +depends_on:!MBEDTLS_PSA_BUILTIN_ALG_SHA_256 +hash_multipart:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_ERROR_NOT_SUPPORTED + +Hash multi-part: SHA-256, INSUFFICIENT_MEMORY +depends_on:MBEDTLS_PSA_BUILTIN_ALG_SHA_256 +hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY::PSA_ERROR_INSUFFICIENT_MEMORY + +Hash clone: SHA-256, clone successful +depends_on:PSA_WANT_ALG_SHA_256 +hash_clone:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS + +Hash clone: SHA-256, clone failure +depends_on:PSA_WANT_ALG_SHA_256 +hash_clone:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function index f16d1d52e..5bd5ba8d3 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function @@ -1046,3 +1046,201 @@ exit: PSA_DONE( ); } /* END_CASE */ + +/* BEGIN_CASE */ +void hash_compute( int alg_arg, + data_t *input, data_t *hash, + int forced_status_arg, + int expected_status_arg ) +{ + psa_algorithm_t alg = alg_arg; + psa_status_t forced_status = forced_status_arg; + psa_status_t expected_status = expected_status_arg; + unsigned char *output = NULL; + size_t output_length; + + test_driver_hash_hooks = test_driver_hash_hooks_init(); + test_driver_hash_hooks.forced_status = forced_status; + + PSA_ASSERT( psa_crypto_init( ) ); + ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); + + TEST_EQUAL( psa_hash_compute( alg, input->x, input->len, + output, PSA_HASH_LENGTH( alg ), + &output_length ), expected_status ); + TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + + if( expected_status == PSA_SUCCESS ) + { + ASSERT_COMPARE( output, output_length, hash->x, hash->len ); + } + +exit: + mbedtls_free( output ); + PSA_DONE( ); + test_driver_hash_hooks = test_driver_hash_hooks_init(); +} +/* END_CASE */ + +/* BEGIN_CASE */ +void hash_multipart( int alg_arg, + data_t *input, data_t *hash, + int forced_status_arg, + int expected_status_arg ) +{ + psa_algorithm_t alg = alg_arg; + psa_status_t forced_status = forced_status_arg; + psa_status_t expected_status = expected_status_arg; + unsigned char *output = NULL; + psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT; + size_t output_length; + + test_driver_hash_hooks = test_driver_hash_hooks_init(); + ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); + + PSA_ASSERT( psa_crypto_init( ) ); + + /* + * Case 1: Force the driver return status for setup. + */ + test_driver_hash_hooks.forced_status = forced_status; + TEST_EQUAL( psa_hash_setup( &operation, alg ), expected_status ); + TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + + if( expected_status == PSA_SUCCESS ) + { + PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) ); + TEST_EQUAL( test_driver_hash_hooks.hits, + forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 2 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + + PSA_ASSERT( psa_hash_finish( &operation, + output, PSA_HASH_LENGTH( alg ), + &output_length ) ); + TEST_EQUAL( test_driver_hash_hooks.hits, + forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 4 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + + ASSERT_COMPARE( output, output_length, hash->x, hash->len ); + } + + /* + * Case 2: Force the driver return status for update. + */ + test_driver_hash_hooks = test_driver_hash_hooks_init(); + PSA_ASSERT( psa_hash_setup( &operation, alg ) ); + TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + test_driver_hash_hooks.forced_status = forced_status; + TEST_EQUAL( psa_hash_update( &operation, input->x, input->len ), + forced_status ); + TEST_EQUAL( test_driver_hash_hooks.hits, + forced_status != PSA_SUCCESS ? 3 : 2 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + + if( forced_status == PSA_SUCCESS ) + { + PSA_ASSERT( psa_hash_finish( &operation, + output, PSA_HASH_LENGTH( alg ), + &output_length ) ); + TEST_EQUAL( test_driver_hash_hooks.hits, 4 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + + ASSERT_COMPARE( output, output_length, hash->x, hash->len ); + } + + /* + * Case 3: Force the driver return status for finish. + */ + test_driver_hash_hooks = test_driver_hash_hooks_init(); + PSA_ASSERT( psa_hash_setup( &operation, alg ) ); + TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) ); + TEST_EQUAL( test_driver_hash_hooks.hits, 2 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + test_driver_hash_hooks.forced_status = forced_status; + TEST_EQUAL( psa_hash_finish( &operation, + output, PSA_HASH_LENGTH( alg ), + &output_length ), forced_status ); + TEST_EQUAL( test_driver_hash_hooks.hits, 4 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + + if( forced_status == PSA_SUCCESS ) + { + ASSERT_COMPARE( output, output_length, hash->x, hash->len ); + } + +exit: + psa_hash_abort( &operation ); + mbedtls_free( output ); + PSA_DONE( ); + test_driver_hash_hooks = test_driver_hash_hooks_init(); +} +/* END_CASE */ + +/* BEGIN_CASE */ +void hash_clone( int alg_arg, + data_t *input, data_t *hash, + int forced_status_arg ) +{ + psa_algorithm_t alg = alg_arg; + psa_status_t forced_status = forced_status_arg; + unsigned char *output = NULL; + psa_hash_operation_t source_operation = PSA_HASH_OPERATION_INIT; + psa_hash_operation_t target_operation = PSA_HASH_OPERATION_INIT; + size_t output_length; + + test_driver_hash_hooks = test_driver_hash_hooks_init(); + ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); + + PSA_ASSERT( psa_crypto_init( ) ); + + /* + * Clone none active operation, the driver shouldn't be called. + */ + TEST_EQUAL( psa_hash_clone( &source_operation, &target_operation ), + PSA_ERROR_BAD_STATE ); + TEST_EQUAL( test_driver_hash_hooks.hits, 0 ); + + PSA_ASSERT( psa_hash_setup( &source_operation, alg ) ); + TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + test_driver_hash_hooks.forced_status = forced_status; + TEST_EQUAL( psa_hash_clone( &source_operation, &target_operation ), + forced_status ); + TEST_EQUAL( test_driver_hash_hooks.hits, + forced_status == PSA_SUCCESS ? 2 : 3 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + + if( forced_status == PSA_SUCCESS ) + { + test_driver_hash_hooks = test_driver_hash_hooks_init(); + PSA_ASSERT( psa_hash_update( &target_operation, + input->x, input->len ) ); + TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + PSA_ASSERT( psa_hash_finish( &target_operation, + output, PSA_HASH_LENGTH( alg ), + &output_length ) ); + TEST_EQUAL( test_driver_hash_hooks.hits, 3 ); + TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + ASSERT_COMPARE( output, output_length, hash->x, hash->len ); + } + +exit: + psa_hash_abort( &source_operation ); + psa_hash_abort( &target_operation ); + mbedtls_free( output ); + PSA_DONE( ); + test_driver_hash_hooks = test_driver_hash_hooks_init(); +} +/* END_CASE */ From b5d59a05b2d833a8d6481a5351e0dcc1354f478e Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Wed, 14 Apr 2021 09:07:03 +0200 Subject: [PATCH 03/12] tests: psa: cipher: Remove out-dated comment Signed-off-by: Ronald Cron --- tests/src/drivers/test_driver_cipher.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/src/drivers/test_driver_cipher.c b/tests/src/drivers/test_driver_cipher.c index 4dc46789b..e241ba446 100644 --- a/tests/src/drivers/test_driver_cipher.c +++ b/tests/src/drivers/test_driver_cipher.c @@ -36,11 +36,6 @@ #include -/* Test driver implements AES-CTR only. Its default behaviour (when its return - * status is not overridden through the hooks) is to take care of all AES-CTR - * operations, and return PSA_ERROR_NOT_SUPPORTED for all others. - * Set test_driver_cipher_hooks.forced_status to PSA_ERROR_NOT_SUPPORTED to use - * fallback even for AES-CTR. */ test_driver_cipher_hooks_t test_driver_cipher_hooks = TEST_DRIVER_CIPHER_INIT; static psa_status_t test_transparent_cipher_oneshot( From 7f13fa2454282b21930045a3f4f9a2835d80425e Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Tue, 13 Apr 2021 12:41:34 +0200 Subject: [PATCH 04/12] tests: psa: Add mbedtls/MBEDTLS prefix to test driver symbols Signed-off-by: Ronald Cron --- library/psa_crypto_driver_wrappers.c | 247 +++++------ tests/include/test/drivers/aead.h | 15 +- tests/include/test/drivers/cipher.h | 43 +- tests/include/test/drivers/hash.h | 23 +- tests/include/test/drivers/key_management.h | 27 +- .../{test_driver.h => mbedtls_test_driver.h} | 0 tests/include/test/drivers/signature.h | 24 +- tests/include/test/drivers/size.h | 35 +- tests/scripts/list-macros.sh | 2 +- tests/src/drivers/hash.c | 87 ++-- tests/src/drivers/platform_builtin_keys.c | 2 +- tests/src/drivers/test_driver_aead.c | 31 +- tests/src/drivers/test_driver_cipher.c | 117 ++--- .../src/drivers/test_driver_key_management.c | 88 ++-- tests/src/drivers/test_driver_signature.c | 38 +- tests/src/drivers/test_driver_size.c | 6 +- ..._suite_psa_crypto_driver_wrappers.function | 412 +++++++++--------- visualc/VS2010/mbedTLS.vcxproj | 4 +- 18 files changed, 623 insertions(+), 578 deletions(-) rename tests/include/test/drivers/{test_driver.h => mbedtls_test_driver.h} (100%) diff --git a/library/psa_crypto_driver_wrappers.c b/library/psa_crypto_driver_wrappers.c index aeea16d7b..d1ec001e6 100644 --- a/library/psa_crypto_driver_wrappers.c +++ b/library/psa_crypto_driver_wrappers.c @@ -37,7 +37,7 @@ #ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #endif -#include "test/drivers/test_driver.h" +#include "test/drivers/mbedtls_test_driver.h" #endif /* PSA_CRYPTO_DRIVER_TEST */ /* Repeat above block for each JSON-declared driver during autogeneration */ @@ -101,7 +101,7 @@ psa_status_t psa_driver_wrapper_sign_hash( * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_signature_sign_hash( attributes, + status = mbedtls_test_transparent_signature_sign_hash( attributes, key_buffer, key_buffer_size, alg, @@ -130,15 +130,15 @@ psa_status_t psa_driver_wrapper_sign_hash( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_signature_sign_hash( attributes, - key_buffer, - key_buffer_size, - alg, - hash, - hash_length, - signature, - signature_size, - signature_length ) ); + return( mbedtls_test_opaque_signature_sign_hash( attributes, + key_buffer, + key_buffer_size, + alg, + hash, + hash_length, + signature, + signature_size, + signature_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: @@ -185,14 +185,15 @@ psa_status_t psa_driver_wrapper_verify_hash( * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_signature_verify_hash( attributes, - key_buffer, - key_buffer_size, - alg, - hash, - hash_length, - signature, - signature_length ); + status = mbedtls_test_transparent_signature_verify_hash( + attributes, + key_buffer, + key_buffer_size, + alg, + hash, + hash_length, + signature, + signature_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -212,14 +213,14 @@ psa_status_t psa_driver_wrapper_verify_hash( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_signature_verify_hash( attributes, - key_buffer, - key_buffer_size, - alg, - hash, - hash_length, - signature, - signature_length ) ); + return( mbedtls_test_opaque_signature_verify_hash( attributes, + key_buffer, + key_buffer_size, + alg, + hash, + hash_length, + signature, + signature_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: @@ -267,37 +268,37 @@ psa_status_t psa_driver_wrapper_get_key_buffer_size( return( PSA_SUCCESS ); } #endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ -#ifdef TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION - *key_buffer_size = test_size_function( key_type, key_bits ); +#ifdef MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION + *key_buffer_size = mbedtls_test_size_function( key_type, key_bits ); return( PSA_SUCCESS ); -#else /* TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ +#else /* MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ if( PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) ) { int public_key_overhead = - ( ( TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY == 1 ) ? - PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) : 0 ); - *key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE - + TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE - + public_key_overhead; + ( ( MBEDTLS_TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY == 1 ) + ? PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) : 0 ); + *key_buffer_size = MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + + MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE + + public_key_overhead; } else if( PSA_KEY_TYPE_IS_PUBLIC_KEY( key_type ) ) { - *key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE - + TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE; + *key_buffer_size = MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + + MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE; } else if ( !PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) && !PSA_KEY_TYPE_IS_PUBLIC_KEY ( key_type ) ) { - *key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE - + TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR - * ( ( key_bits + 7 ) / 8 ); + *key_buffer_size = MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + + ( MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR * + ( ( key_bits + 7 ) / 8 ) ); } else { return( PSA_ERROR_NOT_SUPPORTED ); } return( PSA_SUCCESS ); -#endif /* TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ +#endif /* MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ #endif /* PSA_CRYPTO_DRIVER_TEST */ default: @@ -345,7 +346,7 @@ psa_status_t psa_driver_wrapper_generate_key( { /* Cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_generate_key( + status = mbedtls_test_transparent_generate_key( attributes, key_buffer, key_buffer_size, key_buffer_length ); /* Declared with fallback == true */ @@ -364,7 +365,7 @@ psa_status_t psa_driver_wrapper_generate_key( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - status = test_opaque_generate_key( + status = mbedtls_test_opaque_generate_key( attributes, key_buffer, key_buffer_size, key_buffer_length ); break; #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -428,10 +429,11 @@ psa_status_t psa_driver_wrapper_import_key( * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_import_key( attributes, - data, data_length, - key_buffer, key_buffer_size, - key_buffer_length, bits ); + status = mbedtls_test_transparent_import_key( + attributes, + data, data_length, + key_buffer, key_buffer_size, + key_buffer_length, bits ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -496,12 +498,12 @@ psa_status_t psa_driver_wrapper_export_key( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_export_key( attributes, - key_buffer, - key_buffer_size, - data, - data_size, - data_length ) ); + return( mbedtls_test_opaque_export_key( attributes, + key_buffer, + key_buffer_size, + data, + data_size, + data_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: @@ -547,12 +549,13 @@ psa_status_t psa_driver_wrapper_export_public_key( * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_export_public_key( attributes, - key_buffer, - key_buffer_size, - data, - data_size, - data_length ); + status = mbedtls_test_transparent_export_public_key( + attributes, + key_buffer, + key_buffer_size, + data, + data_size, + data_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -570,12 +573,12 @@ psa_status_t psa_driver_wrapper_export_public_key( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_export_public_key( attributes, - key_buffer, - key_buffer_size, - data, - data_size, - data_length ) ); + return( mbedtls_test_opaque_export_public_key( attributes, + key_buffer, + key_buffer_size, + data, + data_size, + data_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: @@ -594,7 +597,7 @@ psa_status_t psa_driver_wrapper_get_builtin_key( { #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_get_builtin_key( + return( mbedtls_test_opaque_get_builtin_key( slot_number, attributes, key_buffer, key_buffer_size, key_buffer_length ) ); @@ -633,15 +636,15 @@ psa_status_t psa_driver_wrapper_cipher_encrypt( /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_cipher_encrypt( &attributes, - slot->key.data, - slot->key.bytes, - alg, - input, - input_length, - output, - output_size, - output_length ); + status = mbedtls_test_transparent_cipher_encrypt( &attributes, + slot->key.data, + slot->key.bytes, + alg, + input, + input_length, + output, + output_size, + output_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -651,15 +654,15 @@ psa_status_t psa_driver_wrapper_cipher_encrypt( /* Add cases for opaque driver here */ #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_cipher_encrypt( &attributes, - slot->key.data, - slot->key.bytes, - alg, - input, - input_length, - output, - output_size, - output_length ) ); + return( mbedtls_test_opaque_cipher_encrypt( &attributes, + slot->key.data, + slot->key.bytes, + alg, + input, + input_length, + output, + output_size, + output_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ default: /* Key is declared with a lifetime not known to us */ @@ -700,15 +703,15 @@ psa_status_t psa_driver_wrapper_cipher_decrypt( /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_cipher_decrypt( &attributes, - slot->key.data, - slot->key.bytes, - alg, - input, - input_length, - output, - output_size, - output_length ); + status = mbedtls_test_transparent_cipher_decrypt( &attributes, + slot->key.data, + slot->key.bytes, + alg, + input, + input_length, + output, + output_size, + output_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -718,15 +721,15 @@ psa_status_t psa_driver_wrapper_cipher_decrypt( /* Add cases for opaque driver here */ #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_cipher_decrypt( &attributes, - slot->key.data, - slot->key.bytes, - alg, - input, - input_length, - output, - output_size, - output_length ) ); + return( mbedtls_test_opaque_cipher_decrypt( &attributes, + slot->key.data, + slot->key.bytes, + alg, + input, + input_length, + output, + output_size, + output_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ default: /* Key is declared with a lifetime not known to us */ @@ -762,7 +765,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup( * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_cipher_encrypt_setup( + status = mbedtls_test_transparent_cipher_encrypt_setup( &operation->ctx.transparent_test_driver_ctx, attributes, key_buffer, @@ -795,7 +798,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - status = test_opaque_cipher_encrypt_setup( + status = mbedtls_test_opaque_cipher_encrypt_setup( &operation->ctx.opaque_test_driver_ctx, attributes, key_buffer, key_buffer_size, @@ -834,7 +837,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup( * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_cipher_decrypt_setup( + status = mbedtls_test_transparent_cipher_decrypt_setup( &operation->ctx.transparent_test_driver_ctx, attributes, key_buffer, @@ -866,7 +869,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - status = test_opaque_cipher_decrypt_setup( + status = mbedtls_test_opaque_cipher_decrypt_setup( &operation->ctx.opaque_test_driver_ctx, attributes, key_buffer, key_buffer_size, @@ -905,12 +908,12 @@ psa_status_t psa_driver_wrapper_cipher_set_iv( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( test_transparent_cipher_set_iv( + return( mbedtls_test_transparent_cipher_set_iv( &operation->ctx.transparent_test_driver_ctx, iv, iv_length ) ); case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: - return( test_opaque_cipher_set_iv( + return( mbedtls_test_opaque_cipher_set_iv( &operation->ctx.opaque_test_driver_ctx, iv, iv_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -946,13 +949,13 @@ psa_status_t psa_driver_wrapper_cipher_update( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( test_transparent_cipher_update( + return( mbedtls_test_transparent_cipher_update( &operation->ctx.transparent_test_driver_ctx, input, input_length, output, output_size, output_length ) ); case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: - return( test_opaque_cipher_update( + return( mbedtls_test_opaque_cipher_update( &operation->ctx.opaque_test_driver_ctx, input, input_length, output, output_size, output_length ) ); @@ -988,12 +991,12 @@ psa_status_t psa_driver_wrapper_cipher_finish( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( test_transparent_cipher_finish( + return( mbedtls_test_transparent_cipher_finish( &operation->ctx.transparent_test_driver_ctx, output, output_size, output_length ) ); case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: - return( test_opaque_cipher_finish( + return( mbedtls_test_opaque_cipher_finish( &operation->ctx.opaque_test_driver_ctx, output, output_size, output_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -1022,7 +1025,7 @@ psa_status_t psa_driver_wrapper_cipher_abort( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - status = test_transparent_cipher_abort( + status = mbedtls_test_transparent_cipher_abort( &operation->ctx.transparent_test_driver_ctx ); mbedtls_platform_zeroize( &operation->ctx.transparent_test_driver_ctx, @@ -1030,7 +1033,7 @@ psa_status_t psa_driver_wrapper_cipher_abort( return( status ); case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: - status = test_opaque_cipher_abort( + status = mbedtls_test_opaque_cipher_abort( &operation->ctx.opaque_test_driver_ctx ); mbedtls_platform_zeroize( &operation->ctx.opaque_test_driver_ctx, @@ -1059,7 +1062,7 @@ psa_status_t psa_driver_wrapper_hash_compute( /* Try accelerators first */ #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_hash_compute( + status = mbedtls_test_transparent_hash_compute( alg, input, input_length, hash, hash_size, hash_length ); if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -1091,7 +1094,7 @@ psa_status_t psa_driver_wrapper_hash_setup( /* Try setup on accelerators first */ #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_hash_setup( + status = mbedtls_test_transparent_hash_setup( &operation->ctx.test_driver_ctx, alg ); if( status == PSA_SUCCESS ) operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; @@ -1131,7 +1134,7 @@ psa_status_t psa_driver_wrapper_hash_clone( #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; - return( test_transparent_hash_clone( + return( mbedtls_test_transparent_hash_clone( &source_operation->ctx.test_driver_ctx, &target_operation->ctx.test_driver_ctx ) ); #endif @@ -1155,7 +1158,7 @@ psa_status_t psa_driver_wrapper_hash_update( #endif #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( test_transparent_hash_update( + return( mbedtls_test_transparent_hash_update( &operation->ctx.test_driver_ctx, input, input_length ) ); #endif @@ -1181,7 +1184,7 @@ psa_status_t psa_driver_wrapper_hash_finish( #endif #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( test_transparent_hash_finish( + return( mbedtls_test_transparent_hash_finish( &operation->ctx.test_driver_ctx, hash, hash_size, hash_length ) ); #endif @@ -1204,7 +1207,7 @@ psa_status_t psa_driver_wrapper_hash_abort( #endif #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( test_transparent_hash_abort( + return( mbedtls_test_transparent_hash_abort( &operation->ctx.test_driver_ctx ) ); #endif default: @@ -1233,7 +1236,7 @@ psa_status_t psa_driver_wrapper_aead_encrypt( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_aead_encrypt( + status = mbedtls_test_transparent_aead_encrypt( attributes, key_buffer, key_buffer_size, alg, nonce, nonce_length, @@ -1285,7 +1288,7 @@ psa_status_t psa_driver_wrapper_aead_decrypt( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_aead_decrypt( + status = mbedtls_test_transparent_aead_decrypt( attributes, key_buffer, key_buffer_size, alg, nonce, nonce_length, diff --git a/tests/include/test/drivers/aead.h b/tests/include/test/drivers/aead.h index 1be8910a3..2207cb36f 100644 --- a/tests/include/test/drivers/aead.h +++ b/tests/include/test/drivers/aead.h @@ -37,18 +37,19 @@ typedef struct { unsigned long hits; /* Status returned by the last AEAD driver function call. */ psa_status_t driver_status; -} test_driver_aead_hooks_t; +} mbedtls_test_driver_aead_hooks_t; -#define TEST_DRIVER_AEAD_INIT { 0, 0, 0 } -static inline test_driver_aead_hooks_t test_driver_aead_hooks_init( void ) +#define MBEDTLS_TEST_DRIVER_AEAD_INIT { 0, 0, 0 } +static inline mbedtls_test_driver_aead_hooks_t + mbedtls_test_driver_aead_hooks_init( void ) { - const test_driver_aead_hooks_t v = TEST_DRIVER_AEAD_INIT; + const mbedtls_test_driver_aead_hooks_t v = MBEDTLS_TEST_DRIVER_AEAD_INIT; return( v ); } -extern test_driver_aead_hooks_t test_driver_aead_hooks; +extern mbedtls_test_driver_aead_hooks_t mbedtls_test_driver_aead_hooks; -psa_status_t test_transparent_aead_encrypt( +psa_status_t mbedtls_test_transparent_aead_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, @@ -57,7 +58,7 @@ psa_status_t test_transparent_aead_encrypt( const uint8_t *plaintext, size_t plaintext_length, uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length ); -psa_status_t test_transparent_aead_decrypt( +psa_status_t mbedtls_test_transparent_aead_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, diff --git a/tests/include/test/drivers/cipher.h b/tests/include/test/drivers/cipher.h index 6d6a6af42..4fe559618 100644 --- a/tests/include/test/drivers/cipher.h +++ b/tests/include/test/drivers/cipher.h @@ -41,101 +41,102 @@ typedef struct { psa_status_t forced_status; /* Count the amount of times one of the cipher driver functions is called. */ unsigned long hits; -} test_driver_cipher_hooks_t; +} mbedtls_test_driver_cipher_hooks_t; -#define TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 } -static inline test_driver_cipher_hooks_t test_driver_cipher_hooks_init( void ) +#define MBEDTLS_TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 } +static inline mbedtls_test_driver_cipher_hooks_t + mbedtls_test_driver_cipher_hooks_init( void ) { - const test_driver_cipher_hooks_t v = TEST_DRIVER_CIPHER_INIT; + const mbedtls_test_driver_cipher_hooks_t v = MBEDTLS_TEST_DRIVER_CIPHER_INIT; return( v ); } -extern test_driver_cipher_hooks_t test_driver_cipher_hooks; +extern mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks; -psa_status_t test_transparent_cipher_encrypt( +psa_status_t mbedtls_test_transparent_cipher_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length); -psa_status_t test_transparent_cipher_decrypt( +psa_status_t mbedtls_test_transparent_cipher_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length); -psa_status_t test_transparent_cipher_encrypt_setup( +psa_status_t mbedtls_test_transparent_cipher_encrypt_setup( mbedtls_transparent_test_driver_cipher_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg); -psa_status_t test_transparent_cipher_decrypt_setup( +psa_status_t mbedtls_test_transparent_cipher_decrypt_setup( mbedtls_transparent_test_driver_cipher_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg); -psa_status_t test_transparent_cipher_abort( +psa_status_t mbedtls_test_transparent_cipher_abort( mbedtls_transparent_test_driver_cipher_operation_t *operation ); -psa_status_t test_transparent_cipher_set_iv( +psa_status_t mbedtls_test_transparent_cipher_set_iv( mbedtls_transparent_test_driver_cipher_operation_t *operation, const uint8_t *iv, size_t iv_length); -psa_status_t test_transparent_cipher_update( +psa_status_t mbedtls_test_transparent_cipher_update( mbedtls_transparent_test_driver_cipher_operation_t *operation, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length); -psa_status_t test_transparent_cipher_finish( +psa_status_t mbedtls_test_transparent_cipher_finish( mbedtls_transparent_test_driver_cipher_operation_t *operation, uint8_t *output, size_t output_size, size_t *output_length); /* * opaque versions */ -psa_status_t test_opaque_cipher_encrypt( +psa_status_t mbedtls_test_opaque_cipher_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length); -psa_status_t test_opaque_cipher_decrypt( +psa_status_t mbedtls_test_opaque_cipher_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length); -psa_status_t test_opaque_cipher_encrypt_setup( +psa_status_t mbedtls_test_opaque_cipher_encrypt_setup( mbedtls_opaque_test_driver_cipher_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg); -psa_status_t test_opaque_cipher_decrypt_setup( +psa_status_t mbedtls_test_opaque_cipher_decrypt_setup( mbedtls_opaque_test_driver_cipher_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg); -psa_status_t test_opaque_cipher_abort( +psa_status_t mbedtls_test_opaque_cipher_abort( mbedtls_opaque_test_driver_cipher_operation_t *operation); -psa_status_t test_opaque_cipher_set_iv( +psa_status_t mbedtls_test_opaque_cipher_set_iv( mbedtls_opaque_test_driver_cipher_operation_t *operation, const uint8_t *iv, size_t iv_length); -psa_status_t test_opaque_cipher_update( +psa_status_t mbedtls_test_opaque_cipher_update( mbedtls_opaque_test_driver_cipher_operation_t *operation, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length); -psa_status_t test_opaque_cipher_finish( +psa_status_t mbedtls_test_opaque_cipher_finish( mbedtls_opaque_test_driver_cipher_operation_t *operation, uint8_t *output, size_t output_size, size_t *output_length); diff --git a/tests/include/test/drivers/hash.h b/tests/include/test/drivers/hash.h index 7be368982..ebe83dee4 100644 --- a/tests/include/test/drivers/hash.h +++ b/tests/include/test/drivers/hash.h @@ -37,42 +37,43 @@ typedef struct { unsigned long hits; /* Status returned by the last hash driver entry point call. */ psa_status_t driver_status; -} test_driver_hash_hooks_t; +} mbedtls_test_driver_hash_hooks_t; -#define TEST_DRIVER_HASH_INIT { 0, 0, 0 } -static inline test_driver_hash_hooks_t test_driver_hash_hooks_init( void ) +#define MBEDTLS_TEST_DRIVER_HASH_INIT { 0, 0, 0 } +static inline mbedtls_test_driver_hash_hooks_t + mbedtls_test_driver_hash_hooks_init( void ) { - const test_driver_hash_hooks_t v = TEST_DRIVER_HASH_INIT; + const mbedtls_test_driver_hash_hooks_t v = MBEDTLS_TEST_DRIVER_HASH_INIT; return( v ); } -extern test_driver_hash_hooks_t test_driver_hash_hooks; +extern mbedtls_test_driver_hash_hooks_t mbedtls_test_driver_hash_hooks; -psa_status_t test_transparent_hash_compute( +psa_status_t mbedtls_test_transparent_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 ); -psa_status_t test_transparent_hash_setup( +psa_status_t mbedtls_test_transparent_hash_setup( mbedtls_transparent_test_driver_hash_operation_t *operation, psa_algorithm_t alg ); -psa_status_t test_transparent_hash_clone( +psa_status_t mbedtls_test_transparent_hash_clone( const mbedtls_transparent_test_driver_hash_operation_t *source_operation, mbedtls_transparent_test_driver_hash_operation_t *target_operation ); -psa_status_t test_transparent_hash_update( +psa_status_t mbedtls_test_transparent_hash_update( mbedtls_transparent_test_driver_hash_operation_t *operation, const uint8_t *input, size_t input_length ); -psa_status_t test_transparent_hash_finish( +psa_status_t mbedtls_test_transparent_hash_finish( mbedtls_transparent_test_driver_hash_operation_t *operation, uint8_t *hash, size_t hash_size, size_t *hash_length ); -psa_status_t test_transparent_hash_abort( +psa_status_t mbedtls_test_transparent_hash_abort( mbedtls_psa_hash_operation_t *operation ); #endif /* PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/include/test/drivers/key_management.h b/tests/include/test/drivers/key_management.h index 100fc18d3..45814fd03 100644 --- a/tests/include/test/drivers/key_management.h +++ b/tests/include/test/drivers/key_management.h @@ -42,41 +42,44 @@ typedef struct { /* Count the amount of times one of the key management driver functions * is called. */ unsigned long hits; -} test_driver_key_management_hooks_t; +} mbedtls_test_driver_key_management_hooks_t; -#define TEST_DRIVER_KEY_MANAGEMENT_INIT { NULL, 0, PSA_SUCCESS, 0 } -static inline test_driver_key_management_hooks_t test_driver_key_management_hooks_init( void ) +#define MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT { NULL, 0, PSA_SUCCESS, 0 } +static inline mbedtls_test_driver_key_management_hooks_t + mbedtls_test_driver_key_management_hooks_init( void ) { - const test_driver_key_management_hooks_t v = TEST_DRIVER_KEY_MANAGEMENT_INIT; + const mbedtls_test_driver_key_management_hooks_t + v = MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT; return( v ); } -extern test_driver_key_management_hooks_t test_driver_key_management_hooks; +extern mbedtls_test_driver_key_management_hooks_t + mbedtls_test_driver_key_management_hooks; -psa_status_t test_transparent_generate_key( +psa_status_t mbedtls_test_transparent_generate_key( const psa_key_attributes_t *attributes, uint8_t *key, size_t key_size, size_t *key_length ); -psa_status_t test_opaque_generate_key( +psa_status_t mbedtls_test_opaque_generate_key( const psa_key_attributes_t *attributes, uint8_t *key, size_t key_size, size_t *key_length ); -psa_status_t test_opaque_export_key( +psa_status_t mbedtls_test_opaque_export_key( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, uint8_t *data, size_t data_size, size_t *data_length ); -psa_status_t test_transparent_export_public_key( +psa_status_t mbedtls_test_transparent_export_public_key( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, uint8_t *data, size_t data_size, size_t *data_length ); -psa_status_t test_opaque_export_public_key( +psa_status_t mbedtls_test_opaque_export_public_key( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, uint8_t *data, size_t data_size, size_t *data_length ); -psa_status_t test_transparent_import_key( +psa_status_t mbedtls_test_transparent_import_key( const psa_key_attributes_t *attributes, const uint8_t *data, size_t data_length, @@ -85,7 +88,7 @@ psa_status_t test_transparent_import_key( size_t *key_buffer_length, size_t *bits); -psa_status_t test_opaque_get_builtin_key( +psa_status_t mbedtls_test_opaque_get_builtin_key( psa_drv_slot_number_t slot_number, psa_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ); diff --git a/tests/include/test/drivers/test_driver.h b/tests/include/test/drivers/mbedtls_test_driver.h similarity index 100% rename from tests/include/test/drivers/test_driver.h rename to tests/include/test/drivers/mbedtls_test_driver.h diff --git a/tests/include/test/drivers/signature.h b/tests/include/test/drivers/signature.h index e78515125..1586ce9bc 100644 --- a/tests/include/test/drivers/signature.h +++ b/tests/include/test/drivers/signature.h @@ -38,40 +38,44 @@ typedef struct { psa_status_t forced_status; /* Count the amount of times one of the signature driver functions is called. */ unsigned long hits; -} test_driver_signature_hooks_t; +} mbedtls_test_driver_signature_hooks_t; -#define TEST_DRIVER_SIGNATURE_INIT { NULL, 0, PSA_SUCCESS, 0 } -static inline test_driver_signature_hooks_t test_driver_signature_hooks_init( void ) +#define MBEDTLS_TEST_DRIVER_SIGNATURE_INIT { NULL, 0, PSA_SUCCESS, 0 } +static inline mbedtls_test_driver_signature_hooks_t + mbedtls_test_driver_signature_hooks_init( void ) { - const test_driver_signature_hooks_t v = TEST_DRIVER_SIGNATURE_INIT; + const mbedtls_test_driver_signature_hooks_t + v = MBEDTLS_TEST_DRIVER_SIGNATURE_INIT; return( v ); } -extern test_driver_signature_hooks_t test_driver_signature_sign_hooks; -extern test_driver_signature_hooks_t test_driver_signature_verify_hooks; +extern mbedtls_test_driver_signature_hooks_t + mbedtls_test_driver_signature_sign_hooks; +extern mbedtls_test_driver_signature_hooks_t + mbedtls_test_driver_signature_verify_hooks; -psa_status_t test_transparent_signature_sign_hash( +psa_status_t mbedtls_test_transparent_signature_sign_hash( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, uint8_t *signature, size_t signature_size, size_t *signature_length ); -psa_status_t test_opaque_signature_sign_hash( +psa_status_t mbedtls_test_opaque_signature_sign_hash( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, uint8_t *signature, size_t signature_size, size_t *signature_length ); -psa_status_t test_transparent_signature_verify_hash( +psa_status_t mbedtls_test_transparent_signature_verify_hash( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, const uint8_t *signature, size_t signature_length ); -psa_status_t test_opaque_signature_verify_hash( +psa_status_t mbedtls_test_opaque_signature_verify_hash( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, diff --git a/tests/include/test/drivers/size.h b/tests/include/test/drivers/size.h index 4bfe986a2..577e17b8d 100644 --- a/tests/include/test/drivers/size.h +++ b/tests/include/test/drivers/size.h @@ -31,16 +31,17 @@ typedef struct { unsigned int context; -} test_driver_key_context_t; +} mbedtls_test_driver_key_context_t; -/** \def TEST_DRIVER_KEY_CONTEXT_BASE_SIZE +/** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE * * This macro returns the base size for the key context. It is the size of the * driver specific information stored in each key context. */ -#define TEST_DRIVER_KEY_CONTEXT_BASE_SIZE sizeof( test_driver_key_context_t ) +#define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE \ + sizeof( mbedtls_test_driver_key_context_t ) -/** \def TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE +/** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE * * Number of bytes included in every key context for a key pair. * @@ -49,47 +50,47 @@ typedef struct { * subtracting the public key size below from this one. */ -#define TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE 65 +#define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE 65 -/** \def TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE +/** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE * * Number of bytes included in every key context for a public key. * * For ECC public keys, it needs 257 bits so 33 bytes. */ -#define TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE 33 +#define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE 33 -/** \def TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR +/** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR * * Every key context for a symmetric key includes this many times the key size. */ -#define TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR 0 +#define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR 0 -/** \def TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY +/** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY * * If this is true for a key pair, the key context includes space for the public key. * If this is false, no additional space is added for the public key. * * For this instance, store the public key with the private one. */ -#define TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY 1 +#define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY 1 -/** \def TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION +/** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION * - * If TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION is defined, the test driver + * If MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION is defined, the test driver * provides a size_function entry point, otherwise, it does not. * * Some opaque drivers have the need to support a custom size for the storage * of key and context information. The size_function provides the ability to * provide that customization. */ -//#define TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION +//#define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION -#ifdef TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION -size_t test_size_function( +#ifdef MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION +size_t mbedtls_test_size_function( const psa_key_type_t key_type, const size_t key_bits ); -#endif /* TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ +#endif /* MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_TEST_DRIVERS_SIZE_H */ diff --git a/tests/scripts/list-macros.sh b/tests/scripts/list-macros.sh index 2727ff9d5..fd19c471b 100755 --- a/tests/scripts/list-macros.sh +++ b/tests/scripts/list-macros.sh @@ -22,7 +22,7 @@ if [ -d include/mbedtls ]; then :; else exit 1 fi -HEADERS=$( ls include/mbedtls/*.h include/psa/*.h ) +HEADERS=$( ls include/mbedtls/*.h include/psa/*.h tests/include/test/drivers/*.h ) HEADERS="$HEADERS library/*.h" HEADERS="$HEADERS 3rdparty/everest/include/everest/everest.h 3rdparty/everest/include/everest/x25519.h" diff --git a/tests/src/drivers/hash.c b/tests/src/drivers/hash.c index d69a1276c..f95aa6b61 100644 --- a/tests/src/drivers/hash.c +++ b/tests/src/drivers/hash.c @@ -28,133 +28,134 @@ #include "test/drivers/hash.h" -test_driver_hash_hooks_t test_driver_hash_hooks = TEST_DRIVER_HASH_INIT; +mbedtls_test_driver_hash_hooks_t + mbedtls_test_driver_hash_hooks = MBEDTLS_TEST_DRIVER_HASH_INIT; -psa_status_t test_transparent_hash_compute( +psa_status_t mbedtls_test_transparent_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 ) { - test_driver_hash_hooks.hits++; + mbedtls_test_driver_hash_hooks.hits++; - if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS ) { - test_driver_hash_hooks.driver_status = - test_driver_hash_hooks.forced_status; + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.forced_status; } else { - test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.driver_status = mbedtls_transparent_test_driver_hash_compute( alg, input, input_length, hash, hash_size, hash_length ); } - return( test_driver_hash_hooks.driver_status ); + return( mbedtls_test_driver_hash_hooks.driver_status ); } -psa_status_t test_transparent_hash_setup( +psa_status_t mbedtls_test_transparent_hash_setup( mbedtls_transparent_test_driver_hash_operation_t *operation, psa_algorithm_t alg ) { - test_driver_hash_hooks.hits++; + mbedtls_test_driver_hash_hooks.hits++; - if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS ) { - test_driver_hash_hooks.driver_status = - test_driver_hash_hooks.forced_status; + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.forced_status; } else { - test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.driver_status = mbedtls_transparent_test_driver_hash_setup( operation, alg ); } - return( test_driver_hash_hooks.driver_status ); + return( mbedtls_test_driver_hash_hooks.driver_status ); } -psa_status_t test_transparent_hash_clone( +psa_status_t mbedtls_test_transparent_hash_clone( const mbedtls_transparent_test_driver_hash_operation_t *source_operation, mbedtls_transparent_test_driver_hash_operation_t *target_operation ) { - test_driver_hash_hooks.hits++; + mbedtls_test_driver_hash_hooks.hits++; - if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS ) { - test_driver_hash_hooks.driver_status = - test_driver_hash_hooks.forced_status; + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.forced_status; } else { - test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.driver_status = mbedtls_transparent_test_driver_hash_clone( source_operation, target_operation ); } - return( test_driver_hash_hooks.driver_status ); + return( mbedtls_test_driver_hash_hooks.driver_status ); } -psa_status_t test_transparent_hash_update( +psa_status_t mbedtls_test_transparent_hash_update( mbedtls_transparent_test_driver_hash_operation_t *operation, const uint8_t *input, size_t input_length ) { - test_driver_hash_hooks.hits++; + mbedtls_test_driver_hash_hooks.hits++; - if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS ) { - test_driver_hash_hooks.driver_status = - test_driver_hash_hooks.forced_status; + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.forced_status; } else { - test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.driver_status = mbedtls_transparent_test_driver_hash_update( operation, input, input_length ); } - return( test_driver_hash_hooks.driver_status ); + return( mbedtls_test_driver_hash_hooks.driver_status ); } -psa_status_t test_transparent_hash_finish( +psa_status_t mbedtls_test_transparent_hash_finish( mbedtls_transparent_test_driver_hash_operation_t *operation, uint8_t *hash, size_t hash_size, size_t *hash_length ) { - test_driver_hash_hooks.hits++; + mbedtls_test_driver_hash_hooks.hits++; - if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS ) { - test_driver_hash_hooks.driver_status = - test_driver_hash_hooks.forced_status; + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.forced_status; } else { - test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.driver_status = mbedtls_transparent_test_driver_hash_finish( operation, hash, hash_size, hash_length ); } - return( test_driver_hash_hooks.driver_status ); + return( mbedtls_test_driver_hash_hooks.driver_status ); } -psa_status_t test_transparent_hash_abort( +psa_status_t mbedtls_test_transparent_hash_abort( mbedtls_transparent_test_driver_hash_operation_t *operation ) { - test_driver_hash_hooks.hits++; + mbedtls_test_driver_hash_hooks.hits++; - if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS ) { - test_driver_hash_hooks.driver_status = - test_driver_hash_hooks.forced_status; + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.forced_status; } else { - test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.driver_status = mbedtls_transparent_test_driver_hash_abort( operation ); } - return( test_driver_hash_hooks.driver_status ); + return( mbedtls_test_driver_hash_hooks.driver_status ); } #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/src/drivers/platform_builtin_keys.c b/tests/src/drivers/platform_builtin_keys.c index 759fa7830..57d040a78 100644 --- a/tests/src/drivers/platform_builtin_keys.c +++ b/tests/src/drivers/platform_builtin_keys.c @@ -24,7 +24,7 @@ #include #if defined(PSA_CRYPTO_DRIVER_TEST) -#include +#include #endif typedef struct diff --git a/tests/src/drivers/test_driver_aead.c b/tests/src/drivers/test_driver_aead.c index c87752502..25396c92f 100644 --- a/tests/src/drivers/test_driver_aead.c +++ b/tests/src/drivers/test_driver_aead.c @@ -28,9 +28,10 @@ #include "test/drivers/aead.h" -test_driver_aead_hooks_t test_driver_aead_hooks = TEST_DRIVER_AEAD_INIT; +mbedtls_test_driver_aead_hooks_t + mbedtls_test_driver_aead_hooks = MBEDTLS_TEST_DRIVER_AEAD_INIT; -psa_status_t test_transparent_aead_encrypt( +psa_status_t mbedtls_test_transparent_aead_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, @@ -39,16 +40,16 @@ psa_status_t test_transparent_aead_encrypt( const uint8_t *plaintext, size_t plaintext_length, uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length ) { - test_driver_aead_hooks.hits++; + mbedtls_test_driver_aead_hooks.hits++; - if( test_driver_aead_hooks.forced_status != PSA_SUCCESS ) + if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) { - test_driver_aead_hooks.driver_status = - test_driver_aead_hooks.forced_status; + mbedtls_test_driver_aead_hooks.driver_status = + mbedtls_test_driver_aead_hooks.forced_status; } else { - test_driver_aead_hooks.driver_status = + mbedtls_test_driver_aead_hooks.driver_status = mbedtls_psa_aead_encrypt( attributes, key_buffer, key_buffer_size, alg, @@ -58,10 +59,10 @@ psa_status_t test_transparent_aead_encrypt( ciphertext, ciphertext_size, ciphertext_length ); } - return( test_driver_aead_hooks.driver_status ); + return( mbedtls_test_driver_aead_hooks.driver_status ); } -psa_status_t test_transparent_aead_decrypt( +psa_status_t mbedtls_test_transparent_aead_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, @@ -70,16 +71,16 @@ psa_status_t test_transparent_aead_decrypt( const uint8_t *ciphertext, size_t ciphertext_length, uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length ) { - test_driver_aead_hooks.hits++; + mbedtls_test_driver_aead_hooks.hits++; - if( test_driver_aead_hooks.forced_status != PSA_SUCCESS ) + if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) { - test_driver_aead_hooks.driver_status = - test_driver_aead_hooks.forced_status; + mbedtls_test_driver_aead_hooks.driver_status = + mbedtls_test_driver_aead_hooks.forced_status; } else { - test_driver_aead_hooks.driver_status = + mbedtls_test_driver_aead_hooks.driver_status = mbedtls_psa_aead_decrypt( attributes, key_buffer, key_buffer_size, alg, @@ -89,7 +90,7 @@ psa_status_t test_transparent_aead_decrypt( plaintext, plaintext_size, plaintext_length ); } - return( test_driver_aead_hooks.driver_status ); + return( mbedtls_test_driver_aead_hooks.driver_status ); } #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/src/drivers/test_driver_cipher.c b/tests/src/drivers/test_driver_cipher.c index e241ba446..a415dd812 100644 --- a/tests/src/drivers/test_driver_cipher.c +++ b/tests/src/drivers/test_driver_cipher.c @@ -36,9 +36,10 @@ #include -test_driver_cipher_hooks_t test_driver_cipher_hooks = TEST_DRIVER_CIPHER_INIT; +mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks = + MBEDTLS_TEST_DRIVER_CIPHER_INIT; -static psa_status_t test_transparent_cipher_oneshot( +static psa_status_t mbedtls_test_transparent_cipher_oneshot( mbedtls_operation_t direction, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, @@ -46,7 +47,7 @@ static psa_status_t test_transparent_cipher_oneshot( const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length) { - test_driver_cipher_hooks.hits++; + mbedtls_test_driver_cipher_hooks.hits++; /* Test driver supports AES-CTR only, to verify operation calls. */ if( alg != PSA_ALG_CTR || @@ -54,21 +55,21 @@ static psa_status_t test_transparent_cipher_oneshot( return( PSA_ERROR_NOT_SUPPORTED ); /* If test driver response code is not SUCCESS, we can return early */ - if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_cipher_hooks.forced_status ); + if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_cipher_hooks.forced_status ); /* If test driver output is overridden, we don't need to do actual crypto */ - if( test_driver_cipher_hooks.forced_output != NULL ) + if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) { - if( output_size < test_driver_cipher_hooks.forced_output_length ) + if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) return( PSA_ERROR_BUFFER_TOO_SMALL ); memcpy( output, - test_driver_cipher_hooks.forced_output, - test_driver_cipher_hooks.forced_output_length ); - *output_length = test_driver_cipher_hooks.forced_output_length; + mbedtls_test_driver_cipher_hooks.forced_output, + mbedtls_test_driver_cipher_hooks.forced_output_length ); + *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; - return( test_driver_cipher_hooks.forced_status ); + return( mbedtls_test_driver_cipher_hooks.forced_status ); } /* Run AES-CTR using the cipher module */ @@ -166,7 +167,7 @@ exit: } } -psa_status_t test_transparent_cipher_encrypt( +psa_status_t mbedtls_test_transparent_cipher_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, @@ -174,7 +175,7 @@ psa_status_t test_transparent_cipher_encrypt( uint8_t *output, size_t output_size, size_t *output_length) { return ( - test_transparent_cipher_oneshot( + mbedtls_test_transparent_cipher_oneshot( MBEDTLS_ENCRYPT, attributes, key, key_length, @@ -183,7 +184,7 @@ psa_status_t test_transparent_cipher_encrypt( output, output_size, output_length) ); } -psa_status_t test_transparent_cipher_decrypt( +psa_status_t mbedtls_test_transparent_cipher_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, @@ -191,7 +192,7 @@ psa_status_t test_transparent_cipher_decrypt( uint8_t *output, size_t output_size, size_t *output_length) { return ( - test_transparent_cipher_oneshot( + mbedtls_test_transparent_cipher_oneshot( MBEDTLS_DECRYPT, attributes, key, key_length, @@ -200,13 +201,13 @@ psa_status_t test_transparent_cipher_decrypt( output, output_size, output_length) ); } -psa_status_t test_transparent_cipher_encrypt_setup( +psa_status_t mbedtls_test_transparent_cipher_encrypt_setup( mbedtls_transparent_test_driver_cipher_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg) { - test_driver_cipher_hooks.hits++; + mbedtls_test_driver_cipher_hooks.hits++; /* Wiping the entire struct here, instead of member-by-member. This is * useful for the test suite, since it gives a chance of catching memory @@ -214,32 +215,32 @@ psa_status_t test_transparent_cipher_encrypt_setup( * our context struct. */ memset( operation, 0, sizeof( *operation ) ); - if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_cipher_hooks.forced_status ); + if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_cipher_hooks.forced_status ); return ( mbedtls_transparent_test_driver_cipher_encrypt_setup( operation, attributes, key, key_length, alg ) ); } -psa_status_t test_transparent_cipher_decrypt_setup( +psa_status_t mbedtls_test_transparent_cipher_decrypt_setup( mbedtls_transparent_test_driver_cipher_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg) { - test_driver_cipher_hooks.hits++; + mbedtls_test_driver_cipher_hooks.hits++; - if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_cipher_hooks.forced_status ); + if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_cipher_hooks.forced_status ); return ( mbedtls_transparent_test_driver_cipher_decrypt_setup( operation, attributes, key, key_length, alg ) ); } -psa_status_t test_transparent_cipher_abort( +psa_status_t mbedtls_test_transparent_cipher_abort( mbedtls_transparent_test_driver_cipher_operation_t *operation) { - test_driver_cipher_hooks.hits++; + mbedtls_test_driver_cipher_hooks.hits++; if( operation->alg == 0 ) return( PSA_SUCCESS ); @@ -252,24 +253,24 @@ psa_status_t test_transparent_cipher_abort( * our context struct. */ memset( operation, 0, sizeof( *operation ) ); - return( test_driver_cipher_hooks.forced_status ); + return( mbedtls_test_driver_cipher_hooks.forced_status ); } -psa_status_t test_transparent_cipher_set_iv( +psa_status_t mbedtls_test_transparent_cipher_set_iv( mbedtls_transparent_test_driver_cipher_operation_t *operation, const uint8_t *iv, size_t iv_length) { - test_driver_cipher_hooks.hits++; + mbedtls_test_driver_cipher_hooks.hits++; - if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_cipher_hooks.forced_status ); + if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_cipher_hooks.forced_status ); return( mbedtls_transparent_test_driver_cipher_set_iv( operation, iv, iv_length ) ); } -psa_status_t test_transparent_cipher_update( +psa_status_t mbedtls_test_transparent_cipher_update( mbedtls_transparent_test_driver_cipher_operation_t *operation, const uint8_t *input, size_t input_length, @@ -277,52 +278,52 @@ psa_status_t test_transparent_cipher_update( size_t output_size, size_t *output_length) { - test_driver_cipher_hooks.hits++; + mbedtls_test_driver_cipher_hooks.hits++; - if( test_driver_cipher_hooks.forced_output != NULL ) + if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) { - if( output_size < test_driver_cipher_hooks.forced_output_length ) + if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) return PSA_ERROR_BUFFER_TOO_SMALL; memcpy( output, - test_driver_cipher_hooks.forced_output, - test_driver_cipher_hooks.forced_output_length ); - *output_length = test_driver_cipher_hooks.forced_output_length; + mbedtls_test_driver_cipher_hooks.forced_output, + mbedtls_test_driver_cipher_hooks.forced_output_length ); + *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; - return( test_driver_cipher_hooks.forced_status ); + return( mbedtls_test_driver_cipher_hooks.forced_status ); } - if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_cipher_hooks.forced_status ); + if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_cipher_hooks.forced_status ); return( mbedtls_transparent_test_driver_cipher_update( operation, input, input_length, output, output_size, output_length ) ); } -psa_status_t test_transparent_cipher_finish( +psa_status_t mbedtls_test_transparent_cipher_finish( mbedtls_transparent_test_driver_cipher_operation_t *operation, uint8_t *output, size_t output_size, size_t *output_length) { - test_driver_cipher_hooks.hits++; + mbedtls_test_driver_cipher_hooks.hits++; - if( test_driver_cipher_hooks.forced_output != NULL ) + if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) { - if( output_size < test_driver_cipher_hooks.forced_output_length ) + if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) return PSA_ERROR_BUFFER_TOO_SMALL; memcpy( output, - test_driver_cipher_hooks.forced_output, - test_driver_cipher_hooks.forced_output_length ); - *output_length = test_driver_cipher_hooks.forced_output_length; + mbedtls_test_driver_cipher_hooks.forced_output, + mbedtls_test_driver_cipher_hooks.forced_output_length ); + *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; - return( test_driver_cipher_hooks.forced_status ); + return( mbedtls_test_driver_cipher_hooks.forced_status ); } - if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_cipher_hooks.forced_status ); + if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_cipher_hooks.forced_status ); return( mbedtls_transparent_test_driver_cipher_finish( operation, output, output_size, output_length ) ); @@ -331,7 +332,7 @@ psa_status_t test_transparent_cipher_finish( /* * opaque versions, to do */ -psa_status_t test_opaque_cipher_encrypt( +psa_status_t mbedtls_test_opaque_cipher_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, @@ -350,7 +351,7 @@ psa_status_t test_opaque_cipher_encrypt( return( PSA_ERROR_NOT_SUPPORTED ); } -psa_status_t test_opaque_cipher_decrypt( +psa_status_t mbedtls_test_opaque_cipher_decrypt( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, @@ -369,7 +370,7 @@ psa_status_t test_opaque_cipher_decrypt( return( PSA_ERROR_NOT_SUPPORTED ); } -psa_status_t test_opaque_cipher_encrypt_setup( +psa_status_t mbedtls_test_opaque_cipher_encrypt_setup( mbedtls_opaque_test_driver_cipher_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, @@ -383,7 +384,7 @@ psa_status_t test_opaque_cipher_encrypt_setup( return( PSA_ERROR_NOT_SUPPORTED ); } -psa_status_t test_opaque_cipher_decrypt_setup( +psa_status_t mbedtls_test_opaque_cipher_decrypt_setup( mbedtls_opaque_test_driver_cipher_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, @@ -397,14 +398,14 @@ psa_status_t test_opaque_cipher_decrypt_setup( return( PSA_ERROR_NOT_SUPPORTED ); } -psa_status_t test_opaque_cipher_abort( +psa_status_t mbedtls_test_opaque_cipher_abort( mbedtls_opaque_test_driver_cipher_operation_t *operation ) { (void) operation; return( PSA_ERROR_NOT_SUPPORTED ); } -psa_status_t test_opaque_cipher_set_iv( +psa_status_t mbedtls_test_opaque_cipher_set_iv( mbedtls_opaque_test_driver_cipher_operation_t *operation, const uint8_t *iv, size_t iv_length) @@ -415,7 +416,7 @@ psa_status_t test_opaque_cipher_set_iv( return( PSA_ERROR_NOT_SUPPORTED ); } -psa_status_t test_opaque_cipher_update( +psa_status_t mbedtls_test_opaque_cipher_update( mbedtls_opaque_test_driver_cipher_operation_t *operation, const uint8_t *input, size_t input_length, @@ -432,7 +433,7 @@ psa_status_t test_opaque_cipher_update( return( PSA_ERROR_NOT_SUPPORTED ); } -psa_status_t test_opaque_cipher_finish( +psa_status_t mbedtls_test_opaque_cipher_finish( mbedtls_opaque_test_driver_cipher_operation_t *operation, uint8_t *output, size_t output_size, diff --git a/tests/src/drivers/test_driver_key_management.c b/tests/src/drivers/test_driver_key_management.c index a0626fbf4..19e103331 100644 --- a/tests/src/drivers/test_driver_key_management.c +++ b/tests/src/drivers/test_driver_key_management.c @@ -38,18 +38,18 @@ #include -test_driver_key_management_hooks_t test_driver_key_management_hooks = - TEST_DRIVER_KEY_MANAGEMENT_INIT; +mbedtls_test_driver_key_management_hooks_t + mbedtls_test_driver_key_management_hooks = MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT; -const uint8_t test_driver_aes_key[16] = +const uint8_t mbedtls_test_driver_aes_key[16] = { 0x36, 0x77, 0x39, 0x7A, 0x24, 0x43, 0x26, 0x46, 0x29, 0x4A, 0x40, 0x4E, 0x63, 0x52, 0x66, 0x55 }; -const uint8_t test_driver_ecdsa_key[32] = +const uint8_t mbedtls_test_driver_ecdsa_key[32] = { 0xdc, 0x7d, 0x9d, 0x26, 0xd6, 0x7a, 0x4f, 0x63, 0x2c, 0x34, 0xc2, 0xdc, 0x0b, 0x69, 0x86, 0x18, 0x38, 0x82, 0xc2, 0x06, 0xdf, 0x04, 0xcd, 0xb7, 0xd6, 0x9a, 0xab, 0xe2, 0x8b, 0xe4, 0xf8, 0x1a }; -const uint8_t test_driver_ecdsa_pubkey[65] = +const uint8_t mbedtls_test_driver_ecdsa_pubkey[65] = { 0x04, 0x85, 0xf6, 0x4d, 0x89, 0xf0, 0x0b, 0xe6, 0x6c, 0x88, 0xdd, 0x93, 0x7e, 0xfd, 0x6d, 0x7c, 0x44, @@ -60,22 +60,23 @@ const uint8_t test_driver_ecdsa_pubkey[65] = 0xbc, 0x25, 0x16, 0xc3, 0xd2, 0x70, 0x2d, 0x79, 0x2f, 0x13, 0x1a, 0x92, 0x20, 0x95, 0xfd, 0x6c }; -psa_status_t test_transparent_generate_key( +psa_status_t mbedtls_test_transparent_generate_key( const psa_key_attributes_t *attributes, uint8_t *key, size_t key_size, size_t *key_length ) { - ++test_driver_key_management_hooks.hits; + ++mbedtls_test_driver_key_management_hooks.hits; - if( test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_key_management_hooks.forced_status ); + if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_key_management_hooks.forced_status ); - if( test_driver_key_management_hooks.forced_output != NULL ) + if( mbedtls_test_driver_key_management_hooks.forced_output != NULL ) { - if( test_driver_key_management_hooks.forced_output_length > key_size ) + if( mbedtls_test_driver_key_management_hooks.forced_output_length > + key_size ) return( PSA_ERROR_BUFFER_TOO_SMALL ); - memcpy( key, test_driver_key_management_hooks.forced_output, - test_driver_key_management_hooks.forced_output_length ); - *key_length = test_driver_key_management_hooks.forced_output_length; + memcpy( key, mbedtls_test_driver_key_management_hooks.forced_output, + mbedtls_test_driver_key_management_hooks.forced_output_length ); + *key_length = mbedtls_test_driver_key_management_hooks.forced_output_length; return( PSA_SUCCESS ); } @@ -102,7 +103,7 @@ psa_status_t test_transparent_generate_key( } } -psa_status_t test_opaque_generate_key( +psa_status_t mbedtls_test_opaque_generate_key( const psa_key_attributes_t *attributes, uint8_t *key, size_t key_size, size_t *key_length ) { @@ -113,7 +114,7 @@ psa_status_t test_opaque_generate_key( return( PSA_ERROR_NOT_SUPPORTED ); } -psa_status_t test_transparent_import_key( +psa_status_t mbedtls_test_transparent_import_key( const psa_key_attributes_t *attributes, const uint8_t *data, size_t data_length, @@ -122,10 +123,10 @@ psa_status_t test_transparent_import_key( size_t *key_buffer_length, size_t *bits) { - ++test_driver_key_management_hooks.hits; + ++mbedtls_test_driver_key_management_hooks.hits; - if( test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_key_management_hooks.forced_status ); + if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_key_management_hooks.forced_status ); psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; psa_key_type_t type = psa_get_key_type( attributes ); @@ -168,7 +169,7 @@ psa_status_t test_transparent_import_key( return( status ); } -psa_status_t test_opaque_export_key( +psa_status_t mbedtls_test_opaque_export_key( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, uint8_t *data, size_t data_size, size_t *data_length ) @@ -199,12 +200,12 @@ psa_status_t test_opaque_export_key( PSA_KEY_USAGE_EXPORT ) == 0 ) return( PSA_ERROR_CORRUPTION_DETECTED ); - if( data_size < sizeof( test_driver_ecdsa_key ) ) + if( data_size < sizeof( mbedtls_test_driver_ecdsa_key ) ) return( PSA_ERROR_BUFFER_TOO_SMALL ); - memcpy( data, test_driver_ecdsa_key, - sizeof( test_driver_ecdsa_key ) ); - *data_length = sizeof( test_driver_ecdsa_key ); + memcpy( data, mbedtls_test_driver_ecdsa_key, + sizeof( mbedtls_test_driver_ecdsa_key ) ); + *data_length = sizeof( mbedtls_test_driver_ecdsa_key ); return( PSA_SUCCESS ); case PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT: @@ -220,12 +221,12 @@ psa_status_t test_opaque_export_key( PSA_KEY_USAGE_EXPORT ) == 0 ) return( PSA_ERROR_CORRUPTION_DETECTED ); - if( data_size < sizeof( test_driver_aes_key ) ) + if( data_size < sizeof( mbedtls_test_driver_aes_key ) ) return( PSA_ERROR_BUFFER_TOO_SMALL ); - memcpy( data, test_driver_aes_key, - sizeof( test_driver_aes_key ) ); - *data_length = sizeof( test_driver_aes_key ); + memcpy( data, mbedtls_test_driver_aes_key, + sizeof( mbedtls_test_driver_aes_key ) ); + *data_length = sizeof( mbedtls_test_driver_aes_key ); return( PSA_SUCCESS ); default: @@ -233,23 +234,24 @@ psa_status_t test_opaque_export_key( } } -psa_status_t test_transparent_export_public_key( +psa_status_t mbedtls_test_transparent_export_public_key( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, uint8_t *data, size_t data_size, size_t *data_length ) { - ++test_driver_key_management_hooks.hits; + ++mbedtls_test_driver_key_management_hooks.hits; - if( test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_key_management_hooks.forced_status ); + if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_key_management_hooks.forced_status ); - if( test_driver_key_management_hooks.forced_output != NULL ) + if( mbedtls_test_driver_key_management_hooks.forced_output != NULL ) { - if( test_driver_key_management_hooks.forced_output_length > data_size ) + if( mbedtls_test_driver_key_management_hooks.forced_output_length > + data_size ) return( PSA_ERROR_BUFFER_TOO_SMALL ); - memcpy( data, test_driver_key_management_hooks.forced_output, - test_driver_key_management_hooks.forced_output_length ); - *data_length = test_driver_key_management_hooks.forced_output_length; + memcpy( data, mbedtls_test_driver_key_management_hooks.forced_output, + mbedtls_test_driver_key_management_hooks.forced_output_length ); + *data_length = mbedtls_test_driver_key_management_hooks.forced_output_length; return( PSA_SUCCESS ); } @@ -288,7 +290,7 @@ psa_status_t test_transparent_export_public_key( return( status ); } -psa_status_t test_opaque_export_public_key( +psa_status_t mbedtls_test_opaque_export_public_key( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, uint8_t *data, size_t data_size, size_t *data_length ) @@ -315,12 +317,12 @@ psa_status_t test_opaque_export_public_key( PSA_ALG_ECDSA( PSA_ALG_ANY_HASH ) ) return( PSA_ERROR_CORRUPTION_DETECTED ); - if( data_size < sizeof( test_driver_ecdsa_pubkey ) ) + if( data_size < sizeof( mbedtls_test_driver_ecdsa_pubkey ) ) return( PSA_ERROR_BUFFER_TOO_SMALL ); - memcpy( data, test_driver_ecdsa_pubkey, - sizeof( test_driver_ecdsa_pubkey ) ); - *data_length = sizeof( test_driver_ecdsa_pubkey ); + memcpy( data, mbedtls_test_driver_ecdsa_pubkey, + sizeof( mbedtls_test_driver_ecdsa_pubkey ) ); + *data_length = sizeof( mbedtls_test_driver_ecdsa_pubkey ); return( PSA_SUCCESS ); default: @@ -338,7 +340,7 @@ psa_status_t test_opaque_export_public_key( * (i.e. for an actual driver this would mean 'builtin_key_size' = * sizeof(psa_drv_slot_number_t)). */ -psa_status_t test_opaque_get_builtin_key( +psa_status_t mbedtls_test_opaque_get_builtin_key( psa_drv_slot_number_t slot_number, psa_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) diff --git a/tests/src/drivers/test_driver_signature.c b/tests/src/drivers/test_driver_signature.c index 47c6debc5..be8c1792b 100644 --- a/tests/src/drivers/test_driver_signature.c +++ b/tests/src/drivers/test_driver_signature.c @@ -41,28 +41,32 @@ #include -test_driver_signature_hooks_t test_driver_signature_sign_hooks = TEST_DRIVER_SIGNATURE_INIT; -test_driver_signature_hooks_t test_driver_signature_verify_hooks = TEST_DRIVER_SIGNATURE_INIT; +mbedtls_test_driver_signature_hooks_t + mbedtls_test_driver_signature_sign_hooks = MBEDTLS_TEST_DRIVER_SIGNATURE_INIT; +mbedtls_test_driver_signature_hooks_t + mbedtls_test_driver_signature_verify_hooks = MBEDTLS_TEST_DRIVER_SIGNATURE_INIT; -psa_status_t test_transparent_signature_sign_hash( +psa_status_t mbedtls_test_transparent_signature_sign_hash( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, uint8_t *signature, size_t signature_size, size_t *signature_length ) { - ++test_driver_signature_sign_hooks.hits; + ++mbedtls_test_driver_signature_sign_hooks.hits; - if( test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_signature_sign_hooks.forced_status ); + if( mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_signature_sign_hooks.forced_status ); - if( test_driver_signature_sign_hooks.forced_output != NULL ) + if( mbedtls_test_driver_signature_sign_hooks.forced_output != NULL ) { - if( test_driver_signature_sign_hooks.forced_output_length > signature_size ) + if( mbedtls_test_driver_signature_sign_hooks.forced_output_length > + signature_size ) return( PSA_ERROR_BUFFER_TOO_SMALL ); - memcpy( signature, test_driver_signature_sign_hooks.forced_output, - test_driver_signature_sign_hooks.forced_output_length ); - *signature_length = test_driver_signature_sign_hooks.forced_output_length; + memcpy( signature, + mbedtls_test_driver_signature_sign_hooks.forced_output, + mbedtls_test_driver_signature_sign_hooks.forced_output_length ); + *signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length; return( PSA_SUCCESS ); } @@ -120,7 +124,7 @@ psa_status_t test_transparent_signature_sign_hash( } } -psa_status_t test_opaque_signature_sign_hash( +psa_status_t mbedtls_test_opaque_signature_sign_hash( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, @@ -140,17 +144,17 @@ psa_status_t test_opaque_signature_sign_hash( return( PSA_ERROR_NOT_SUPPORTED ); } -psa_status_t test_transparent_signature_verify_hash( +psa_status_t mbedtls_test_transparent_signature_verify_hash( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, const uint8_t *signature, size_t signature_length ) { - ++test_driver_signature_verify_hooks.hits; + ++mbedtls_test_driver_signature_verify_hooks.hits; - if( test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_signature_verify_hooks.forced_status ); + if( mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_signature_verify_hooks.forced_status ); #if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) || \ defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS) @@ -200,7 +204,7 @@ psa_status_t test_transparent_signature_verify_hash( } } -psa_status_t test_opaque_signature_verify_hash( +psa_status_t mbedtls_test_opaque_signature_verify_hash( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, diff --git a/tests/src/drivers/test_driver_size.c b/tests/src/drivers/test_driver_size.c index 16a86922a..fd10209d2 100644 --- a/tests/src/drivers/test_driver_size.c +++ b/tests/src/drivers/test_driver_size.c @@ -28,8 +28,8 @@ #include "test/drivers/size.h" -#ifdef TEST_KEY_CONTEXT_SIZE_FUNCTION -size_t test_size_function( +#ifdef MBEDTLS_TEST_KEY_CONTEXT_SIZE_FUNCTION +size_t mbedtls_test_size_function( const psa_key_type_t key_type, const size_t key_bits ) { @@ -37,6 +37,6 @@ size_t test_size_function( (void) key_bits; return 0; } -#endif /*TEST_KEY_CONTEXT_SIZE_FUNCTION */ +#endif /*MBEDTLS_TEST_KEY_CONTEXT_SIZE_FUNCTION */ #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function index 5bd5ba8d3..3c48b06ac 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function @@ -1,5 +1,5 @@ /* BEGIN_HEADER */ -#include "test/drivers/test_driver.h" +#include "test/drivers/mbedtls_test_driver.h" /* END_HEADER */ /* BEGIN_DEPENDENCIES @@ -23,7 +23,8 @@ void ecdsa_sign( int force_status_arg, uint8_t signature[64]; size_t signature_length = 0xdeadbeef; psa_status_t actual_status; - test_driver_signature_sign_hooks = test_driver_signature_hooks_init(); + mbedtls_test_driver_signature_sign_hooks = + mbedtls_test_driver_signature_hooks_init(); PSA_ASSERT( psa_crypto_init( ) ); psa_set_key_type( &attributes, @@ -34,11 +35,13 @@ void ecdsa_sign( int force_status_arg, key_input->x, key_input->len, &key ); - test_driver_signature_sign_hooks.forced_status = force_status; + mbedtls_test_driver_signature_sign_hooks.forced_status = force_status; if( fake_output == 1 ) { - test_driver_signature_sign_hooks.forced_output = expected_output->x; - test_driver_signature_sign_hooks.forced_output_length = expected_output->len; + mbedtls_test_driver_signature_sign_hooks.forced_output = + expected_output->x; + mbedtls_test_driver_signature_sign_hooks.forced_output_length = + expected_output->len; } actual_status = psa_sign_hash( key, alg, @@ -51,13 +54,14 @@ void ecdsa_sign( int force_status_arg, ASSERT_COMPARE( signature, signature_length, expected_output->x, expected_output->len ); } - TEST_EQUAL( test_driver_signature_sign_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_signature_sign_hooks.hits, 1 ); exit: psa_reset_key_attributes( &attributes ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_signature_sign_hooks = test_driver_signature_hooks_init(); + mbedtls_test_driver_signature_sign_hooks = + mbedtls_test_driver_signature_hooks_init(); } /* END_CASE */ @@ -75,7 +79,8 @@ void ecdsa_verify( int force_status_arg, psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_algorithm_t alg = PSA_ALG_DETERMINISTIC_ECDSA( PSA_ALG_SHA_256 ); psa_status_t actual_status; - test_driver_signature_verify_hooks = test_driver_signature_hooks_init(); + mbedtls_test_driver_signature_verify_hooks = + mbedtls_test_driver_signature_hooks_init(); PSA_ASSERT( psa_crypto_init( ) ); if( register_public_key ) @@ -99,19 +104,20 @@ void ecdsa_verify( int force_status_arg, &key ); } - test_driver_signature_verify_hooks.forced_status = force_status; + mbedtls_test_driver_signature_verify_hooks.forced_status = force_status; actual_status = psa_verify_hash( key, alg, data_input->x, data_input->len, signature_input->x, signature_input->len ); TEST_EQUAL( actual_status, expected_status ); - TEST_EQUAL( test_driver_signature_verify_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_signature_verify_hooks.hits, 1 ); exit: psa_reset_key_attributes( &attributes ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_signature_verify_hooks = test_driver_signature_hooks_init(); + mbedtls_test_driver_signature_verify_hooks = + mbedtls_test_driver_signature_hooks_init(); } /* END_CASE */ @@ -130,7 +136,8 @@ void generate_key( int force_status_arg, psa_status_t actual_status; uint8_t actual_output[PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(256)] = {0}; size_t actual_output_length; - test_driver_key_management_hooks = test_driver_key_management_hooks_init(); + mbedtls_test_driver_key_management_hooks = + mbedtls_test_driver_key_management_hooks_init(); psa_set_key_type( &attributes, PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 ) ); @@ -140,18 +147,22 @@ void generate_key( int force_status_arg, if( fake_output->len > 0 ) { - expected_output = test_driver_key_management_hooks.forced_output = fake_output->x; - expected_output_length = test_driver_key_management_hooks.forced_output_length = + expected_output = + mbedtls_test_driver_key_management_hooks.forced_output = + fake_output->x; + + expected_output_length = + mbedtls_test_driver_key_management_hooks.forced_output_length = fake_output->len; } - test_driver_key_management_hooks.hits = 0; - test_driver_key_management_hooks.forced_status = force_status; + mbedtls_test_driver_key_management_hooks.hits = 0; + mbedtls_test_driver_key_management_hooks.forced_status = force_status; PSA_ASSERT( psa_crypto_init( ) ); actual_status = psa_generate_key( &attributes, &key ); - TEST_EQUAL( test_driver_key_management_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_key_management_hooks.hits, 1 ); TEST_EQUAL( actual_status, expected_status ); if( actual_status == PSA_SUCCESS ) @@ -178,7 +189,8 @@ exit: psa_reset_key_attributes( &attributes ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_key_management_hooks = test_driver_key_management_hooks_init(); + mbedtls_test_driver_key_management_hooks = + mbedtls_test_driver_key_management_hooks_init(); } /* END_CASE */ @@ -194,25 +206,27 @@ void validate_key( int force_status_arg, mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_status_t actual_status; - test_driver_key_management_hooks = test_driver_key_management_hooks_init(); + mbedtls_test_driver_key_management_hooks = + mbedtls_test_driver_key_management_hooks_init(); psa_set_key_type( &attributes, key_type ); psa_set_key_bits( &attributes, 0 ); psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT ); - test_driver_key_management_hooks.forced_status = force_status; + mbedtls_test_driver_key_management_hooks.forced_status = force_status; PSA_ASSERT( psa_crypto_init( ) ); actual_status = psa_import_key( &attributes, key_input->x, key_input->len, &key ); - TEST_EQUAL( test_driver_key_management_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_key_management_hooks.hits, 1 ); TEST_EQUAL( actual_status, expected_status ); exit: psa_reset_key_attributes( &attributes ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_key_management_hooks = test_driver_key_management_hooks_init(); + mbedtls_test_driver_key_management_hooks = + mbedtls_test_driver_key_management_hooks_init(); } /* END_CASE */ @@ -236,7 +250,8 @@ void export_key( int force_status_arg, psa_status_t actual_status; uint8_t actual_output[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(256)] = {0}; size_t actual_output_length; - test_driver_key_management_hooks = test_driver_key_management_hooks_init(); + mbedtls_test_driver_key_management_hooks = + mbedtls_test_driver_key_management_hooks_init(); psa_set_key_type( &attributes, input_key_type ); psa_set_key_bits( &attributes, 256 ); @@ -247,8 +262,12 @@ void export_key( int force_status_arg, if( fake_output->len > 0 ) { - expected_output_ptr = test_driver_key_management_hooks.forced_output = fake_output->x; - expected_output_length = test_driver_key_management_hooks.forced_output_length = + expected_output_ptr = + mbedtls_test_driver_key_management_hooks.forced_output = + fake_output->x; + + expected_output_length = + mbedtls_test_driver_key_management_hooks.forced_output_length = fake_output->len; } else @@ -257,8 +276,8 @@ void export_key( int force_status_arg, expected_output_length = expected_output->len; } - test_driver_key_management_hooks.hits = 0; - test_driver_key_management_hooks.forced_status = force_status; + mbedtls_test_driver_key_management_hooks.hits = 0; + mbedtls_test_driver_key_management_hooks.forced_status = force_status; if( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( output_key_type ) ) actual_status = psa_export_public_key( handle, actual_output, sizeof(actual_output), &actual_output_length ); @@ -268,7 +287,7 @@ void export_key( int force_status_arg, if( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( output_key_type ) && !PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( input_key_type ) ) - TEST_EQUAL( test_driver_key_management_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_key_management_hooks.hits, 1 ); if( actual_status == PSA_SUCCESS ) { @@ -279,7 +298,8 @@ exit: psa_reset_key_attributes( &attributes ); psa_destroy_key( handle ); PSA_DONE( ); - test_driver_key_management_hooks = test_driver_key_management_hooks_init(); + mbedtls_test_driver_key_management_hooks = + mbedtls_test_driver_key_management_hooks_init(); } /* END_CASE */ @@ -303,8 +323,8 @@ void cipher_encrypt( int alg_arg, int key_type_arg, size_t total_output_length = 0; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); - test_driver_cipher_hooks.forced_status = force_status; + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks.forced_status = force_status; PSA_ASSERT( psa_crypto_init( ) ); @@ -316,12 +336,12 @@ void cipher_encrypt( int alg_arg, int key_type_arg, &key ) ); PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); + mbedtls_test_driver_cipher_hooks.hits = 0; output_buffer_size = ( (size_t) input->len + PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) ); @@ -329,21 +349,21 @@ void cipher_encrypt( int alg_arg, int key_type_arg, if( mock_output_arg ) { - test_driver_cipher_hooks.forced_output = expected_output->x; - test_driver_cipher_hooks.forced_output_length = expected_output->len; + mbedtls_test_driver_cipher_hooks.forced_output = expected_output->x; + mbedtls_test_driver_cipher_hooks.forced_output_length = expected_output->len; } PSA_ASSERT( psa_cipher_update( &operation, input->x, input->len, output, output_buffer_size, &function_output_length ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); + mbedtls_test_driver_cipher_hooks.hits = 0; if( mock_output_arg ) { - test_driver_cipher_hooks.forced_output = NULL; - test_driver_cipher_hooks.forced_output_length = 0; + mbedtls_test_driver_cipher_hooks.forced_output = NULL; + mbedtls_test_driver_cipher_hooks.forced_output_length = 0; } total_output_length += function_output_length; @@ -352,8 +372,8 @@ void cipher_encrypt( int alg_arg, int key_type_arg, output_buffer_size - total_output_length, &function_output_length ); /* Finish will have called abort as well, so expecting two hits here */ - TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 2 : 0 ) ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 2 : 0 ) ); + mbedtls_test_driver_cipher_hooks.hits = 0; total_output_length += function_output_length; @@ -362,7 +382,7 @@ void cipher_encrypt( int alg_arg, int key_type_arg, { PSA_ASSERT( psa_cipher_abort( &operation ) ); // driver function should've been called as part of the finish() core routine - TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 ); ASSERT_COMPARE( expected_output->x, expected_output->len, output, total_output_length ); } @@ -372,7 +392,7 @@ exit: mbedtls_free( output ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); } /* END_CASE */ @@ -396,7 +416,7 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg, size_t total_output_length = 0; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); PSA_ASSERT( psa_crypto_init( ) ); @@ -408,12 +428,12 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg, &key ) ); PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; output_buffer_size = ( (size_t) input->len + PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) ); @@ -423,8 +443,8 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg, PSA_ASSERT( psa_cipher_update( &operation, input->x, first_part_size, output, output_buffer_size, &function_output_length ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; TEST_ASSERT( function_output_length == output1_length ); total_output_length += function_output_length; @@ -434,8 +454,8 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg, output + total_output_length, output_buffer_size - total_output_length, &function_output_length ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; TEST_ASSERT( function_output_length == output2_length ); total_output_length += function_output_length; PSA_ASSERT( psa_cipher_finish( &operation, @@ -443,11 +463,11 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg, output_buffer_size - total_output_length, &function_output_length ) ); /* Finish will have called abort as well, so expecting two hits here */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); - test_driver_cipher_hooks.hits = 0 ; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 ); + mbedtls_test_driver_cipher_hooks.hits = 0 ; total_output_length += function_output_length; PSA_ASSERT( psa_cipher_abort( &operation ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 ); ASSERT_COMPARE( expected_output->x, expected_output->len, output, total_output_length ); @@ -457,7 +477,7 @@ exit: mbedtls_free( output ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); } /* END_CASE */ @@ -481,7 +501,7 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg, size_t total_output_length = 0; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); PSA_ASSERT( psa_crypto_init( ) ); @@ -493,12 +513,12 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg, &key ) ); PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; output_buffer_size = ( (size_t) input->len + PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) ); @@ -509,8 +529,8 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg, input->x, first_part_size, output, output_buffer_size, &function_output_length ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; TEST_ASSERT( function_output_length == output1_length ); total_output_length += function_output_length; @@ -520,8 +540,8 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg, output + total_output_length, output_buffer_size - total_output_length, &function_output_length ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; TEST_ASSERT( function_output_length == output2_length ); total_output_length += function_output_length; @@ -530,11 +550,11 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg, output_buffer_size - total_output_length, &function_output_length ) ); /* Finish will have called abort as well, so expecting two hits here */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 ); + mbedtls_test_driver_cipher_hooks.hits = 0; total_output_length += function_output_length; PSA_ASSERT( psa_cipher_abort( &operation ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 ); ASSERT_COMPARE( expected_output->x, expected_output->len, output, total_output_length ); @@ -544,7 +564,7 @@ exit: mbedtls_free( output ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); } /* END_CASE */ @@ -568,8 +588,8 @@ void cipher_decrypt( int alg_arg, int key_type_arg, size_t total_output_length = 0; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); - test_driver_cipher_hooks.forced_status = force_status; + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks.forced_status = force_status; PSA_ASSERT( psa_crypto_init( ) ); @@ -581,12 +601,12 @@ void cipher_decrypt( int alg_arg, int key_type_arg, &key ) ); PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); + mbedtls_test_driver_cipher_hooks.hits = 0; output_buffer_size = ( (size_t) input->len + PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) ); @@ -594,21 +614,21 @@ void cipher_decrypt( int alg_arg, int key_type_arg, if( mock_output_arg ) { - test_driver_cipher_hooks.forced_output = expected_output->x; - test_driver_cipher_hooks.forced_output_length = expected_output->len; + mbedtls_test_driver_cipher_hooks.forced_output = expected_output->x; + mbedtls_test_driver_cipher_hooks.forced_output_length = expected_output->len; } PSA_ASSERT( psa_cipher_update( &operation, input->x, input->len, output, output_buffer_size, &function_output_length ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); + mbedtls_test_driver_cipher_hooks.hits = 0; if( mock_output_arg ) { - test_driver_cipher_hooks.forced_output = NULL; - test_driver_cipher_hooks.forced_output_length = 0; + mbedtls_test_driver_cipher_hooks.forced_output = NULL; + mbedtls_test_driver_cipher_hooks.forced_output_length = 0; } total_output_length += function_output_length; @@ -617,8 +637,8 @@ void cipher_decrypt( int alg_arg, int key_type_arg, output_buffer_size - total_output_length, &function_output_length ); /* Finish will have called abort as well, so expecting two hits here */ - TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 2 : 0 ) ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 2 : 0 ) ); + mbedtls_test_driver_cipher_hooks.hits = 0; total_output_length += function_output_length; TEST_EQUAL( status, expected_status ); @@ -626,7 +646,7 @@ void cipher_decrypt( int alg_arg, int key_type_arg, if( expected_status == PSA_SUCCESS ) { PSA_ASSERT( psa_cipher_abort( &operation ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 ); ASSERT_COMPARE( expected_output->x, expected_output->len, output, total_output_length ); } @@ -636,7 +656,7 @@ exit: mbedtls_free( output ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); } /* END_CASE */ @@ -654,7 +674,7 @@ void cipher_entry_points( int alg_arg, int key_type_arg, size_t function_output_length = 0; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); ASSERT_ALLOC( output, input->len + 16 ); output_buffer_size = input->len + 16; @@ -669,136 +689,136 @@ void cipher_entry_points( int alg_arg, int key_type_arg, &key ) ); /* Test setup call, encrypt */ - test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; + mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; status = psa_cipher_encrypt_setup( &operation, key, alg ); /* When setup fails, it shouldn't call any further entry points */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_set_iv( &operation, iv->x, iv->len ); TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 ); /* Test setup call failure, decrypt */ status = psa_cipher_decrypt_setup( &operation, key, alg ); /* When setup fails, it shouldn't call any further entry points */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_set_iv( &operation, iv->x, iv->len ); TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 ); /* Test IV setting failure */ - test_driver_cipher_hooks.forced_status = PSA_SUCCESS; + mbedtls_test_driver_cipher_hooks.forced_status = PSA_SUCCESS; status = psa_cipher_encrypt_setup( &operation, key, alg ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; - test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; + mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; status = psa_cipher_set_iv( &operation, iv->x, iv->len ); /* When setting the IV fails, it should call abort too */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); /* Failure should prevent further operations from executing on the driver */ - test_driver_cipher_hooks.hits = 0; + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_update( &operation, input->x, input->len, output, output_buffer_size, &function_output_length ); TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 ); psa_cipher_abort( &operation ); /* Test IV generation failure */ - test_driver_cipher_hooks.forced_status = PSA_SUCCESS; + mbedtls_test_driver_cipher_hooks.forced_status = PSA_SUCCESS; status = psa_cipher_encrypt_setup( &operation, key, alg ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; - test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; + mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; status = psa_cipher_generate_iv( &operation, output, 16, &function_output_length ); /* When generating the IV fails, it should call abort too */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); /* Failure should prevent further operations from executing on the driver */ - test_driver_cipher_hooks.hits = 0; + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_update( &operation, input->x, input->len, output, output_buffer_size, &function_output_length ); TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 ); psa_cipher_abort( &operation ); /* Test update failure */ - test_driver_cipher_hooks.forced_status = PSA_SUCCESS; + mbedtls_test_driver_cipher_hooks.forced_status = PSA_SUCCESS; status = psa_cipher_encrypt_setup( &operation, key, alg ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_set_iv( &operation, iv->x, iv->len ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; - test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; + mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; status = psa_cipher_update( &operation, input->x, input->len, output, output_buffer_size, &function_output_length ); /* When the update call fails, it should call abort too */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); /* Failure should prevent further operations from executing on the driver */ - test_driver_cipher_hooks.hits = 0; + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_update( &operation, input->x, input->len, output, output_buffer_size, &function_output_length ); TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 ); psa_cipher_abort( &operation ); /* Test finish failure */ - test_driver_cipher_hooks.forced_status = PSA_SUCCESS; + mbedtls_test_driver_cipher_hooks.forced_status = PSA_SUCCESS; status = psa_cipher_encrypt_setup( &operation, key, alg ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_set_iv( &operation, iv->x, iv->len ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_update( &operation, input->x, input->len, output, output_buffer_size, &function_output_length ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; - test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; + mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; status = psa_cipher_finish( &operation, output + function_output_length, output_buffer_size - function_output_length, &function_output_length ); /* When the finish call fails, it should call abort too */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); /* Failure should prevent further operations from executing on the driver */ - test_driver_cipher_hooks.hits = 0; + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_update( &operation, input->x, input->len, output, output_buffer_size, &function_output_length ); TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 ); psa_cipher_abort( &operation ); exit: @@ -806,7 +826,7 @@ exit: mbedtls_free( output ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); } /* END_CASE */ @@ -829,7 +849,7 @@ void aead_encrypt( int key_type_arg, data_t *key_data, size_t output_length = 0; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_status_t status = PSA_ERROR_GENERIC_ERROR; - test_driver_aead_hooks = test_driver_aead_hooks_init(); + mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init(); PSA_ASSERT( psa_crypto_init( ) ); @@ -852,15 +872,15 @@ void aead_encrypt( int key_type_arg, data_t *key_data, PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE( input_data->len ) ); ASSERT_ALLOC( output_data, output_size ); - test_driver_aead_hooks.forced_status = forced_status; + mbedtls_test_driver_aead_hooks.forced_status = forced_status; status = psa_aead_encrypt( key, alg, nonce->x, nonce->len, additional_data->x, additional_data->len, input_data->x, input_data->len, output_data, output_size, &output_length ); - TEST_EQUAL( test_driver_aead_hooks.hits, 1 ); - TEST_EQUAL( test_driver_aead_hooks.driver_status, forced_status ); + TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_aead_hooks.driver_status, forced_status ); TEST_EQUAL( status, ( forced_status == PSA_ERROR_NOT_SUPPORTED ) ? PSA_SUCCESS : forced_status ); @@ -875,7 +895,7 @@ exit: psa_destroy_key( key ); mbedtls_free( output_data ); PSA_DONE( ); - test_driver_aead_hooks = test_driver_aead_hooks_init(); + mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init(); } /* END_CASE */ @@ -898,7 +918,7 @@ void aead_decrypt( int key_type_arg, data_t *key_data, size_t output_length = 0; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_status_t status = PSA_ERROR_GENERIC_ERROR; - test_driver_aead_hooks = test_driver_aead_hooks_init(); + mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init(); PSA_ASSERT( psa_crypto_init( ) ); @@ -915,7 +935,7 @@ void aead_decrypt( int key_type_arg, data_t *key_data, alg ); ASSERT_ALLOC( output_data, output_size ); - test_driver_aead_hooks.forced_status = forced_status; + mbedtls_test_driver_aead_hooks.forced_status = forced_status; status = psa_aead_decrypt( key, alg, nonce->x, nonce->len, additional_data->x, @@ -923,8 +943,8 @@ void aead_decrypt( int key_type_arg, data_t *key_data, input_data->x, input_data->len, output_data, output_size, &output_length ); - TEST_EQUAL( test_driver_aead_hooks.hits, 1 ); - TEST_EQUAL( test_driver_aead_hooks.driver_status, forced_status ); + TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_aead_hooks.driver_status, forced_status ); TEST_EQUAL( status, ( forced_status == PSA_ERROR_NOT_SUPPORTED ) ? PSA_SUCCESS : forced_status ); @@ -939,7 +959,7 @@ exit: psa_destroy_key( key ); mbedtls_free( output_data ); PSA_DONE( ); - test_driver_aead_hooks = test_driver_aead_hooks_init(); + mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init(); } /* END_CASE */ @@ -1059,8 +1079,8 @@ void hash_compute( int alg_arg, unsigned char *output = NULL; size_t output_length; - test_driver_hash_hooks = test_driver_hash_hooks_init(); - test_driver_hash_hooks.forced_status = forced_status; + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); + mbedtls_test_driver_hash_hooks.forced_status = forced_status; PSA_ASSERT( psa_crypto_init( ) ); ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); @@ -1068,8 +1088,8 @@ void hash_compute( int alg_arg, TEST_EQUAL( psa_hash_compute( alg, input->x, input->len, output, PSA_HASH_LENGTH( alg ), &output_length ), expected_status ); - TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); if( expected_status == PSA_SUCCESS ) { @@ -1079,7 +1099,7 @@ void hash_compute( int alg_arg, exit: mbedtls_free( output ); PSA_DONE( ); - test_driver_hash_hooks = test_driver_hash_hooks_init(); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); } /* END_CASE */ @@ -1096,7 +1116,7 @@ void hash_multipart( int alg_arg, psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT; size_t output_length; - test_driver_hash_hooks = test_driver_hash_hooks_init(); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); PSA_ASSERT( psa_crypto_init( ) ); @@ -1104,24 +1124,24 @@ void hash_multipart( int alg_arg, /* * Case 1: Force the driver return status for setup. */ - test_driver_hash_hooks.forced_status = forced_status; + mbedtls_test_driver_hash_hooks.forced_status = forced_status; TEST_EQUAL( psa_hash_setup( &operation, alg ), expected_status ); - TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); if( expected_status == PSA_SUCCESS ) { PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) ); - TEST_EQUAL( test_driver_hash_hooks.hits, + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 2 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); PSA_ASSERT( psa_hash_finish( &operation, output, PSA_HASH_LENGTH( alg ), &output_length ) ); - TEST_EQUAL( test_driver_hash_hooks.hits, + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 4 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); ASSERT_COMPARE( output, output_length, hash->x, hash->len ); } @@ -1129,25 +1149,25 @@ void hash_multipart( int alg_arg, /* * Case 2: Force the driver return status for update. */ - test_driver_hash_hooks = test_driver_hash_hooks_init(); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); PSA_ASSERT( psa_hash_setup( &operation, alg ) ); - TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); - test_driver_hash_hooks.forced_status = forced_status; + mbedtls_test_driver_hash_hooks.forced_status = forced_status; TEST_EQUAL( psa_hash_update( &operation, input->x, input->len ), forced_status ); - TEST_EQUAL( test_driver_hash_hooks.hits, + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, forced_status != PSA_SUCCESS ? 3 : 2 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); if( forced_status == PSA_SUCCESS ) { PSA_ASSERT( psa_hash_finish( &operation, output, PSA_HASH_LENGTH( alg ), &output_length ) ); - TEST_EQUAL( test_driver_hash_hooks.hits, 4 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 4 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); ASSERT_COMPARE( output, output_length, hash->x, hash->len ); } @@ -1155,21 +1175,21 @@ void hash_multipart( int alg_arg, /* * Case 3: Force the driver return status for finish. */ - test_driver_hash_hooks = test_driver_hash_hooks_init(); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); PSA_ASSERT( psa_hash_setup( &operation, alg ) ); - TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) ); - TEST_EQUAL( test_driver_hash_hooks.hits, 2 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 2 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); - test_driver_hash_hooks.forced_status = forced_status; + mbedtls_test_driver_hash_hooks.forced_status = forced_status; TEST_EQUAL( psa_hash_finish( &operation, output, PSA_HASH_LENGTH( alg ), &output_length ), forced_status ); - TEST_EQUAL( test_driver_hash_hooks.hits, 4 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 4 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); if( forced_status == PSA_SUCCESS ) { @@ -1180,7 +1200,7 @@ exit: psa_hash_abort( &operation ); mbedtls_free( output ); PSA_DONE( ); - test_driver_hash_hooks = test_driver_hash_hooks_init(); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); } /* END_CASE */ @@ -1196,7 +1216,7 @@ void hash_clone( int alg_arg, psa_hash_operation_t target_operation = PSA_HASH_OPERATION_INIT; size_t output_length; - test_driver_hash_hooks = test_driver_hash_hooks_init(); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); PSA_ASSERT( psa_crypto_init( ) ); @@ -1206,32 +1226,32 @@ void hash_clone( int alg_arg, */ TEST_EQUAL( psa_hash_clone( &source_operation, &target_operation ), PSA_ERROR_BAD_STATE ); - TEST_EQUAL( test_driver_hash_hooks.hits, 0 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 0 ); PSA_ASSERT( psa_hash_setup( &source_operation, alg ) ); - TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); - test_driver_hash_hooks.forced_status = forced_status; + mbedtls_test_driver_hash_hooks.forced_status = forced_status; TEST_EQUAL( psa_hash_clone( &source_operation, &target_operation ), forced_status ); - TEST_EQUAL( test_driver_hash_hooks.hits, + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, forced_status == PSA_SUCCESS ? 2 : 3 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); if( forced_status == PSA_SUCCESS ) { - test_driver_hash_hooks = test_driver_hash_hooks_init(); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); PSA_ASSERT( psa_hash_update( &target_operation, input->x, input->len ) ); - TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); PSA_ASSERT( psa_hash_finish( &target_operation, output, PSA_HASH_LENGTH( alg ), &output_length ) ); - TEST_EQUAL( test_driver_hash_hooks.hits, 3 ); - TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 3 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); ASSERT_COMPARE( output, output_length, hash->x, hash->len ); } @@ -1241,6 +1261,6 @@ exit: psa_hash_abort( &target_operation ); mbedtls_free( output ); PSA_DONE( ); - test_driver_hash_hooks = test_driver_hash_hooks_init(); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); } /* END_CASE */ diff --git a/visualc/VS2010/mbedTLS.vcxproj b/visualc/VS2010/mbedTLS.vcxproj index dd36da7ec..8cc1dbf44 100644 --- a/visualc/VS2010/mbedTLS.vcxproj +++ b/visualc/VS2010/mbedTLS.vcxproj @@ -234,9 +234,9 @@ + - @@ -375,6 +375,8 @@ + + From 4607c829d00de9b1135b3758b09b2c467cd18ac3 Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Wed, 14 Apr 2021 10:55:34 +0200 Subject: [PATCH 05/12] tests: psa: Simplify key buffer size calculation Move the key buffer size calculation code under tests to avoid check-names.sh to complain about "likely macros with typos". This removes the calculation of key buffer sizes for the test driver from the wrapper based on static size data. But the code is still there in test code to be used when we go back to work on the generation of the driver wrapper. Signed-off-by: Ronald Cron --- library/psa_crypto_driver_wrappers.c | 32 +------------ tests/include/test/drivers/size.h | 59 ----------------------- tests/src/drivers/test_driver_size.c | 71 +++++++++++++++++++++++++--- 3 files changed, 67 insertions(+), 95 deletions(-) diff --git a/library/psa_crypto_driver_wrappers.c b/library/psa_crypto_driver_wrappers.c index d1ec001e6..d6e9e148f 100644 --- a/library/psa_crypto_driver_wrappers.c +++ b/library/psa_crypto_driver_wrappers.c @@ -268,37 +268,9 @@ psa_status_t psa_driver_wrapper_get_key_buffer_size( return( PSA_SUCCESS ); } #endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ -#ifdef MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION *key_buffer_size = mbedtls_test_size_function( key_type, key_bits ); - return( PSA_SUCCESS ); -#else /* MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ - if( PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) ) - { - int public_key_overhead = - ( ( MBEDTLS_TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY == 1 ) - ? PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) : 0 ); - *key_buffer_size = MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + - MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE + - public_key_overhead; - } - else if( PSA_KEY_TYPE_IS_PUBLIC_KEY( key_type ) ) - { - *key_buffer_size = MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + - MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE; - } - else if ( !PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) && - !PSA_KEY_TYPE_IS_PUBLIC_KEY ( key_type ) ) - { - *key_buffer_size = MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + - ( MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR * - ( ( key_bits + 7 ) / 8 ) ); - } - else - { - return( PSA_ERROR_NOT_SUPPORTED ); - } - return( PSA_SUCCESS ); -#endif /* MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ + return( ( *key_buffer_size != 0 ) ? + PSA_SUCCESS : PSA_ERROR_NOT_SUPPORTED ); #endif /* PSA_CRYPTO_DRIVER_TEST */ default: diff --git a/tests/include/test/drivers/size.h b/tests/include/test/drivers/size.h index 577e17b8d..b2665bdda 100644 --- a/tests/include/test/drivers/size.h +++ b/tests/include/test/drivers/size.h @@ -29,68 +29,9 @@ #if defined(PSA_CRYPTO_DRIVER_TEST) #include -typedef struct { - unsigned int context; -} mbedtls_test_driver_key_context_t; - -/** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE - * - * This macro returns the base size for the key context. It is the size of the - * driver specific information stored in each key context. - */ -#define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE \ - sizeof( mbedtls_test_driver_key_context_t ) - -/** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE - * - * Number of bytes included in every key context for a key pair. - * - * This pair size is for an ECC 256-bit private/public key pair. - * Based on this value, the size of the private key can be derived by - * subtracting the public key size below from this one. - */ - -#define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE 65 - -/** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE - * - * Number of bytes included in every key context for a public key. - * - * For ECC public keys, it needs 257 bits so 33 bytes. - */ -#define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE 33 - -/** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR - * - * Every key context for a symmetric key includes this many times the key size. - */ -#define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR 0 - -/** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY - * - * If this is true for a key pair, the key context includes space for the public key. - * If this is false, no additional space is added for the public key. - * - * For this instance, store the public key with the private one. - */ -#define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY 1 - -/** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION - * - * If MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION is defined, the test driver - * provides a size_function entry point, otherwise, it does not. - * - * Some opaque drivers have the need to support a custom size for the storage - * of key and context information. The size_function provides the ability to - * provide that customization. - */ -//#define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION - -#ifdef MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION size_t mbedtls_test_size_function( const psa_key_type_t key_type, const size_t key_bits ); -#endif /* MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_TEST_DRIVERS_SIZE_H */ diff --git a/tests/src/drivers/test_driver_size.c b/tests/src/drivers/test_driver_size.c index fd10209d2..d8bcaee38 100644 --- a/tests/src/drivers/test_driver_size.c +++ b/tests/src/drivers/test_driver_size.c @@ -27,16 +27,75 @@ #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST) #include "test/drivers/size.h" +#include "psa/crypto.h" + +typedef struct { + unsigned int context; +} test_driver_key_context_t; + +/* + * This macro returns the base size for the key context. It is the size of the + * driver specific information stored in each key context. + */ +#define TEST_DRIVER_KEY_CONTEXT_BASE_SIZE sizeof( test_driver_key_context_t ) + +/* + * Number of bytes included in every key context for a key pair. + * + * This pair size is for an ECC 256-bit private/public key pair. + * Based on this value, the size of the private key can be derived by + * subtracting the public key size below from this one. + */ +#define TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE 65 + +/* + * Number of bytes included in every key context for a public key. + * + * For ECC public keys, it needs 257 bits so 33 bytes. + */ +#define TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE 33 + +/* + * Every key context for a symmetric key includes this many times the key size. + */ +#define TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR 0 + +/* + * If this is true for a key pair, the key context includes space for the public key. + * If this is false, no additional space is added for the public key. + * + * For this instance, store the public key with the private one. + */ +#define TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY 1 -#ifdef MBEDTLS_TEST_KEY_CONTEXT_SIZE_FUNCTION size_t mbedtls_test_size_function( const psa_key_type_t key_type, const size_t key_bits ) { - (void) key_type; - (void) key_bits; - return 0; -} -#endif /*MBEDTLS_TEST_KEY_CONTEXT_SIZE_FUNCTION */ + size_t key_buffer_size = 0; + if( PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) ) + { + int public_key_overhead = + ( ( TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY == 1 ) + ? PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) : 0 ); + key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + + TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE + + public_key_overhead; + } + else if( PSA_KEY_TYPE_IS_PUBLIC_KEY( key_type ) ) + { + key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + + TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE; + } + else if ( !PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) && + !PSA_KEY_TYPE_IS_PUBLIC_KEY ( key_type ) ) + { + key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + + ( TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR * + ( ( key_bits + 7 ) / 8 ) ); + } + + return( key_buffer_size ); +} #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ From 63281332b0084e30b654ba2ce445831ee4fd69a9 Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Fri, 30 Apr 2021 16:56:51 +0200 Subject: [PATCH 06/12] tests: Fix test arguments separator Signed-off-by: Ronald Cron --- tests/suites/test_suite_psa_crypto_driver_wrappers.data | 4 ++-- tests/suites/test_suite_ssl.data | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.data b/tests/suites/test_suite_psa_crypto_driver_wrappers.data index 64e6023cb..20b4af8ff 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.data +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.data @@ -282,7 +282,7 @@ hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e994148 Hash compute: SHA-256, INSUFFICIENT_MEMORY depends_on:MBEDTLS_PSA_BUILTIN_ALG_SHA_256 -hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY::PSA_ERROR_INSUFFICIENT_MEMORY +hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY:PSA_ERROR_INSUFFICIENT_MEMORY Hash multi-part: SHA-256, computed by the driver depends_on:PSA_WANT_ALG_SHA_256 @@ -298,7 +298,7 @@ hash_multipart:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e9941 Hash multi-part: SHA-256, INSUFFICIENT_MEMORY depends_on:MBEDTLS_PSA_BUILTIN_ALG_SHA_256 -hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY::PSA_ERROR_INSUFFICIENT_MEMORY +hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY:PSA_ERROR_INSUFFICIENT_MEMORY Hash clone: SHA-256, clone successful depends_on:PSA_WANT_ALG_SHA_256 diff --git a/tests/suites/test_suite_ssl.data b/tests/suites/test_suite_ssl.data index e59c9055f..44279d9be 100644 --- a/tests/suites/test_suite_ssl.data +++ b/tests/suites/test_suite_ssl.data @@ -9219,7 +9219,7 @@ ssl_tls1_3_derive_secret:MBEDTLS_MD_SHA256:"9b2188e9b2fc6d64d71dc329900e20bb4191 SSL TLS 1.3 Key schedule: Derive-Secret( ., "c hs traffic", hash) # Vector from RFC 8448 -ssl_tls1_3_derive_secret:MBEDTLS_MD_SHA256:"005cb112fd8eb4ccc623bb88a07c64b3ede1605363fc7d0df8c7ce4ff0fb4ae6":tls1_3_label_c_hs_traffic:"f736cb34fe25e701551bee6fd24c1cc7102a7daf9405cb15d97aafe16f757d03"::32:MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED:"2faac08f851d35fea3604fcb4de82dc62c9b164a70974d0462e27f1ab278700f" +ssl_tls1_3_derive_secret:MBEDTLS_MD_SHA256:"005cb112fd8eb4ccc623bb88a07c64b3ede1605363fc7d0df8c7ce4ff0fb4ae6":tls1_3_label_c_hs_traffic:"f736cb34fe25e701551bee6fd24c1cc7102a7daf9405cb15d97aafe16f757d03":32:MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED:"2faac08f851d35fea3604fcb4de82dc62c9b164a70974d0462e27f1ab278700f" SSL TLS 1.3 Key schedule: Derive-Secret( ., "s hs traffic", hash) # Vector from RFC 8448 From ce1d8d2c4ed4e5f11384374b5bd49327a590583e Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Fri, 30 Apr 2021 17:00:34 +0200 Subject: [PATCH 07/12] tests: Revert test_driver.h name change Signed-off-by: Ronald Cron --- library/psa_crypto_driver_wrappers.c | 2 +- .../test/drivers/{mbedtls_test_driver.h => test_driver.h} | 0 tests/src/drivers/platform_builtin_keys.c | 2 +- tests/suites/test_suite_psa_crypto_driver_wrappers.function | 2 +- visualc/VS2010/mbedTLS.vcxproj | 3 +-- 5 files changed, 4 insertions(+), 5 deletions(-) rename tests/include/test/drivers/{mbedtls_test_driver.h => test_driver.h} (100%) diff --git a/library/psa_crypto_driver_wrappers.c b/library/psa_crypto_driver_wrappers.c index d6e9e148f..9bef02cd0 100644 --- a/library/psa_crypto_driver_wrappers.c +++ b/library/psa_crypto_driver_wrappers.c @@ -37,7 +37,7 @@ #ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #endif -#include "test/drivers/mbedtls_test_driver.h" +#include "test/drivers/test_driver.h" #endif /* PSA_CRYPTO_DRIVER_TEST */ /* Repeat above block for each JSON-declared driver during autogeneration */ diff --git a/tests/include/test/drivers/mbedtls_test_driver.h b/tests/include/test/drivers/test_driver.h similarity index 100% rename from tests/include/test/drivers/mbedtls_test_driver.h rename to tests/include/test/drivers/test_driver.h diff --git a/tests/src/drivers/platform_builtin_keys.c b/tests/src/drivers/platform_builtin_keys.c index 57d040a78..759fa7830 100644 --- a/tests/src/drivers/platform_builtin_keys.c +++ b/tests/src/drivers/platform_builtin_keys.c @@ -24,7 +24,7 @@ #include #if defined(PSA_CRYPTO_DRIVER_TEST) -#include +#include #endif typedef struct diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function index 3c48b06ac..ce27a8b0e 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function @@ -1,5 +1,5 @@ /* BEGIN_HEADER */ -#include "test/drivers/mbedtls_test_driver.h" +#include "test/drivers/test_driver.h" /* END_HEADER */ /* BEGIN_DEPENDENCIES diff --git a/visualc/VS2010/mbedTLS.vcxproj b/visualc/VS2010/mbedTLS.vcxproj index 8cc1dbf44..c3e1d026a 100644 --- a/visualc/VS2010/mbedTLS.vcxproj +++ b/visualc/VS2010/mbedTLS.vcxproj @@ -234,9 +234,9 @@ - + @@ -376,7 +376,6 @@ - From eba3c871001bdc74be95f2b9f5fa9f25f853652c Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Mon, 26 Apr 2021 16:11:37 +0200 Subject: [PATCH 08/12] tests: driver wrappers: Fix hash tests dependencies Take into account that the test driver may not support hash operations. Signed-off-by: Ronald Cron --- .../suites/test_suite_psa_crypto_driver_wrappers.data | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.data b/tests/suites/test_suite_psa_crypto_driver_wrappers.data index 20b4af8ff..0e62d18b4 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.data +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.data @@ -269,7 +269,7 @@ PSA opaque driver builtin pubkey export: not a public key builtin_pubkey_export:MBEDTLS_PSA_KEY_ID_BUILTIN_MIN:PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1):256:PSA_ALG_ECDSA(PSA_ALG_ANY_HASH):"0485f64d89f00be66c88dd937efd6d7c445648dcb701150b8a9509295850f41c1931e571fb8f8c78317a20b380e866584bbc2516c3d2702d792f131a922095fd6c":PSA_ERROR_INVALID_ARGUMENT Hash compute: SHA-256, computed by the driver -depends_on:PSA_WANT_ALG_SHA_256 +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS:PSA_SUCCESS Hash compute: SHA-256, fallback @@ -281,11 +281,10 @@ depends_on:!MBEDTLS_PSA_BUILTIN_ALG_SHA_256 hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_ERROR_NOT_SUPPORTED Hash compute: SHA-256, INSUFFICIENT_MEMORY -depends_on:MBEDTLS_PSA_BUILTIN_ALG_SHA_256 hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY:PSA_ERROR_INSUFFICIENT_MEMORY Hash multi-part: SHA-256, computed by the driver -depends_on:PSA_WANT_ALG_SHA_256 +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 hash_multipart:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS:PSA_SUCCESS Hash multi-part: SHA-256, fallback @@ -297,13 +296,12 @@ depends_on:!MBEDTLS_PSA_BUILTIN_ALG_SHA_256 hash_multipart:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_ERROR_NOT_SUPPORTED Hash multi-part: SHA-256, INSUFFICIENT_MEMORY -depends_on:MBEDTLS_PSA_BUILTIN_ALG_SHA_256 hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY:PSA_ERROR_INSUFFICIENT_MEMORY Hash clone: SHA-256, clone successful -depends_on:PSA_WANT_ALG_SHA_256 +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 hash_clone:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS Hash clone: SHA-256, clone failure -depends_on:PSA_WANT_ALG_SHA_256 +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 hash_clone:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED From 6e12b7b50c23e9bdd7eee236997ed3a01535b330 Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Sat, 1 May 2021 14:38:42 +0200 Subject: [PATCH 09/12] tests: driver wrappers: Specialize hash multi-part test on setup only Signed-off-by: Ronald Cron --- ...test_suite_psa_crypto_driver_wrappers.data | 16 ++--- ..._suite_psa_crypto_driver_wrappers.function | 61 ++----------------- 2 files changed, 12 insertions(+), 65 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.data b/tests/suites/test_suite_psa_crypto_driver_wrappers.data index 0e62d18b4..cc892de82 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.data +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.data @@ -283,20 +283,20 @@ hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e994148 Hash compute: SHA-256, INSUFFICIENT_MEMORY hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY:PSA_ERROR_INSUFFICIENT_MEMORY -Hash multi-part: SHA-256, computed by the driver +Hash multi-part setup: SHA-256, computed by the driver depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 -hash_multipart:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS:PSA_SUCCESS +hash_multipart_setup:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS:PSA_SUCCESS -Hash multi-part: SHA-256, fallback +Hash multi-part setup: SHA-256, fallback depends_on:MBEDTLS_PSA_BUILTIN_ALG_SHA_256 -hash_multipart:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_SUCCESS +hash_multipart_setup:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_SUCCESS -Hash multi-part: SHA-256, no fallback +Hash multi-part setup: SHA-256, no fallback depends_on:!MBEDTLS_PSA_BUILTIN_ALG_SHA_256 -hash_multipart:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_ERROR_NOT_SUPPORTED +hash_multipart_setup:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_ERROR_NOT_SUPPORTED -Hash multi-part: SHA-256, INSUFFICIENT_MEMORY -hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY:PSA_ERROR_INSUFFICIENT_MEMORY +Hash multi-part setup: SHA-256, INSUFFICIENT_MEMORY +hash_multipart_setup:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY:PSA_ERROR_INSUFFICIENT_MEMORY Hash clone: SHA-256, clone successful depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function index ce27a8b0e..735fcbbfd 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function @@ -1104,10 +1104,10 @@ exit: /* END_CASE */ /* BEGIN_CASE */ -void hash_multipart( int alg_arg, - data_t *input, data_t *hash, - int forced_status_arg, - int expected_status_arg ) +void hash_multipart_setup( int alg_arg, + data_t *input, data_t *hash, + int forced_status_arg, + int expected_status_arg ) { psa_algorithm_t alg = alg_arg; psa_status_t forced_status = forced_status_arg; @@ -1121,9 +1121,6 @@ void hash_multipart( int alg_arg, PSA_ASSERT( psa_crypto_init( ) ); - /* - * Case 1: Force the driver return status for setup. - */ mbedtls_test_driver_hash_hooks.forced_status = forced_status; TEST_EQUAL( psa_hash_setup( &operation, alg ), expected_status ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); @@ -1146,56 +1143,6 @@ void hash_multipart( int alg_arg, ASSERT_COMPARE( output, output_length, hash->x, hash->len ); } - /* - * Case 2: Force the driver return status for update. - */ - mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); - PSA_ASSERT( psa_hash_setup( &operation, alg ) ); - TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); - TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); - - mbedtls_test_driver_hash_hooks.forced_status = forced_status; - TEST_EQUAL( psa_hash_update( &operation, input->x, input->len ), - forced_status ); - TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, - forced_status != PSA_SUCCESS ? 3 : 2 ); - TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); - - if( forced_status == PSA_SUCCESS ) - { - PSA_ASSERT( psa_hash_finish( &operation, - output, PSA_HASH_LENGTH( alg ), - &output_length ) ); - TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 4 ); - TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); - - ASSERT_COMPARE( output, output_length, hash->x, hash->len ); - } - - /* - * Case 3: Force the driver return status for finish. - */ - mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); - PSA_ASSERT( psa_hash_setup( &operation, alg ) ); - TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); - TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); - - PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) ); - TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 2 ); - TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); - - mbedtls_test_driver_hash_hooks.forced_status = forced_status; - TEST_EQUAL( psa_hash_finish( &operation, - output, PSA_HASH_LENGTH( alg ), - &output_length ), forced_status ); - TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 4 ); - TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); - - if( forced_status == PSA_SUCCESS ) - { - ASSERT_COMPARE( output, output_length, hash->x, hash->len ); - } - exit: psa_hash_abort( &operation ); mbedtls_free( output ); From 1fb49e6ee720bf1b5a56e300a72fd6b11be66865 Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Sat, 1 May 2021 14:52:54 +0200 Subject: [PATCH 10/12] tests: driver wrappers: Add hash update tests Signed-off-by: Ronald Cron --- ...test_suite_psa_crypto_driver_wrappers.data | 8 +++ ..._suite_psa_crypto_driver_wrappers.function | 56 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.data b/tests/suites/test_suite_psa_crypto_driver_wrappers.data index cc892de82..17e7b03c1 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.data +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.data @@ -298,6 +298,14 @@ hash_multipart_setup:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e Hash multi-part setup: SHA-256, INSUFFICIENT_MEMORY hash_multipart_setup:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY:PSA_ERROR_INSUFFICIENT_MEMORY +Hash multi-part update: SHA-256, update successful +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_multipart_update:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS + +Hash multi-part update: SHA-256, update failure +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_multipart_update:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED + Hash clone: SHA-256, clone successful depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 hash_clone:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function index 735fcbbfd..d96078ded 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function @@ -1151,6 +1151,62 @@ exit: } /* END_CASE */ +/* BEGIN_CASE */ +void hash_multipart_update( int alg_arg, + data_t *input, data_t *hash, + int forced_status_arg ) +{ + psa_algorithm_t alg = alg_arg; + psa_status_t forced_status = forced_status_arg; + unsigned char *output = NULL; + psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT; + size_t output_length; + + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); + ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); + + PSA_ASSERT( psa_crypto_init( ) ); + + /* + * Update none active operation, the driver shouldn't be called. + */ + TEST_EQUAL( psa_hash_update( &operation, input->x, input->len ), + PSA_ERROR_BAD_STATE ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 0 ); + + PSA_ASSERT( psa_hash_setup( &operation, alg ) ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + mbedtls_test_driver_hash_hooks.forced_status = forced_status; + TEST_EQUAL( psa_hash_update( &operation, input->x, input->len ), + forced_status ); + /* One or two more calls to the driver interface: update or update + abort */ + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, + forced_status == PSA_SUCCESS ? 2 : 3 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); + + if( forced_status == PSA_SUCCESS ) + { + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); + PSA_ASSERT( psa_hash_finish( &operation, + output, PSA_HASH_LENGTH( alg ), + &output_length ) ); + /* Two calls to the driver interface: update + abort */ + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 2 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + ASSERT_COMPARE( output, output_length, hash->x, hash->len ); + } + +exit: + psa_hash_abort( &operation ); + mbedtls_free( output ); + PSA_DONE( ); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); +} +/* END_CASE */ + /* BEGIN_CASE */ void hash_clone( int alg_arg, data_t *input, data_t *hash, From 3e4d190b4a7dec4738389829b28200bc5fd32dd6 Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Sat, 1 May 2021 15:02:51 +0200 Subject: [PATCH 11/12] tests: driver wrappers: Add hash finish tests Signed-off-by: Ronald Cron --- ...test_suite_psa_crypto_driver_wrappers.data | 8 +++ ..._suite_psa_crypto_driver_wrappers.function | 52 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.data b/tests/suites/test_suite_psa_crypto_driver_wrappers.data index 17e7b03c1..5fbfac66a 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.data +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.data @@ -306,6 +306,14 @@ Hash multi-part update: SHA-256, update failure depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 hash_multipart_update:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED +Hash multi-part finish: SHA-256, finish successful +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_multipart_update:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS + +Hash multi-part finish: SHA-256, finish failure +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_multipart_update:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED + Hash clone: SHA-256, clone successful depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 hash_clone:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function index d96078ded..ec489b481 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function @@ -1207,6 +1207,58 @@ exit: } /* END_CASE */ +/* BEGIN_CASE */ +void hash_multipart_finish( int alg_arg, + data_t *input, data_t *hash, + int forced_status_arg ) +{ + psa_algorithm_t alg = alg_arg; + psa_status_t forced_status = forced_status_arg; + unsigned char *output = NULL; + psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT; + size_t output_length; + + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); + ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); + + PSA_ASSERT( psa_crypto_init( ) ); + + /* + * Finish none active operation, the driver shouldn't be called. + */ + TEST_EQUAL( psa_hash_finish( &operation, output, PSA_HASH_LENGTH( alg ), + &output_length ), + PSA_ERROR_BAD_STATE ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 0 ); + + PSA_ASSERT( psa_hash_setup( &operation, alg ) ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 2 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + mbedtls_test_driver_hash_hooks.forced_status = forced_status; + TEST_EQUAL( psa_hash_finish( &operation, + output, PSA_HASH_LENGTH( alg ), + &output_length ), + forced_status ); + /* Two more calls to the driver interface: finish + abort */ + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 4 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); + + if( forced_status == PSA_SUCCESS ) + ASSERT_COMPARE( output, output_length, hash->x, hash->len ); + +exit: + psa_hash_abort( &operation ); + mbedtls_free( output ); + PSA_DONE( ); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); +} +/* END_CASE */ + /* BEGIN_CASE */ void hash_clone( int alg_arg, data_t *input, data_t *hash, From 1153c3d4f3c5caafb2e3f72cab7c10c8abf54b6a Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Tue, 4 May 2021 16:11:06 +0200 Subject: [PATCH 12/12] tests: driver wrappers: Improve test comments Signed-off-by: Ronald Cron --- tests/suites/test_suite_psa_crypto_driver_wrappers.function | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function index ec489b481..a0b719ef6 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function @@ -1168,7 +1168,7 @@ void hash_multipart_update( int alg_arg, PSA_ASSERT( psa_crypto_init( ) ); /* - * Update none active operation, the driver shouldn't be called. + * Update inactive operation, the driver shouldn't be called. */ TEST_EQUAL( psa_hash_update( &operation, input->x, input->len ), PSA_ERROR_BAD_STATE ); @@ -1224,7 +1224,7 @@ void hash_multipart_finish( int alg_arg, PSA_ASSERT( psa_crypto_init( ) ); /* - * Finish none active operation, the driver shouldn't be called. + * Finish inactive operation, the driver shouldn't be called. */ TEST_EQUAL( psa_hash_finish( &operation, output, PSA_HASH_LENGTH( alg ), &output_length ), @@ -1277,7 +1277,7 @@ void hash_clone( int alg_arg, PSA_ASSERT( psa_crypto_init( ) ); /* - * Clone none active operation, the driver shouldn't be called. + * Clone inactive operation, the driver shouldn't be called. */ TEST_EQUAL( psa_hash_clone( &source_operation, &target_operation ), PSA_ERROR_BAD_STATE );