| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include "common.h" |
| 22 |
|
| 23 |
#if defined(MBEDTLS_PSA_CRYPTO_C) |
| 24 |
|
| 25 |
#include "psa/crypto.h" |
| 26 |
|
| 27 |
#include "psa_crypto_core.h" |
| 28 |
#include "psa_crypto_driver_wrappers.h" |
| 29 |
#include "psa_crypto_slot_management.h" |
| 30 |
#include "psa_crypto_storage.h" |
| 31 |
#if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 32 |
#include "psa_crypto_se.h" |
| 33 |
#endif |
| 34 |
|
| 35 |
#include <stdlib.h> |
| 36 |
#include <string.h> |
| 37 |
#if defined(MBEDTLS_PLATFORM_C) |
| 38 |
#include "mbedtls/platform.h" |
| 39 |
#else |
| 40 |
#define mbedtls_calloc calloc |
| 41 |
#define mbedtls_free free |
| 42 |
#endif |
| 43 |
|
| 44 |
#define ARRAY_LENGTH( array ) ( sizeof( array ) / sizeof( *( array ) ) ) |
| 45 |
|
| 46 |
typedef struct |
| 47 |
{ |
| 48 |
psa_key_slot_t key_slots[MBEDTLS_PSA_KEY_SLOT_COUNT]; |
| 49 |
unsigned key_slots_initialized : 1; |
| 50 |
} psa_global_data_t; |
| 51 |
|
| 52 |
static psa_global_data_t global_data; |
| 53 |
|
| 54 |
int psa_is_valid_key_id( mbedtls_svc_key_id_t key, int vendor_ok ) |
| 55 |
{ |
| 56 |
psa_key_id_t key_id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( key ); |
| 57 |
|
| 58 |
if( ( PSA_KEY_ID_USER_MIN <= key_id ) && |
| 59 |
( key_id <= PSA_KEY_ID_USER_MAX ) ) |
| 60 |
return( 1 ); |
| 61 |
|
| 62 |
if( vendor_ok && |
| 63 |
( PSA_KEY_ID_VENDOR_MIN <= key_id ) && |
| 64 |
( key_id <= PSA_KEY_ID_VENDOR_MAX ) ) |
| 65 |
return( 1 ); |
| 66 |
|
| 67 |
return( 0 ); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
static psa_status_t psa_get_and_lock_key_slot_in_memory( |
| 102 |
mbedtls_svc_key_id_t key, psa_key_slot_t **p_slot ) |
| 103 |
{ |
| 104 |
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 105 |
psa_key_id_t key_id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( key ); |
| 106 |
size_t slot_idx; |
| 107 |
psa_key_slot_t *slot = NULL; |
| 108 |
|
| 109 |
if( psa_key_id_is_volatile( key_id ) ) |
| 110 |
{ |
| 111 |
slot = &global_data.key_slots[ key_id - PSA_KEY_ID_VOLATILE_MIN ]; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
status = mbedtls_svc_key_id_equal( key, slot->attr.id ) ? |
| 122 |
PSA_SUCCESS : PSA_ERROR_DOES_NOT_EXIST; |
| 123 |
} |
| 124 |
else |
| 125 |
{ |
| 126 |
if ( !psa_is_valid_key_id( key, 1 ) ) |
| 127 |
return( PSA_ERROR_INVALID_HANDLE ); |
| 128 |
|
| 129 |
for( slot_idx = 0; slot_idx < MBEDTLS_PSA_KEY_SLOT_COUNT; slot_idx++ ) |
| 130 |
{ |
| 131 |
slot = &global_data.key_slots[ slot_idx ]; |
| 132 |
if( mbedtls_svc_key_id_equal( key, slot->attr.id ) ) |
| 133 |
break; |
| 134 |
} |
| 135 |
status = ( slot_idx < MBEDTLS_PSA_KEY_SLOT_COUNT ) ? |
| 136 |
PSA_SUCCESS : PSA_ERROR_DOES_NOT_EXIST; |
| 137 |
} |
| 138 |
|
| 139 |
if( status == PSA_SUCCESS ) |
| 140 |
{ |
| 141 |
status = psa_lock_key_slot( slot ); |
| 142 |
if( status == PSA_SUCCESS ) |
| 143 |
*p_slot = slot; |
| 144 |
} |
| 145 |
|
| 146 |
return( status ); |
| 147 |
} |
| 148 |
|
| 149 |
psa_status_t psa_initialize_key_slots( void ) |
| 150 |
{ |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
global_data.key_slots_initialized = 1; |
| 155 |
return( PSA_SUCCESS ); |
| 156 |
} |
| 157 |
|
| 158 |
void psa_wipe_all_key_slots( void ) |
| 159 |
{ |
| 160 |
size_t slot_idx; |
| 161 |
|
| 162 |
for( slot_idx = 0; slot_idx < MBEDTLS_PSA_KEY_SLOT_COUNT; slot_idx++ ) |
| 163 |
{ |
| 164 |
psa_key_slot_t *slot = &global_data.key_slots[ slot_idx ]; |
| 165 |
slot->lock_count = 1; |
| 166 |
(void) psa_wipe_key_slot( slot ); |
| 167 |
} |
| 168 |
global_data.key_slots_initialized = 0; |
| 169 |
} |
| 170 |
|
| 171 |
psa_status_t psa_get_empty_key_slot( psa_key_id_t *volatile_key_id, |
| 172 |
psa_key_slot_t **p_slot ) |
| 173 |
{ |
| 174 |
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 175 |
size_t slot_idx; |
| 176 |
psa_key_slot_t *selected_slot, *unlocked_persistent_key_slot; |
| 177 |
|
| 178 |
if( ! global_data.key_slots_initialized ) |
| 179 |
{ |
| 180 |
status = PSA_ERROR_BAD_STATE; |
| 181 |
goto error; |
| 182 |
} |
| 183 |
|
| 184 |
selected_slot = unlocked_persistent_key_slot = NULL; |
| 185 |
for( slot_idx = 0; slot_idx < MBEDTLS_PSA_KEY_SLOT_COUNT; slot_idx++ ) |
| 186 |
{ |
| 187 |
psa_key_slot_t *slot = &global_data.key_slots[ slot_idx ]; |
| 188 |
if( ! psa_is_key_slot_occupied( slot ) ) |
| 189 |
{ |
| 190 |
selected_slot = slot; |
| 191 |
break; |
| 192 |
} |
| 193 |
|
| 194 |
if( ( unlocked_persistent_key_slot == NULL ) && |
| 195 |
( ! PSA_KEY_LIFETIME_IS_VOLATILE( slot->attr.lifetime ) ) && |
| 196 |
( ! psa_is_key_slot_locked( slot ) ) ) |
| 197 |
unlocked_persistent_key_slot = slot; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
if( ( selected_slot == NULL ) && |
| 208 |
( unlocked_persistent_key_slot != NULL ) ) |
| 209 |
{ |
| 210 |
selected_slot = unlocked_persistent_key_slot; |
| 211 |
selected_slot->lock_count = 1; |
| 212 |
psa_wipe_key_slot( selected_slot ); |
| 213 |
} |
| 214 |
|
| 215 |
if( selected_slot != NULL ) |
| 216 |
{ |
| 217 |
status = psa_lock_key_slot( selected_slot ); |
| 218 |
if( status != PSA_SUCCESS ) |
| 219 |
goto error; |
| 220 |
|
| 221 |
*volatile_key_id = PSA_KEY_ID_VOLATILE_MIN + |
| 222 |
( (psa_key_id_t)( selected_slot - global_data.key_slots ) ); |
| 223 |
*p_slot = selected_slot; |
| 224 |
|
| 225 |
return( PSA_SUCCESS ); |
| 226 |
} |
| 227 |
status = PSA_ERROR_INSUFFICIENT_MEMORY; |
| 228 |
|
| 229 |
error: |
| 230 |
*p_slot = NULL; |
| 231 |
*volatile_key_id = 0; |
| 232 |
|
| 233 |
return( status ); |
| 234 |
} |
| 235 |
|
| 236 |
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) |
| 237 |
static psa_status_t psa_load_persistent_key_into_slot( psa_key_slot_t *slot ) |
| 238 |
{ |
| 239 |
psa_status_t status = PSA_SUCCESS; |
| 240 |
uint8_t *key_data = NULL; |
| 241 |
size_t key_data_length = 0; |
| 242 |
|
| 243 |
status = psa_load_persistent_key( &slot->attr, |
| 244 |
&key_data, &key_data_length ); |
| 245 |
if( status != PSA_SUCCESS ) |
| 246 |
goto exit; |
| 247 |
|
| 248 |
#if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 249 |
|
| 250 |
|
| 251 |
const psa_drv_se_t *drv; |
| 252 |
psa_drv_se_context_t *drv_context; |
| 253 |
if( psa_get_se_driver( slot->attr.lifetime, &drv, &drv_context ) ) |
| 254 |
{ |
| 255 |
psa_se_key_data_storage_t *data; |
| 256 |
|
| 257 |
if( key_data_length != sizeof( *data ) ) |
| 258 |
{ |
| 259 |
status = PSA_ERROR_DATA_INVALID; |
| 260 |
goto exit; |
| 261 |
} |
| 262 |
data = (psa_se_key_data_storage_t *) key_data; |
| 263 |
status = psa_copy_key_material_into_slot( |
| 264 |
slot, data->slot_number, sizeof( data->slot_number ) ); |
| 265 |
goto exit; |
| 266 |
} |
| 267 |
#endif |
| 268 |
|
| 269 |
status = psa_copy_key_material_into_slot( slot, key_data, key_data_length ); |
| 270 |
|
| 271 |
exit: |
| 272 |
psa_free_persistent_key_data( key_data, key_data_length ); |
| 273 |
return( status ); |
| 274 |
} |
| 275 |
#endif |
| 276 |
|
| 277 |
#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) |
| 278 |
|
| 279 |
static psa_status_t psa_load_builtin_key_into_slot( psa_key_slot_t *slot ) |
| 280 |
{ |
| 281 |
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 282 |
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; |
| 283 |
psa_key_lifetime_t lifetime = PSA_KEY_LIFETIME_VOLATILE; |
| 284 |
psa_drv_slot_number_t slot_number = 0; |
| 285 |
size_t key_buffer_size = 0; |
| 286 |
size_t key_buffer_length = 0; |
| 287 |
|
| 288 |
if( ! psa_key_id_is_builtin( |
| 289 |
MBEDTLS_SVC_KEY_ID_GET_KEY_ID( slot->attr.id ) ) ) |
| 290 |
{ |
| 291 |
return( PSA_ERROR_DOES_NOT_EXIST ); |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
status = mbedtls_psa_platform_get_builtin_key( |
| 296 |
slot->attr.id, &lifetime, &slot_number ); |
| 297 |
if( status != PSA_SUCCESS ) |
| 298 |
return( status ); |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
psa_set_key_id( &attributes, slot->attr.id ); |
| 303 |
psa_set_key_lifetime( &attributes, lifetime ); |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
status = psa_driver_wrapper_get_builtin_key( |
| 308 |
slot_number, &attributes, |
| 309 |
NULL, 0, NULL ); |
| 310 |
if( status != PSA_ERROR_BUFFER_TOO_SMALL ) |
| 311 |
{ |
| 312 |
|
| 313 |
if( status == PSA_SUCCESS ) |
| 314 |
status = PSA_ERROR_CORRUPTION_DETECTED; |
| 315 |
return( status ); |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
status = psa_driver_wrapper_get_key_buffer_size( &attributes, |
| 321 |
&key_buffer_size ); |
| 322 |
if( status != PSA_SUCCESS ) |
| 323 |
return( status ); |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
status = psa_allocate_buffer_to_slot( slot, key_buffer_size ); |
| 328 |
if( status != PSA_SUCCESS ) |
| 329 |
return( status ); |
| 330 |
|
| 331 |
status = psa_driver_wrapper_get_builtin_key( |
| 332 |
slot_number, &attributes, |
| 333 |
slot->key.data, slot->key.bytes, &key_buffer_length ); |
| 334 |
if( status != PSA_SUCCESS ) |
| 335 |
goto exit; |
| 336 |
|
| 337 |
|
| 338 |
slot->key.bytes = key_buffer_length; |
| 339 |
slot->attr = attributes.core; |
| 340 |
|
| 341 |
exit: |
| 342 |
if( status != PSA_SUCCESS ) |
| 343 |
psa_remove_key_data_from_memory( slot ); |
| 344 |
return( status ); |
| 345 |
} |
| 346 |
#endif |
| 347 |
|
| 348 |
psa_status_t psa_get_and_lock_key_slot( mbedtls_svc_key_id_t key, |
| 349 |
psa_key_slot_t **p_slot ) |
| 350 |
{ |
| 351 |
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 352 |
|
| 353 |
*p_slot = NULL; |
| 354 |
if( ! global_data.key_slots_initialized ) |
| 355 |
return( PSA_ERROR_BAD_STATE ); |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
status = psa_get_and_lock_key_slot_in_memory( key, p_slot ); |
| 362 |
if( status != PSA_ERROR_DOES_NOT_EXIST ) |
| 363 |
return( status ); |
| 364 |
|
| 365 |
|
| 366 |
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) || \ |
| 367 |
defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) |
| 368 |
psa_key_id_t volatile_key_id; |
| 369 |
|
| 370 |
status = psa_get_empty_key_slot( &volatile_key_id, p_slot ); |
| 371 |
if( status != PSA_SUCCESS ) |
| 372 |
return( status ); |
| 373 |
|
| 374 |
(*p_slot)->attr.id = key; |
| 375 |
(*p_slot)->attr.lifetime = PSA_KEY_LIFETIME_PERSISTENT; |
| 376 |
|
| 377 |
status = PSA_ERROR_DOES_NOT_EXIST; |
| 378 |
#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) |
| 379 |
|
| 380 |
status = psa_load_builtin_key_into_slot( *p_slot ); |
| 381 |
#endif |
| 382 |
|
| 383 |
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) |
| 384 |
if( status == PSA_ERROR_DOES_NOT_EXIST ) |
| 385 |
status = psa_load_persistent_key_into_slot( *p_slot ); |
| 386 |
#endif |
| 387 |
|
| 388 |
if( status != PSA_SUCCESS ) |
| 389 |
{ |
| 390 |
psa_wipe_key_slot( *p_slot ); |
| 391 |
if( status == PSA_ERROR_DOES_NOT_EXIST ) |
| 392 |
status = PSA_ERROR_INVALID_HANDLE; |
| 393 |
} |
| 394 |
else |
| 395 |
|
| 396 |
psa_extend_key_usage_flags( &(*p_slot)->attr.policy.usage ); |
| 397 |
|
| 398 |
return( status ); |
| 399 |
#else |
| 400 |
return( PSA_ERROR_INVALID_HANDLE ); |
| 401 |
#endif |
| 402 |
} |
| 403 |
|
| 404 |
psa_status_t psa_unlock_key_slot( psa_key_slot_t *slot ) |
| 405 |
{ |
| 406 |
if( slot == NULL ) |
| 407 |
return( PSA_SUCCESS ); |
| 408 |
|
| 409 |
if( slot->lock_count > 0 ) |
| 410 |
{ |
| 411 |
slot->lock_count--; |
| 412 |
return( PSA_SUCCESS ); |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
#ifdef MBEDTLS_CHECK_PARAMS |
| 423 |
MBEDTLS_PARAM_FAILED( slot->lock_count > 0 ); |
| 424 |
#endif |
| 425 |
|
| 426 |
return( PSA_ERROR_CORRUPTION_DETECTED ); |
| 427 |
} |
| 428 |
|
| 429 |
psa_status_t psa_validate_key_location( psa_key_lifetime_t lifetime, |
| 430 |
psa_se_drv_table_entry_t **p_drv ) |
| 431 |
{ |
| 432 |
if ( psa_key_lifetime_is_external( lifetime ) ) |
| 433 |
{ |
| 434 |
#if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 435 |
|
| 436 |
psa_se_drv_table_entry_t *driver = psa_get_se_driver_entry( lifetime ); |
| 437 |
if( driver != NULL ) |
| 438 |
{ |
| 439 |
if (p_drv != NULL) |
| 440 |
*p_drv = driver; |
| 441 |
return( PSA_SUCCESS ); |
| 442 |
} |
| 443 |
#else |
| 444 |
(void) p_drv; |
| 445 |
#endif |
| 446 |
|
| 447 |
#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) |
| 448 |
|
| 449 |
return( PSA_SUCCESS ); |
| 450 |
#else |
| 451 |
|
| 452 |
|
| 453 |
return( PSA_ERROR_INVALID_ARGUMENT ); |
| 454 |
#endif |
| 455 |
} |
| 456 |
else |
| 457 |
|
| 458 |
return( PSA_SUCCESS ); |
| 459 |
} |
| 460 |
|
| 461 |
psa_status_t psa_validate_key_persistence( psa_key_lifetime_t lifetime ) |
| 462 |
{ |
| 463 |
if ( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) ) |
| 464 |
{ |
| 465 |
|
| 466 |
return( PSA_SUCCESS ); |
| 467 |
} |
| 468 |
else |
| 469 |
{ |
| 470 |
|
| 471 |
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) |
| 472 |
if( PSA_KEY_LIFETIME_IS_READ_ONLY( lifetime ) ) |
| 473 |
return( PSA_ERROR_INVALID_ARGUMENT ); |
| 474 |
else |
| 475 |
return( PSA_SUCCESS ); |
| 476 |
#else |
| 477 |
return( PSA_ERROR_NOT_SUPPORTED ); |
| 478 |
#endif |
| 479 |
} |
| 480 |
} |
| 481 |
|
| 482 |
psa_status_t psa_open_key( mbedtls_svc_key_id_t key, psa_key_handle_t *handle ) |
| 483 |
{ |
| 484 |
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) || \ |
| 485 |
defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) |
| 486 |
psa_status_t status; |
| 487 |
psa_key_slot_t *slot; |
| 488 |
|
| 489 |
status = psa_get_and_lock_key_slot( key, &slot ); |
| 490 |
if( status != PSA_SUCCESS ) |
| 491 |
{ |
| 492 |
*handle = PSA_KEY_HANDLE_INIT; |
| 493 |
if( status == PSA_ERROR_INVALID_HANDLE ) |
| 494 |
status = PSA_ERROR_DOES_NOT_EXIST; |
| 495 |
|
| 496 |
return( status ); |
| 497 |
} |
| 498 |
|
| 499 |
*handle = key; |
| 500 |
|
| 501 |
return( psa_unlock_key_slot( slot ) ); |
| 502 |
|
| 503 |
#else |
| 504 |
(void) key; |
| 505 |
*handle = PSA_KEY_HANDLE_INIT; |
| 506 |
return( PSA_ERROR_NOT_SUPPORTED ); |
| 507 |
#endif |
| 508 |
} |
| 509 |
|
| 510 |
psa_status_t psa_close_key( psa_key_handle_t handle ) |
| 511 |
{ |
| 512 |
psa_status_t status; |
| 513 |
psa_key_slot_t *slot; |
| 514 |
|
| 515 |
if( psa_key_handle_is_null( handle ) ) |
| 516 |
return( PSA_SUCCESS ); |
| 517 |
|
| 518 |
status = psa_get_and_lock_key_slot_in_memory( handle, &slot ); |
| 519 |
if( status != PSA_SUCCESS ) |
| 520 |
{ |
| 521 |
if( status == PSA_ERROR_DOES_NOT_EXIST ) |
| 522 |
status = PSA_ERROR_INVALID_HANDLE; |
| 523 |
|
| 524 |
return( status ); |
| 525 |
} |
| 526 |
if( slot->lock_count <= 1 ) |
| 527 |
return( psa_wipe_key_slot( slot ) ); |
| 528 |
else |
| 529 |
return( psa_unlock_key_slot( slot ) ); |
| 530 |
} |
| 531 |
|
| 532 |
psa_status_t psa_purge_key( mbedtls_svc_key_id_t key ) |
| 533 |
{ |
| 534 |
psa_status_t status; |
| 535 |
psa_key_slot_t *slot; |
| 536 |
|
| 537 |
status = psa_get_and_lock_key_slot_in_memory( key, &slot ); |
| 538 |
if( status != PSA_SUCCESS ) |
| 539 |
return( status ); |
| 540 |
|
| 541 |
if( ( ! PSA_KEY_LIFETIME_IS_VOLATILE( slot->attr.lifetime ) ) && |
| 542 |
( slot->lock_count <= 1 ) ) |
| 543 |
return( psa_wipe_key_slot( slot ) ); |
| 544 |
else |
| 545 |
return( psa_unlock_key_slot( slot ) ); |
| 546 |
} |
| 547 |
|
| 548 |
void mbedtls_psa_get_stats( mbedtls_psa_stats_t *stats ) |
| 549 |
{ |
| 550 |
size_t slot_idx; |
| 551 |
|
| 552 |
memset( stats, 0, sizeof( *stats ) ); |
| 553 |
|
| 554 |
for( slot_idx = 0; slot_idx < MBEDTLS_PSA_KEY_SLOT_COUNT; slot_idx++ ) |
| 555 |
{ |
| 556 |
const psa_key_slot_t *slot = &global_data.key_slots[ slot_idx ]; |
| 557 |
if( psa_is_key_slot_locked( slot ) ) |
| 558 |
{ |
| 559 |
++stats->locked_slots; |
| 560 |
} |
| 561 |
if( ! psa_is_key_slot_occupied( slot ) ) |
| 562 |
{ |
| 563 |
++stats->empty_slots; |
| 564 |
continue; |
| 565 |
} |
| 566 |
if( PSA_KEY_LIFETIME_IS_VOLATILE( slot->attr.lifetime ) ) |
| 567 |
++stats->volatile_slots; |
| 568 |
else |
| 569 |
{ |
| 570 |
psa_key_id_t id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( slot->attr.id ); |
| 571 |
++stats->persistent_slots; |
| 572 |
if( id > stats->max_open_internal_key_id ) |
| 573 |
stats->max_open_internal_key_id = id; |
| 574 |
} |
| 575 |
if( PSA_KEY_LIFETIME_GET_LOCATION( slot->attr.lifetime ) != |
| 576 |
PSA_KEY_LOCATION_LOCAL_STORAGE ) |
| 577 |
{ |
| 578 |
psa_key_id_t id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( slot->attr.id ); |
| 579 |
++stats->external_slots; |
| 580 |
if( id > stats->max_open_external_key_id ) |
| 581 |
stats->max_open_external_key_id = id; |
| 582 |
} |
| 583 |
} |
| 584 |
} |
| 585 |
|
| 586 |
#endif |