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 | /* |
| 5 | * Copyright (C) 2018, ARM Limited, All Rights Reserved |
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. |
| 19 | * |
| 20 | * This file is part of mbed TLS (https://tls.mbed.org) |
| 21 | */ |
| 22 | |
| 23 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 24 | #include "mbedtls/config.h" |
| 25 | #else |
| 26 | #include MBEDTLS_CONFIG_FILE |
| 27 | #endif |
| 28 | |
| 29 | #if defined(MBEDTLS_PSA_CRYPTO_C) |
| 30 | |
itayzafrir | 7723ab1 | 2019-02-14 10:28:02 +0200 | [diff] [blame] | 31 | #include "psa_crypto_service_integration.h" |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 32 | #include "psa/crypto.h" |
| 33 | |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 34 | #include "psa_crypto_core.h" |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 35 | #include "psa_crypto_slot_management.h" |
| 36 | #include "psa_crypto_storage.h" |
Gilles Peskine | b46bef2 | 2019-07-30 21:32:04 +0200 | [diff] [blame] | 37 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 38 | #include "psa_crypto_se.h" |
| 39 | #endif |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 40 | |
| 41 | #include <stdlib.h> |
| 42 | #include <string.h> |
| 43 | #if defined(MBEDTLS_PLATFORM_C) |
| 44 | #include "mbedtls/platform.h" |
| 45 | #else |
| 46 | #define mbedtls_calloc calloc |
| 47 | #define mbedtls_free free |
| 48 | #endif |
| 49 | |
| 50 | #define ARRAY_LENGTH( array ) ( sizeof( array ) / sizeof( *( array ) ) ) |
| 51 | |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 52 | typedef struct |
| 53 | { |
| 54 | psa_key_slot_t key_slots[PSA_KEY_SLOT_COUNT]; |
| 55 | unsigned key_slots_initialized : 1; |
| 56 | } psa_global_data_t; |
| 57 | |
Gilles Peskine | 2e14bd3 | 2018-12-12 14:05:08 +0100 | [diff] [blame] | 58 | static psa_global_data_t global_data; |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 59 | |
| 60 | /* Access a key slot at the given handle. The handle of a key slot is |
| 61 | * the index of the slot in the global slot array, plus one so that handles |
| 62 | * start at 1 and not 0. */ |
| 63 | psa_status_t psa_get_key_slot( psa_key_handle_t handle, |
| 64 | psa_key_slot_t **p_slot ) |
| 65 | { |
| 66 | psa_key_slot_t *slot = NULL; |
| 67 | |
| 68 | if( ! global_data.key_slots_initialized ) |
| 69 | return( PSA_ERROR_BAD_STATE ); |
| 70 | |
| 71 | /* 0 is not a valid handle under any circumstance. This |
| 72 | * implementation provides slots number 1 to N where N is the |
| 73 | * number of available slots. */ |
| 74 | if( handle == 0 || handle > ARRAY_LENGTH( global_data.key_slots ) ) |
| 75 | return( PSA_ERROR_INVALID_HANDLE ); |
| 76 | slot = &global_data.key_slots[handle - 1]; |
| 77 | |
Gilles Peskine | 41e50d2 | 2019-07-31 15:01:55 +0200 | [diff] [blame] | 78 | /* If the slot isn't occupied, the handle is invalid. */ |
| 79 | if( ! psa_is_key_slot_occupied( slot ) ) |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 80 | return( PSA_ERROR_INVALID_HANDLE ); |
| 81 | |
| 82 | *p_slot = slot; |
| 83 | return( PSA_SUCCESS ); |
| 84 | } |
| 85 | |
| 86 | psa_status_t psa_initialize_key_slots( void ) |
| 87 | { |
| 88 | /* Nothing to do: program startup and psa_wipe_all_key_slots() both |
| 89 | * guarantee that the key slots are initialized to all-zero, which |
| 90 | * means that all the key slots are in a valid, empty state. */ |
| 91 | global_data.key_slots_initialized = 1; |
| 92 | return( PSA_SUCCESS ); |
| 93 | } |
| 94 | |
| 95 | void psa_wipe_all_key_slots( void ) |
| 96 | { |
| 97 | psa_key_handle_t key; |
| 98 | for( key = 1; key <= PSA_KEY_SLOT_COUNT; key++ ) |
| 99 | { |
| 100 | psa_key_slot_t *slot = &global_data.key_slots[key - 1]; |
| 101 | (void) psa_wipe_key_slot( slot ); |
| 102 | } |
| 103 | global_data.key_slots_initialized = 0; |
| 104 | } |
| 105 | |
Gilles Peskine | edbed56 | 2019-08-07 18:19:59 +0200 | [diff] [blame] | 106 | 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] | 107 | psa_key_slot_t **p_slot ) |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 108 | { |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 109 | if( ! global_data.key_slots_initialized ) |
| 110 | return( PSA_ERROR_BAD_STATE ); |
| 111 | |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 112 | for( *handle = PSA_KEY_SLOT_COUNT; *handle != 0; --( *handle ) ) |
| 113 | { |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 114 | *p_slot = &global_data.key_slots[*handle - 1]; |
Gilles Peskine | 41e50d2 | 2019-07-31 15:01:55 +0200 | [diff] [blame] | 115 | if( ! psa_is_key_slot_occupied( *p_slot ) ) |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 116 | return( PSA_SUCCESS ); |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 117 | } |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 118 | *p_slot = NULL; |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 119 | return( PSA_ERROR_INSUFFICIENT_MEMORY ); |
| 120 | } |
| 121 | |
Gilles Peskine | fa4135b | 2018-12-10 16:48:53 +0100 | [diff] [blame] | 122 | #if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) |
Gilles Peskine | 2431859 | 2019-07-30 20:30:51 +0200 | [diff] [blame] | 123 | 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] | 124 | { |
| 125 | psa_status_t status = PSA_SUCCESS; |
| 126 | uint8_t *key_data = NULL; |
| 127 | size_t key_data_length = 0; |
| 128 | |
Gilles Peskine | 2431859 | 2019-07-30 20:30:51 +0200 | [diff] [blame] | 129 | status = psa_load_persistent_key( &slot->attr, |
Gilles Peskine | bfd322f | 2019-07-23 11:58:03 +0200 | [diff] [blame] | 130 | &key_data, &key_data_length ); |
Gilles Peskine | fa4135b | 2018-12-10 16:48:53 +0100 | [diff] [blame] | 131 | if( status != PSA_SUCCESS ) |
| 132 | goto exit; |
Gilles Peskine | 1df83d4 | 2019-07-23 16:13:14 +0200 | [diff] [blame] | 133 | |
| 134 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
Gilles Peskine | 2431859 | 2019-07-30 20:30:51 +0200 | [diff] [blame] | 135 | if( psa_key_lifetime_is_external( slot->attr.lifetime ) ) |
Gilles Peskine | 1df83d4 | 2019-07-23 16:13:14 +0200 | [diff] [blame] | 136 | { |
Gilles Peskine | b46bef2 | 2019-07-30 21:32:04 +0200 | [diff] [blame] | 137 | psa_se_key_data_storage_t *data; |
| 138 | if( key_data_length != sizeof( *data ) ) |
Gilles Peskine | 1df83d4 | 2019-07-23 16:13:14 +0200 | [diff] [blame] | 139 | { |
| 140 | status = PSA_ERROR_STORAGE_FAILURE; |
| 141 | goto exit; |
| 142 | } |
Gilles Peskine | b46bef2 | 2019-07-30 21:32:04 +0200 | [diff] [blame] | 143 | data = (psa_se_key_data_storage_t *) key_data; |
| 144 | memcpy( &slot->data.se.slot_number, &data->slot_number, |
| 145 | sizeof( slot->data.se.slot_number ) ); |
| 146 | memcpy( &slot->attr.bits, &data->bits, |
| 147 | sizeof( slot->attr.bits ) ); |
Gilles Peskine | 1df83d4 | 2019-07-23 16:13:14 +0200 | [diff] [blame] | 148 | } |
| 149 | else |
| 150 | #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ |
| 151 | { |
Gilles Peskine | 2431859 | 2019-07-30 20:30:51 +0200 | [diff] [blame] | 152 | status = psa_import_key_into_slot( slot, key_data, key_data_length ); |
Gilles Peskine | 1df83d4 | 2019-07-23 16:13:14 +0200 | [diff] [blame] | 153 | } |
| 154 | |
Gilles Peskine | fa4135b | 2018-12-10 16:48:53 +0100 | [diff] [blame] | 155 | exit: |
| 156 | psa_free_persistent_key_data( key_data, key_data_length ); |
| 157 | return( status ); |
| 158 | } |
Gilles Peskine | c8569bc | 2019-02-19 13:04:02 +0100 | [diff] [blame] | 159 | |
| 160 | /** Check whether a key identifier is acceptable. |
| 161 | * |
| 162 | * For backward compatibility, key identifiers that were valid in a |
| 163 | * past released version must remain valid, unless a migration path |
| 164 | * is provided. |
| 165 | * |
Gilles Peskine | 5b229a0 | 2019-02-19 13:24:37 +0100 | [diff] [blame] | 166 | * \param file_id The key identifier to check. |
Gilles Peskine | f966659 | 2019-05-06 18:56:30 +0200 | [diff] [blame] | 167 | * \param vendor_ok Nonzero to allow key ids in the vendor range. |
| 168 | * 0 to allow only key ids in the application range. |
Gilles Peskine | c8569bc | 2019-02-19 13:04:02 +0100 | [diff] [blame] | 169 | * |
Gilles Peskine | 5b229a0 | 2019-02-19 13:24:37 +0100 | [diff] [blame] | 170 | * \return 1 if \p file_id is acceptable, otherwise 0. |
Gilles Peskine | c8569bc | 2019-02-19 13:04:02 +0100 | [diff] [blame] | 171 | */ |
Gilles Peskine | f966659 | 2019-05-06 18:56:30 +0200 | [diff] [blame] | 172 | static int psa_is_key_id_valid( psa_key_file_id_t file_id, |
| 173 | int vendor_ok ) |
Gilles Peskine | c8569bc | 2019-02-19 13:04:02 +0100 | [diff] [blame] | 174 | { |
Gilles Peskine | 5b229a0 | 2019-02-19 13:24:37 +0100 | [diff] [blame] | 175 | 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] | 176 | if( PSA_KEY_ID_USER_MIN <= key_id && key_id <= PSA_KEY_ID_USER_MAX ) |
| 177 | return( 1 ); |
| 178 | else if( vendor_ok && |
| 179 | PSA_KEY_ID_VENDOR_MIN <= key_id && |
| 180 | key_id <= PSA_KEY_ID_VENDOR_MAX ) |
| 181 | return( 1 ); |
| 182 | else |
Gilles Peskine | c8569bc | 2019-02-19 13:04:02 +0100 | [diff] [blame] | 183 | return( 0 ); |
Gilles Peskine | c8569bc | 2019-02-19 13:04:02 +0100 | [diff] [blame] | 184 | } |
Gilles Peskine | 30afafd | 2019-04-25 13:47:40 +0200 | [diff] [blame] | 185 | #endif /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */ |
Gilles Peskine | fa4135b | 2018-12-10 16:48:53 +0100 | [diff] [blame] | 186 | |
Gilles Peskine | d167b94 | 2019-04-19 18:19:40 +0200 | [diff] [blame] | 187 | psa_status_t psa_validate_persistent_key_parameters( |
| 188 | psa_key_lifetime_t lifetime, |
Gilles Peskine | f966659 | 2019-05-06 18:56:30 +0200 | [diff] [blame] | 189 | psa_key_file_id_t id, |
Gilles Peskine | 8abe6a2 | 2019-07-12 23:40:35 +0200 | [diff] [blame] | 190 | psa_se_drv_table_entry_t **p_drv, |
Gilles Peskine | f966659 | 2019-05-06 18:56:30 +0200 | [diff] [blame] | 191 | int creating ) |
Gilles Peskine | d167b94 | 2019-04-19 18:19:40 +0200 | [diff] [blame] | 192 | { |
Gilles Peskine | 011e428 | 2019-06-26 18:34:38 +0200 | [diff] [blame] | 193 | if( p_drv != NULL ) |
| 194 | *p_drv = NULL; |
| 195 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 196 | if( psa_key_lifetime_is_external( lifetime ) ) |
| 197 | { |
| 198 | *p_drv = psa_get_se_driver_entry( lifetime ); |
| 199 | if( *p_drv == NULL ) |
| 200 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 201 | } |
| 202 | else |
| 203 | #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ |
Gilles Peskine | d167b94 | 2019-04-19 18:19:40 +0200 | [diff] [blame] | 204 | if( lifetime != PSA_KEY_LIFETIME_PERSISTENT ) |
| 205 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Gilles Peskine | 30afafd | 2019-04-25 13:47:40 +0200 | [diff] [blame] | 206 | |
| 207 | #if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) |
Gilles Peskine | f966659 | 2019-05-06 18:56:30 +0200 | [diff] [blame] | 208 | if( ! psa_is_key_id_valid( id, ! creating ) ) |
Gilles Peskine | d167b94 | 2019-04-19 18:19:40 +0200 | [diff] [blame] | 209 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 210 | return( PSA_SUCCESS ); |
Gilles Peskine | 30afafd | 2019-04-25 13:47:40 +0200 | [diff] [blame] | 211 | |
| 212 | #else /* MBEDTLS_PSA_CRYPTO_STORAGE_C */ |
| 213 | (void) id; |
Gilles Peskine | e2f62ba | 2019-05-16 00:31:48 +0200 | [diff] [blame] | 214 | (void) creating; |
Gilles Peskine | 30afafd | 2019-04-25 13:47:40 +0200 | [diff] [blame] | 215 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 216 | #endif /* !MBEDTLS_PSA_CRYPTO_STORAGE_C */ |
Gilles Peskine | d167b94 | 2019-04-19 18:19:40 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Gilles Peskine | 70e085a | 2019-05-27 19:04:07 +0200 | [diff] [blame] | 219 | 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] | 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; |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 223 | psa_key_slot_t *slot; |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 224 | |
| 225 | *handle = 0; |
| 226 | |
Gilles Peskine | 70e085a | 2019-05-27 19:04:07 +0200 | [diff] [blame] | 227 | status = psa_validate_persistent_key_parameters( |
Gilles Peskine | 011e428 | 2019-06-26 18:34:38 +0200 | [diff] [blame] | 228 | PSA_KEY_LIFETIME_PERSISTENT, id, NULL, 0 ); |
Gilles Peskine | d167b94 | 2019-04-19 18:19:40 +0200 | [diff] [blame] | 229 | if( status != PSA_SUCCESS ) |
| 230 | return( status ); |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 231 | |
Gilles Peskine | edbed56 | 2019-08-07 18:19:59 +0200 | [diff] [blame] | 232 | status = psa_get_empty_key_slot( handle, &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; |
| 237 | slot->attr.id = id; |
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) */ |
Gilles Peskine | 70e085a | 2019-05-27 19:04:07 +0200 | [diff] [blame] | 248 | (void) id; |
| 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 | { |
Jaeden Amero | 6fa62a5 | 2019-08-20 17:43:48 +0100 | [diff] [blame] | 285 | 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] | 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 | { |
Jaeden Amero | 6fa62a5 | 2019-08-20 17:43:48 +0100 | [diff] [blame] | 292 | 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] | 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 */ |