Do key usage policy extension when loading keys

Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com>
This commit is contained in:
gabor-mezei-arm 2021-06-23 16:48:08 +02:00
parent edf2df84ba
commit 43110b6b2c
2 changed files with 14 additions and 6 deletions

View File

@ -392,15 +392,19 @@ static inline psa_key_lifetime_t psa_get_key_lifetime(
return( attributes->MBEDTLS_PRIVATE(core).MBEDTLS_PRIVATE(lifetime) ); return( attributes->MBEDTLS_PRIVATE(core).MBEDTLS_PRIVATE(lifetime) );
} }
static inline void psa_set_key_usage_flags( psa_key_attributes_t *attributes, static inline void psa_extend_key_usage_flags( psa_key_usage_t *usage_flags )
psa_key_usage_t usage_flags )
{ {
if( usage_flags & PSA_KEY_USAGE_SIGN_HASH ) if( *usage_flags & PSA_KEY_USAGE_SIGN_HASH )
usage_flags |= PSA_KEY_USAGE_SIGN_MESSAGE; *usage_flags |= PSA_KEY_USAGE_SIGN_MESSAGE;
if( usage_flags & PSA_KEY_USAGE_VERIFY_HASH ) if( *usage_flags & PSA_KEY_USAGE_VERIFY_HASH )
usage_flags |= PSA_KEY_USAGE_VERIFY_MESSAGE; *usage_flags |= PSA_KEY_USAGE_VERIFY_MESSAGE;
}
static inline void psa_set_key_usage_flags(psa_key_attributes_t *attributes,
psa_key_usage_t usage_flags)
{
psa_extend_key_usage_flags( &usage_flags );
attributes->MBEDTLS_PRIVATE(core).MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(usage) = usage_flags; attributes->MBEDTLS_PRIVATE(core).MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(usage) = usage_flags;
} }

View File

@ -391,6 +391,10 @@ psa_status_t psa_get_and_lock_key_slot( mbedtls_svc_key_id_t key,
if( status == PSA_ERROR_DOES_NOT_EXIST ) if( status == PSA_ERROR_DOES_NOT_EXIST )
status = PSA_ERROR_INVALID_HANDLE; status = PSA_ERROR_INVALID_HANDLE;
} }
else
/* Do the key usage policy extension. */
psa_extend_key_usage_flags( &(*p_slot)->attr.policy.usage );
return( status ); return( status );
#else /* MBEDTLS_PSA_CRYPTO_STORAGE_C || MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ #else /* MBEDTLS_PSA_CRYPTO_STORAGE_C || MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
return( PSA_ERROR_INVALID_HANDLE ); return( PSA_ERROR_INVALID_HANDLE );