Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 1 | /* |
| 2 | * PSA crypto layer on top of Mbed TLS crypto |
| 3 | */ |
Bence Szépkúti | 8697465 | 2020-06-15 11:59:37 +0200 | [diff] [blame] | 4 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 5 | * Copyright The Mbed TLS Contributors |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 6 | * SPDX-License-Identifier: Apache-2.0 |
| 7 | * |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 9 | * not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 16 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 19 | */ |
| 20 | |
Gilles Peskine | db09ef6 | 2020-06-03 01:43:33 +0200 | [diff] [blame] | 21 | #include "common.h" |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 22 | |
| 23 | #if defined(MBEDTLS_PSA_CRYPTO_C) |
| 24 | |
itayzafrir | 7723ab1 | 2019-02-14 10:28:02 +0200 | [diff] [blame] | 25 | #include "psa_crypto_service_integration.h" |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 26 | #include "psa/crypto.h" |
| 27 | |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 28 | #include "psa_crypto_core.h" |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 29 | #include "psa_crypto_slot_management.h" |
| 30 | #include "psa_crypto_storage.h" |
Gilles Peskine | b46bef2 | 2019-07-30 21:32:04 +0200 | [diff] [blame] | 31 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 32 | #include "psa_crypto_se.h" |
| 33 | #endif |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 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 | |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 46 | typedef struct |
| 47 | { |
| 48 | psa_key_slot_t key_slots[PSA_KEY_SLOT_COUNT]; |
| 49 | unsigned key_slots_initialized : 1; |
| 50 | } psa_global_data_t; |
| 51 | |
Gilles Peskine | 2e14bd3 | 2018-12-12 14:05:08 +0100 | [diff] [blame] | 52 | static psa_global_data_t global_data; |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 53 | |
Ronald Cron | d2ed481 | 2020-07-17 16:11:30 +0200 | [diff] [blame] | 54 | psa_status_t psa_validate_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( PSA_SUCCESS ); |
| 61 | |
| 62 | if( vendor_ok && |
| 63 | ( PSA_KEY_ID_VENDOR_MIN <= key_id ) && |
| 64 | ( key_id <= PSA_KEY_ID_VENDOR_MAX ) ) |
| 65 | return( PSA_SUCCESS ); |
| 66 | |
| 67 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 68 | } |
| 69 | |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 70 | /* Access a key slot at the given handle. The handle of a key slot is |
| 71 | * the index of the slot in the global slot array, plus one so that handles |
| 72 | * start at 1 and not 0. */ |
| 73 | psa_status_t psa_get_key_slot( psa_key_handle_t handle, |
| 74 | psa_key_slot_t **p_slot ) |
| 75 | { |
| 76 | psa_key_slot_t *slot = NULL; |
| 77 | |
| 78 | if( ! global_data.key_slots_initialized ) |
| 79 | return( PSA_ERROR_BAD_STATE ); |
| 80 | |
| 81 | /* 0 is not a valid handle under any circumstance. This |
| 82 | * implementation provides slots number 1 to N where N is the |
| 83 | * number of available slots. */ |
| 84 | if( handle == 0 || handle > ARRAY_LENGTH( global_data.key_slots ) ) |
| 85 | return( PSA_ERROR_INVALID_HANDLE ); |
| 86 | slot = &global_data.key_slots[handle - 1]; |
| 87 | |
Gilles Peskine | 41e50d2 | 2019-07-31 15:01:55 +0200 | [diff] [blame] | 88 | /* If the slot isn't occupied, the handle is invalid. */ |
| 89 | if( ! psa_is_key_slot_occupied( slot ) ) |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 90 | return( PSA_ERROR_INVALID_HANDLE ); |
| 91 | |
| 92 | *p_slot = slot; |
| 93 | return( PSA_SUCCESS ); |
| 94 | } |
| 95 | |
| 96 | psa_status_t psa_initialize_key_slots( void ) |
| 97 | { |
| 98 | /* Nothing to do: program startup and psa_wipe_all_key_slots() both |
| 99 | * guarantee that the key slots are initialized to all-zero, which |
| 100 | * means that all the key slots are in a valid, empty state. */ |
| 101 | global_data.key_slots_initialized = 1; |
| 102 | return( PSA_SUCCESS ); |
| 103 | } |
| 104 | |
| 105 | void psa_wipe_all_key_slots( void ) |
| 106 | { |
| 107 | psa_key_handle_t key; |
| 108 | for( key = 1; key <= PSA_KEY_SLOT_COUNT; key++ ) |
| 109 | { |
| 110 | psa_key_slot_t *slot = &global_data.key_slots[key - 1]; |
| 111 | (void) psa_wipe_key_slot( slot ); |
| 112 | } |
| 113 | global_data.key_slots_initialized = 0; |
| 114 | } |
| 115 | |
Gilles Peskine | edbed56 | 2019-08-07 18:19:59 +0200 | [diff] [blame] | 116 | psa_status_t psa_get_empty_key_slot( psa_key_handle_t *handle, |
Ronald Cron | 2a99315 | 2020-07-17 14:13:26 +0200 | [diff] [blame^] | 117 | psa_key_id_t *volatile_key_id, |
| 118 | psa_key_slot_t **p_slot ) |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 119 | { |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 120 | if( ! global_data.key_slots_initialized ) |
| 121 | return( PSA_ERROR_BAD_STATE ); |
| 122 | |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 123 | for( *handle = PSA_KEY_SLOT_COUNT; *handle != 0; --( *handle ) ) |
| 124 | { |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 125 | *p_slot = &global_data.key_slots[*handle - 1]; |
Gilles Peskine | 41e50d2 | 2019-07-31 15:01:55 +0200 | [diff] [blame] | 126 | if( ! psa_is_key_slot_occupied( *p_slot ) ) |
Ronald Cron | 2a99315 | 2020-07-17 14:13:26 +0200 | [diff] [blame^] | 127 | { |
| 128 | *volatile_key_id = PSA_KEY_ID_VOLATILE_MIN + ( *handle ) - 1; |
| 129 | |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 130 | return( PSA_SUCCESS ); |
Ronald Cron | 2a99315 | 2020-07-17 14:13:26 +0200 | [diff] [blame^] | 131 | } |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 132 | } |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 133 | *p_slot = NULL; |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 134 | return( PSA_ERROR_INSUFFICIENT_MEMORY ); |
| 135 | } |
| 136 | |
Gilles Peskine | fa4135b | 2018-12-10 16:48:53 +0100 | [diff] [blame] | 137 | #if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) |
Gilles Peskine | 2431859 | 2019-07-30 20:30:51 +0200 | [diff] [blame] | 138 | static psa_status_t psa_load_persistent_key_into_slot( psa_key_slot_t *slot ) |
Gilles Peskine | fa4135b | 2018-12-10 16:48:53 +0100 | [diff] [blame] | 139 | { |
| 140 | psa_status_t status = PSA_SUCCESS; |
| 141 | uint8_t *key_data = NULL; |
| 142 | size_t key_data_length = 0; |
| 143 | |
Gilles Peskine | 2431859 | 2019-07-30 20:30:51 +0200 | [diff] [blame] | 144 | status = psa_load_persistent_key( &slot->attr, |
Gilles Peskine | bfd322f | 2019-07-23 11:58:03 +0200 | [diff] [blame] | 145 | &key_data, &key_data_length ); |
Gilles Peskine | fa4135b | 2018-12-10 16:48:53 +0100 | [diff] [blame] | 146 | if( status != PSA_SUCCESS ) |
| 147 | goto exit; |
Gilles Peskine | 1df83d4 | 2019-07-23 16:13:14 +0200 | [diff] [blame] | 148 | |
| 149 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
Gilles Peskine | 2431859 | 2019-07-30 20:30:51 +0200 | [diff] [blame] | 150 | if( psa_key_lifetime_is_external( slot->attr.lifetime ) ) |
Gilles Peskine | 1df83d4 | 2019-07-23 16:13:14 +0200 | [diff] [blame] | 151 | { |
Gilles Peskine | b46bef2 | 2019-07-30 21:32:04 +0200 | [diff] [blame] | 152 | psa_se_key_data_storage_t *data; |
| 153 | if( key_data_length != sizeof( *data ) ) |
Gilles Peskine | 1df83d4 | 2019-07-23 16:13:14 +0200 | [diff] [blame] | 154 | { |
| 155 | status = PSA_ERROR_STORAGE_FAILURE; |
| 156 | goto exit; |
| 157 | } |
Gilles Peskine | b46bef2 | 2019-07-30 21:32:04 +0200 | [diff] [blame] | 158 | data = (psa_se_key_data_storage_t *) key_data; |
| 159 | memcpy( &slot->data.se.slot_number, &data->slot_number, |
| 160 | sizeof( slot->data.se.slot_number ) ); |
Gilles Peskine | 1df83d4 | 2019-07-23 16:13:14 +0200 | [diff] [blame] | 161 | } |
| 162 | else |
| 163 | #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ |
| 164 | { |
Steven Cooreman | 3ea0ce4 | 2020-10-23 11:37:05 +0200 | [diff] [blame] | 165 | status = psa_copy_key_material_into_slot( slot, key_data, key_data_length ); |
| 166 | if( status != PSA_SUCCESS ) |
| 167 | goto exit; |
Gilles Peskine | 1df83d4 | 2019-07-23 16:13:14 +0200 | [diff] [blame] | 168 | } |
| 169 | |
Gilles Peskine | fa4135b | 2018-12-10 16:48:53 +0100 | [diff] [blame] | 170 | exit: |
| 171 | psa_free_persistent_key_data( key_data, key_data_length ); |
| 172 | return( status ); |
| 173 | } |
Gilles Peskine | 30afafd | 2019-04-25 13:47:40 +0200 | [diff] [blame] | 174 | #endif /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */ |
Gilles Peskine | fa4135b | 2018-12-10 16:48:53 +0100 | [diff] [blame] | 175 | |
Steven Cooreman | 8c1e759 | 2020-06-17 14:52:05 +0200 | [diff] [blame] | 176 | psa_status_t psa_validate_key_location( psa_key_lifetime_t lifetime, |
Steven Cooreman | 81fe7c3 | 2020-06-08 18:37:19 +0200 | [diff] [blame] | 177 | psa_se_drv_table_entry_t **p_drv ) |
Gilles Peskine | d167b94 | 2019-04-19 18:19:40 +0200 | [diff] [blame] | 178 | { |
Steven Cooreman | 81fe7c3 | 2020-06-08 18:37:19 +0200 | [diff] [blame] | 179 | if ( psa_key_lifetime_is_external( lifetime ) ) |
Gilles Peskine | 011e428 | 2019-06-26 18:34:38 +0200 | [diff] [blame] | 180 | { |
Steven Cooreman | 81fe7c3 | 2020-06-08 18:37:19 +0200 | [diff] [blame] | 181 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
Steven Cooreman | 00106a1 | 2020-06-08 18:54:23 +0200 | [diff] [blame] | 182 | psa_se_drv_table_entry_t *driver = psa_get_se_driver_entry( lifetime ); |
| 183 | if( driver == NULL ) |
Gilles Peskine | 011e428 | 2019-06-26 18:34:38 +0200 | [diff] [blame] | 184 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 81fe7c3 | 2020-06-08 18:37:19 +0200 | [diff] [blame] | 185 | else |
| 186 | { |
| 187 | if (p_drv != NULL) |
Steven Cooreman | 00106a1 | 2020-06-08 18:54:23 +0200 | [diff] [blame] | 188 | *p_drv = driver; |
Steven Cooreman | 81fe7c3 | 2020-06-08 18:37:19 +0200 | [diff] [blame] | 189 | return( PSA_SUCCESS ); |
| 190 | } |
| 191 | #else |
| 192 | (void) p_drv; |
| 193 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 194 | #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ |
Gilles Peskine | 011e428 | 2019-06-26 18:34:38 +0200 | [diff] [blame] | 195 | } |
| 196 | else |
Steven Cooreman | 81fe7c3 | 2020-06-08 18:37:19 +0200 | [diff] [blame] | 197 | /* Local/internal keys are always valid */ |
| 198 | return( PSA_SUCCESS ); |
| 199 | } |
Gilles Peskine | 30afafd | 2019-04-25 13:47:40 +0200 | [diff] [blame] | 200 | |
Ronald Cron | d2ed481 | 2020-07-17 16:11:30 +0200 | [diff] [blame] | 201 | psa_status_t psa_validate_key_persistence( psa_key_lifetime_t lifetime ) |
Steven Cooreman | 81fe7c3 | 2020-06-08 18:37:19 +0200 | [diff] [blame] | 202 | { |
Steven Cooreman | 81fe7c3 | 2020-06-08 18:37:19 +0200 | [diff] [blame] | 203 | if ( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) ) |
| 204 | { |
| 205 | /* Volatile keys are always supported */ |
| 206 | return( PSA_SUCCESS ); |
| 207 | } |
| 208 | else |
| 209 | { |
| 210 | /* Persistent keys require storage support */ |
Gilles Peskine | 30afafd | 2019-04-25 13:47:40 +0200 | [diff] [blame] | 211 | #if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) |
Ronald Cron | d2ed481 | 2020-07-17 16:11:30 +0200 | [diff] [blame] | 212 | return( PSA_SUCCESS ); |
Gilles Peskine | 30afafd | 2019-04-25 13:47:40 +0200 | [diff] [blame] | 213 | #else /* MBEDTLS_PSA_CRYPTO_STORAGE_C */ |
Steven Cooreman | 81fe7c3 | 2020-06-08 18:37:19 +0200 | [diff] [blame] | 214 | return( PSA_ERROR_NOT_SUPPORTED ); |
Gilles Peskine | 30afafd | 2019-04-25 13:47:40 +0200 | [diff] [blame] | 215 | #endif /* !MBEDTLS_PSA_CRYPTO_STORAGE_C */ |
Steven Cooreman | 81fe7c3 | 2020-06-08 18:37:19 +0200 | [diff] [blame] | 216 | } |
Gilles Peskine | d167b94 | 2019-04-19 18:19:40 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Ronald Cron | 71016a9 | 2020-08-28 19:01:50 +0200 | [diff] [blame] | 219 | psa_status_t psa_open_key( mbedtls_svc_key_id_t key, psa_key_handle_t *handle ) |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 220 | { |
Gilles Peskine | 70e085a | 2019-05-27 19:04:07 +0200 | [diff] [blame] | 221 | #if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 222 | psa_status_t status; |
Ronald Cron | 2a99315 | 2020-07-17 14:13:26 +0200 | [diff] [blame^] | 223 | psa_key_id_t volatile_key_id; |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 224 | psa_key_slot_t *slot; |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 225 | |
| 226 | *handle = 0; |
| 227 | |
Ronald Cron | d2ed481 | 2020-07-17 16:11:30 +0200 | [diff] [blame] | 228 | status = psa_validate_key_id( key, 1 ); |
| 229 | if( status != PSA_SUCCESS ) |
| 230 | return( status ); |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 231 | |
Ronald Cron | 2a99315 | 2020-07-17 14:13:26 +0200 | [diff] [blame^] | 232 | status = psa_get_empty_key_slot( handle, &volatile_key_id, &slot ); |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 233 | if( status != PSA_SUCCESS ) |
| 234 | return( status ); |
| 235 | |
Gilles Peskine | 8e33870 | 2019-07-30 20:06:31 +0200 | [diff] [blame] | 236 | slot->attr.lifetime = PSA_KEY_LIFETIME_PERSISTENT; |
Ronald Cron | 27238fc | 2020-07-23 12:30:41 +0200 | [diff] [blame] | 237 | slot->attr.id = key; |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 238 | |
| 239 | status = psa_load_persistent_key_into_slot( slot ); |
Gilles Peskine | 70e085a | 2019-05-27 19:04:07 +0200 | [diff] [blame] | 240 | if( status != PSA_SUCCESS ) |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 241 | { |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 242 | psa_wipe_key_slot( slot ); |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 243 | *handle = 0; |
| 244 | } |
| 245 | return( status ); |
Gilles Peskine | 70e085a | 2019-05-27 19:04:07 +0200 | [diff] [blame] | 246 | |
Gilles Peskine | 30afafd | 2019-04-25 13:47:40 +0200 | [diff] [blame] | 247 | #else /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */ |
Ronald Cron | 27238fc | 2020-07-23 12:30:41 +0200 | [diff] [blame] | 248 | (void) key; |
Gilles Peskine | 70e085a | 2019-05-27 19:04:07 +0200 | [diff] [blame] | 249 | *handle = 0; |
Gilles Peskine | 30afafd | 2019-04-25 13:47:40 +0200 | [diff] [blame] | 250 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 251 | #endif /* !defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */ |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 252 | } |
| 253 | |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 254 | psa_status_t psa_close_key( psa_key_handle_t handle ) |
| 255 | { |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 256 | psa_status_t status; |
| 257 | psa_key_slot_t *slot; |
| 258 | |
Gilles Peskine | 1841cf4 | 2019-10-08 15:48:25 +0200 | [diff] [blame] | 259 | if( handle == 0 ) |
| 260 | return( PSA_SUCCESS ); |
| 261 | |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 262 | status = psa_get_key_slot( handle, &slot ); |
| 263 | if( status != PSA_SUCCESS ) |
| 264 | return( status ); |
| 265 | |
| 266 | return( psa_wipe_key_slot( slot ) ); |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 267 | } |
| 268 | |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 269 | void mbedtls_psa_get_stats( mbedtls_psa_stats_t *stats ) |
| 270 | { |
| 271 | psa_key_handle_t key; |
| 272 | memset( stats, 0, sizeof( *stats ) ); |
| 273 | for( key = 1; key <= PSA_KEY_SLOT_COUNT; key++ ) |
| 274 | { |
Gilles Peskine | 41e50d2 | 2019-07-31 15:01:55 +0200 | [diff] [blame] | 275 | const psa_key_slot_t *slot = &global_data.key_slots[key - 1]; |
| 276 | if( ! psa_is_key_slot_occupied( slot ) ) |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 277 | { |
Gilles Peskine | 41e50d2 | 2019-07-31 15:01:55 +0200 | [diff] [blame] | 278 | ++stats->empty_slots; |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 279 | continue; |
| 280 | } |
Gilles Peskine | 8e33870 | 2019-07-30 20:06:31 +0200 | [diff] [blame] | 281 | if( slot->attr.lifetime == PSA_KEY_LIFETIME_VOLATILE ) |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 282 | ++stats->volatile_slots; |
Gilles Peskine | 8e33870 | 2019-07-30 20:06:31 +0200 | [diff] [blame] | 283 | else if( slot->attr.lifetime == PSA_KEY_LIFETIME_PERSISTENT ) |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 284 | { |
Ronald Cron | 71016a9 | 2020-08-28 19:01:50 +0200 | [diff] [blame] | 285 | psa_key_id_t id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( slot->attr.id ); |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 286 | ++stats->persistent_slots; |
Jaeden Amero | 6fa62a5 | 2019-08-20 17:43:48 +0100 | [diff] [blame] | 287 | if( id > stats->max_open_internal_key_id ) |
| 288 | stats->max_open_internal_key_id = id; |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 289 | } |
| 290 | else |
| 291 | { |
Ronald Cron | 71016a9 | 2020-08-28 19:01:50 +0200 | [diff] [blame] | 292 | psa_key_id_t id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( slot->attr.id ); |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 293 | ++stats->external_slots; |
Jaeden Amero | 6fa62a5 | 2019-08-20 17:43:48 +0100 | [diff] [blame] | 294 | if( id > stats->max_open_external_key_id ) |
| 295 | stats->max_open_external_key_id = id; |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | } |
| 299 | |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 300 | #endif /* MBEDTLS_PSA_CRYPTO_C */ |