@@ -1107,6 +1107,23 @@ exit:
1107
1107
return( ok );
1108
1108
}
1109
1109
1110
+ /* Assert that a key isn't reported as having a slot number. */
1111
+ #if defined(MBEDTLS_PSA_CRYPTO_SE_C)
1112
+ #define ASSERT_NO_SLOT_NUMBER( attributes ) \
1113
+ do \
1114
+ { \
1115
+ psa_key_slot_number_t ASSERT_NO_SLOT_NUMBER_slot_number; \
1116
+ TEST_EQUAL( psa_get_key_slot_number( \
1117
+ attributes, \
1118
+ &ASSERT_NO_SLOT_NUMBER_slot_number ), \
1119
+ PSA_ERROR_INVALID_ARGUMENT ); \
1120
+ } \
1121
+ while( 0 )
1122
+ #else /* MBEDTLS_PSA_CRYPTO_SE_C */
1123
+ #define ASSERT_NO_SLOT_NUMBER( attributes ) \
1124
+ ( (void) 0 )
1125
+ #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
1126
+
1110
1127
/* An overapproximation of the amount of storage needed for a key of the
1111
1128
* given type and with the given content. The API doesn't make it easy
1112
1129
* to find a good value for the size. The current implementation doesn't
@@ -1208,6 +1225,46 @@ void persistence_attributes( int id1_arg, int lifetime_arg, int id2_arg,
1208
1225
}
1209
1226
/* END_CASE */
1210
1227
1228
+ /* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_SE_C */
1229
+ void slot_number_attribute( )
1230
+ {
1231
+ psa_key_slot_number_t slot_number = 0xdeadbeef;
1232
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
1233
+
1234
+ /* Initially, there is no slot number. */
1235
+ TEST_EQUAL( psa_get_key_slot_number( &attributes, &slot_number ),
1236
+ PSA_ERROR_INVALID_ARGUMENT );
1237
+
1238
+ /* Test setting a slot number. */
1239
+ psa_set_key_slot_number( &attributes, 0 );
1240
+ PSA_ASSERT( psa_get_key_slot_number( &attributes, &slot_number ) );
1241
+ TEST_EQUAL( slot_number, 0 );
1242
+
1243
+ /* Test changing the slot number. */
1244
+ psa_set_key_slot_number( &attributes, 42 );
1245
+ PSA_ASSERT( psa_get_key_slot_number( &attributes, &slot_number ) );
1246
+ TEST_EQUAL( slot_number, 42 );
1247
+
1248
+ /* Test clearing the slot number. */
1249
+ psa_clear_key_slot_number( &attributes );
1250
+ TEST_EQUAL( psa_get_key_slot_number( &attributes, &slot_number ),
1251
+ PSA_ERROR_INVALID_ARGUMENT );
1252
+
1253
+ /* Clearing again should have no effect. */
1254
+ psa_clear_key_slot_number( &attributes );
1255
+ TEST_EQUAL( psa_get_key_slot_number( &attributes, &slot_number ),
1256
+ PSA_ERROR_INVALID_ARGUMENT );
1257
+
1258
+ /* Test that reset clears the slot number. */
1259
+ psa_set_key_slot_number( &attributes, 42 );
1260
+ PSA_ASSERT( psa_get_key_slot_number( &attributes, &slot_number ) );
1261
+ TEST_EQUAL( slot_number, 42 );
1262
+ psa_reset_key_attributes( &attributes );
1263
+ TEST_EQUAL( psa_get_key_slot_number( &attributes, &slot_number ),
1264
+ PSA_ERROR_INVALID_ARGUMENT );
1265
+ }
1266
+ /* END_CASE */
1267
+
1211
1268
/* BEGIN_CASE */
1212
1269
void import_with_policy( int type_arg,
1213
1270
int usage_arg, int alg_arg,
@@ -1240,6 +1297,7 @@ void import_with_policy( int type_arg,
1240
1297
TEST_EQUAL( psa_get_key_type( &got_attributes ), type );
1241
1298
TEST_EQUAL( psa_get_key_usage_flags( &got_attributes ), usage );
1242
1299
TEST_EQUAL( psa_get_key_algorithm( &got_attributes ), alg );
1300
+ ASSERT_NO_SLOT_NUMBER( &got_attributes );
1243
1301
1244
1302
PSA_ASSERT( psa_destroy_key( handle ) );
1245
1303
test_operations_on_invalid_handle( handle );
@@ -1278,6 +1336,7 @@ void import_with_data( data_t *data, int type_arg,
1278
1336
TEST_EQUAL( psa_get_key_type( &got_attributes ), type );
1279
1337
if( attr_bits != 0 )
1280
1338
TEST_EQUAL( attr_bits, psa_get_key_bits( &got_attributes ) );
1339
+ ASSERT_NO_SLOT_NUMBER( &got_attributes );
1281
1340
1282
1341
PSA_ASSERT( psa_destroy_key( handle ) );
1283
1342
test_operations_on_invalid_handle( handle );
@@ -1322,6 +1381,7 @@ void import_large_key( int type_arg, int byte_size_arg,
1322
1381
TEST_EQUAL( psa_get_key_type( &attributes ), type );
1323
1382
TEST_EQUAL( psa_get_key_bits( &attributes ),
1324
1383
PSA_BYTES_TO_BITS( byte_size ) );
1384
+ ASSERT_NO_SLOT_NUMBER( &attributes );
1325
1385
memset( buffer, 0, byte_size + 1 );
1326
1386
PSA_ASSERT( psa_export_key( handle, buffer, byte_size, &n ) );
1327
1387
for( n = 0; n < byte_size; n++ )
@@ -1414,6 +1474,7 @@ void import_export( data_t *data,
1414
1474
PSA_ASSERT( psa_get_key_attributes( handle, &got_attributes ) );
1415
1475
TEST_EQUAL( psa_get_key_type( &got_attributes ), type );
1416
1476
TEST_EQUAL( psa_get_key_bits( &got_attributes ), (size_t) expected_bits );
1477
+ ASSERT_NO_SLOT_NUMBER( &got_attributes );
1417
1478
1418
1479
/* Export the key */
1419
1480
status = psa_export_key( handle,
0 commit comments