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