Skip to content

Commit 3825e14

Browse files
Fix policy validity check on key creation.
Add a non-regression test.
1 parent 6edfa29 commit 3825e14

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

library/psa_crypto.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,10 +1469,6 @@ static psa_status_t psa_start_key_creation(
14691469
return( status );
14701470
}
14711471

1472-
status = psa_check_key_slot_policy( slot );
1473-
if( status != PSA_SUCCESS )
1474-
return( status );
1475-
14761472
/* Refuse to create overly large keys.
14771473
* Note that this doesn't trigger on import if the attributes don't
14781474
* explicitly specify a size (so psa_get_key_bits returns 0), so
@@ -1487,6 +1483,10 @@ static psa_status_t psa_start_key_creation(
14871483

14881484
slot->attr = attributes->core;
14891485

1486+
status = psa_check_key_slot_policy( slot );
1487+
if( status != PSA_SUCCESS )
1488+
return( status );
1489+
14901490
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
14911491
/* For a key in a secure element, we need to do three things:
14921492
* create the key file in internal storage, create the

tests/suites/test_suite_psa_crypto.data

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ invalid_handle:1
5252
PSA invalid handle (largest plausible handle)
5353
invalid_handle:-1
5454

55+
PSA import: bad usage flag
56+
import_with_policy:PSA_KEY_TYPE_RAW_DATA:0x40000000:0:PSA_ERROR_INVALID_ARGUMENT
57+
5558
PSA import: invalid type (0)
5659
import_with_policy:PSA_KEY_TYPE_NONE:0:0:PSA_ERROR_NOT_SUPPORTED
5760

0 commit comments

Comments
 (0)