tests: psa: Refine choice of default hash algorithm for signature
As PSA signatures rely on built-in hash implementations (cannot take an advantage of an accelerator for the time being), chose an available built-in hash for tests exercising a signature key. Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
parent
403c15cb51
commit
4c0ec7651b
@ -52,6 +52,34 @@
|
||||
#undef KNOWN_SUPPORTED_HASH_ALG
|
||||
#endif
|
||||
|
||||
/** \def KNOWN_MBEDTLS_SUPPORTED_HASH_ALG
|
||||
*
|
||||
* A hash algorithm that is known to be supported by Mbed TLS APIs.
|
||||
*
|
||||
* This is used in some smoke tests where the hash algorithm is used as
|
||||
* part of another algorithm like a signature algorithm and the hashing is
|
||||
* completed through an Mbed TLS hash API, not the PSA one.
|
||||
*/
|
||||
#if defined(MBEDTLS_MD2_C)
|
||||
#define KNOWN_MBEDTLS_SUPPORTED_HASH_ALG PSA_ALG_MD2
|
||||
#elif defined(MBEDTLS_MD4_C)
|
||||
#define KNOWN_MBEDTLS_SUPPORTED_HASH_ALG PSA_ALG_MD4
|
||||
#elif defined(MBEDTLS_MD5_C)
|
||||
#define KNOWN_MBEDTLS_SUPPORTED_HASH_ALG PSA_ALG_MD5
|
||||
/* MBEDTLS_RIPEMD160_C omitted. This is necessary for the sake of
|
||||
* exercise_signature_key() because Mbed TLS doesn't support RIPEMD160
|
||||
* in RSA PKCS#1v1.5 signatures. A RIPEMD160-only configuration would be
|
||||
* implausible anyway. */
|
||||
#elif defined(MBEDTLS_SHA1_C)
|
||||
#define KNOWN_MBEDTLS_SUPPORTED_HASH_ALG PSA_ALG_SHA_1
|
||||
#elif defined(MBEDTLS_SHA256_C)
|
||||
#define KNOWN_MBEDTLS_SUPPORTED_HASH_ALG PSA_ALG_SHA_256
|
||||
#elif defined(MBEDTLS_SHA512_C)
|
||||
#define KNOWN_MBEDTLS_SUPPORTED_HASH_ALG PSA_ALG_SHA_512
|
||||
#else
|
||||
#undef KNOWN_MBEDLTS_SUPPORTED_HASH_ALG
|
||||
#endif
|
||||
|
||||
/** \def KNOWN_SUPPORTED_BLOCK_CIPHER
|
||||
*
|
||||
* A block cipher that is known to be supported.
|
||||
|
@ -309,8 +309,8 @@ static int exercise_signature_key( mbedtls_svc_key_id_t key,
|
||||
/* If the policy allows signing with any hash, just pick one. */
|
||||
if( PSA_ALG_IS_SIGN_HASH( alg ) && hash_alg == PSA_ALG_ANY_HASH )
|
||||
{
|
||||
#if defined(KNOWN_SUPPORTED_HASH_ALG)
|
||||
hash_alg = KNOWN_SUPPORTED_HASH_ALG;
|
||||
#if defined(KNOWN_MBEDTLS_SUPPORTED_HASH_ALG)
|
||||
hash_alg = KNOWN_MBEDTLS_SUPPORTED_HASH_ALG;
|
||||
alg ^= PSA_ALG_ANY_HASH ^ hash_alg;
|
||||
#else
|
||||
TEST_ASSERT( ! "No hash algorithm for hash-and-sign testing" );
|
||||
|
Loading…
Reference in New Issue
Block a user