1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

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 <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron
2021-04-14 10:55:34 +02:00
parent c4bc12e8f3
commit b0737dab26
3 changed files with 67 additions and 95 deletions

View File

@ -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: