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 | #ifndef PSA_CRYPTO_SLOT_MANAGEMENT_H |
| 23 | #define PSA_CRYPTO_SLOT_MANAGEMENT_H |
| 24 | |
| 25 | /* Number of key slots (plus one because 0 is not used). |
| 26 | * The value is a compile-time constant for now, for simplicity. */ |
| 27 | #define PSA_KEY_SLOT_COUNT 32 |
| 28 | |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 29 | /** \defgroup core_slot_management Internal functions exposed by the core |
| 30 | * @{ |
| 31 | */ |
| 32 | |
| 33 | /** Find a free key slot and mark it as in use. |
| 34 | * |
| 35 | * \param[out] handle On success, a slot number that is not in use. |
| 36 | * |
| 37 | * \retval #PSA_SUCCESS |
| 38 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 39 | */ |
| 40 | psa_status_t psa_internal_allocate_key_slot( psa_key_handle_t *handle ); |
| 41 | |
| 42 | /** Wipe an a key slot and mark it as available. |
| 43 | * |
| 44 | * This does not affect persistent storage. |
| 45 | * |
| 46 | * \param handle The key slot number to release. |
| 47 | * |
| 48 | * \retval #PSA_SUCCESS |
| 49 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 50 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 51 | */ |
| 52 | psa_status_t psa_internal_release_key_slot( psa_key_handle_t handle ); |
| 53 | |
| 54 | /** Declare a slot as persistent and load it from storage. |
| 55 | * |
| 56 | * This function may only be called immediately after a successful call |
| 57 | * to psa_internal_allocate_key_slot(). |
| 58 | * |
| 59 | * \param handle A handle to a key slot freshly allocated with |
| 60 | * psa_internal_allocate_key_slot(). |
| 61 | * |
| 62 | * \retval #PSA_SUCCESS |
| 63 | * The slot content was loaded successfully. |
| 64 | * \retval #PSA_ERROR_EMPTY_SLOT |
| 65 | * There is no content for this slot in persistent storage. |
| 66 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 67 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 68 | * \p id is not acceptable. |
| 69 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 70 | * \retval #PSA_ERROR_STORAGE_FAILURE |
| 71 | */ |
| 72 | psa_status_t psa_internal_make_key_persistent( psa_key_handle_t handle, |
| 73 | psa_key_id_t id ); |
| 74 | |
| 75 | /**@}*/ |
| 76 | |
| 77 | #endif /* PSA_CRYPTO_SLOT_MANAGEMENT_H */ |