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 | 0982903 | 2018-12-10 17:00:38 +0100 | [diff] [blame] | 29 | /** Access a key slot at the given handle. |
| 30 | * |
| 31 | * \param handle Key handle to query. |
| 32 | * \param[out] p_slot On success, `*p_slot` contains a pointer to the |
| 33 | * key slot in memory designated by \p handle. |
| 34 | * |
| 35 | * \retval PSA_SUCCESS |
| 36 | * Success: \p handle is a handle to `*p_slot`. Note that `*p_slot` |
| 37 | * may be empty or occupied. |
| 38 | * \retval PSA_ERROR_INVALID_HANDLE |
| 39 | * \p handle is out of range or is not in use. |
| 40 | * \retval PSA_ERROR_BAD_STATE |
| 41 | * The library has not been initialized. |
| 42 | */ |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 43 | psa_status_t psa_get_key_slot( psa_key_handle_t handle, |
| 44 | psa_key_slot_t **p_slot ); |
| 45 | |
Gilles Peskine | 0982903 | 2018-12-10 17:00:38 +0100 | [diff] [blame] | 46 | /** Initialize the key slot structures. |
| 47 | * |
| 48 | * \retval PSA_SUCCESS |
| 49 | * Currently this function always succeeds. |
| 50 | */ |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 51 | psa_status_t psa_initialize_key_slots( void ); |
| 52 | |
Gilles Peskine | 0982903 | 2018-12-10 17:00:38 +0100 | [diff] [blame] | 53 | /** Delete all data from key slots in memory. |
| 54 | * |
| 55 | * This does not affect persistent storage. */ |
Gilles Peskine | 66fb126 | 2018-12-10 16:29:04 +0100 | [diff] [blame] | 56 | void psa_wipe_all_key_slots( void ); |
| 57 | |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 58 | /** Find a free key slot and mark it as in use. |
Gilles Peskine | f46f81c | 2019-05-27 14:53:10 +0200 | [diff] [blame] | 59 | * |
Gilles Peskine | bfcae2e | 2019-06-05 11:39:57 +0200 | [diff] [blame^] | 60 | * \param[out] handle On success, a slot number that can be used as a |
| 61 | * handle to the slot. The selected slot was not |
| 62 | * in use before. This function marks it as in use |
| 63 | * and otherwise leaves it in a freshly-initialized |
| 64 | * state. |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 65 | * \param[out] p_slot On success, a pointer to the slot. |
Gilles Peskine | f46f81c | 2019-05-27 14:53:10 +0200 | [diff] [blame] | 66 | * |
| 67 | * \retval #PSA_SUCCESS |
| 68 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 69 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | f46f81c | 2019-05-27 14:53:10 +0200 | [diff] [blame] | 70 | */ |
Gilles Peskine | 267c656 | 2019-05-27 19:01:54 +0200 | [diff] [blame] | 71 | psa_status_t psa_internal_allocate_key_slot( psa_key_handle_t *handle, |
| 72 | psa_key_slot_t **p_slot ); |
Gilles Peskine | f46f81c | 2019-05-27 14:53:10 +0200 | [diff] [blame] | 73 | |
Gilles Peskine | d167b94 | 2019-04-19 18:19:40 +0200 | [diff] [blame] | 74 | /** Test whether the given parameters are acceptable for a persistent key. |
| 75 | * |
| 76 | * This function does not access the storage in any way. It only tests |
| 77 | * whether the parameters are meaningful and permitted by general policy. |
| 78 | * It does not test whether the a file by the given id exists or could be |
| 79 | * created. |
| 80 | * |
| 81 | * \param lifetime The lifetime to test. |
| 82 | * \param id The key id to test. |
Gilles Peskine | f966659 | 2019-05-06 18:56:30 +0200 | [diff] [blame] | 83 | * \param creating 0 if attempting to open an existing key. |
| 84 | * Nonzero if attempting to create a key. |
Gilles Peskine | d167b94 | 2019-04-19 18:19:40 +0200 | [diff] [blame] | 85 | * |
| 86 | * \retval PSA_SUCCESS |
| 87 | * The given parameters are valid. |
| 88 | * \retval PSA_ERROR_INVALID_ARGUMENT |
| 89 | * \p lifetime is volatile or is invalid. |
| 90 | * \retval PSA_ERROR_INVALID_ARGUMENT |
| 91 | * \p id is invalid. |
| 92 | */ |
| 93 | psa_status_t psa_validate_persistent_key_parameters( |
| 94 | psa_key_lifetime_t lifetime, |
Gilles Peskine | f966659 | 2019-05-06 18:56:30 +0200 | [diff] [blame] | 95 | psa_key_file_id_t id, |
| 96 | int creating ); |
Gilles Peskine | d167b94 | 2019-04-19 18:19:40 +0200 | [diff] [blame] | 97 | |
| 98 | |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 99 | #endif /* PSA_CRYPTO_SLOT_MANAGEMENT_H */ |