2018-11-30 18:54:54 +01:00
|
|
|
/*
|
|
|
|
* PSA crypto layer on top of Mbed TLS crypto
|
|
|
|
*/
|
2020-06-15 11:59:37 +02:00
|
|
|
/*
|
2020-08-07 13:07:28 +02:00
|
|
|
* Copyright The Mbed TLS Contributors
|
2018-11-30 18:54:54 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PSA_CRYPTO_SLOT_MANAGEMENT_H
|
|
|
|
#define PSA_CRYPTO_SLOT_MANAGEMENT_H
|
|
|
|
|
2019-06-26 18:34:38 +02:00
|
|
|
#include "psa/crypto.h"
|
|
|
|
#include "psa_crypto_se.h"
|
|
|
|
|
2018-11-30 18:54:54 +01:00
|
|
|
/* Number of key slots (plus one because 0 is not used).
|
|
|
|
* The value is a compile-time constant for now, for simplicity. */
|
|
|
|
#define PSA_KEY_SLOT_COUNT 32
|
|
|
|
|
2020-07-17 14:13:26 +02:00
|
|
|
/** Range of volatile key identifiers.
|
|
|
|
*
|
|
|
|
* The last PSA_KEY_SLOT_COUNT identifiers of the implementation range
|
|
|
|
* of key identifiers are reserved for volatile key identifiers.
|
|
|
|
* A volatile key identifier is equal to PSA_KEY_ID_VOLATILE_MIN plus the
|
|
|
|
* index of the key slot containing the volatile key definition.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** The minimum value for a volatile key identifier.
|
|
|
|
*/
|
|
|
|
#define PSA_KEY_ID_VOLATILE_MIN ( PSA_KEY_ID_VENDOR_MAX - \
|
|
|
|
PSA_KEY_SLOT_COUNT + 1 )
|
|
|
|
|
|
|
|
/** The maximum value for a volatile key identifier.
|
|
|
|
*/
|
|
|
|
#define PSA_KEY_ID_VOLATILE_MAX PSA_KEY_ID_VENDOR_MAX
|
|
|
|
|
2018-12-10 17:00:38 +01:00
|
|
|
/** Access a key slot at the given handle.
|
|
|
|
*
|
|
|
|
* \param handle Key handle to query.
|
|
|
|
* \param[out] p_slot On success, `*p_slot` contains a pointer to the
|
|
|
|
* key slot in memory designated by \p handle.
|
|
|
|
*
|
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
* Success: \p handle is a handle to `*p_slot`. Note that `*p_slot`
|
|
|
|
* may be empty or occupied.
|
|
|
|
* \retval PSA_ERROR_INVALID_HANDLE
|
|
|
|
* \p handle is out of range or is not in use.
|
|
|
|
* \retval PSA_ERROR_BAD_STATE
|
|
|
|
* The library has not been initialized.
|
|
|
|
*/
|
2018-12-10 16:29:04 +01:00
|
|
|
psa_status_t psa_get_key_slot( psa_key_handle_t handle,
|
|
|
|
psa_key_slot_t **p_slot );
|
|
|
|
|
2018-12-10 17:00:38 +01:00
|
|
|
/** Initialize the key slot structures.
|
|
|
|
*
|
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
* Currently this function always succeeds.
|
|
|
|
*/
|
2018-12-10 16:29:04 +01:00
|
|
|
psa_status_t psa_initialize_key_slots( void );
|
|
|
|
|
2018-12-10 17:00:38 +01:00
|
|
|
/** Delete all data from key slots in memory.
|
|
|
|
*
|
|
|
|
* This does not affect persistent storage. */
|
2018-12-10 16:29:04 +01:00
|
|
|
void psa_wipe_all_key_slots( void );
|
|
|
|
|
2019-07-31 15:01:55 +02:00
|
|
|
/** Find a free key slot.
|
|
|
|
*
|
|
|
|
* This function returns a key slot that is available for use and is in its
|
|
|
|
* ground state (all-bits-zero).
|
2019-05-27 14:53:10 +02:00
|
|
|
*
|
2020-07-17 14:13:26 +02:00
|
|
|
* \param[out] handle On success, a slot number that can be used
|
|
|
|
* as a handle to the slot.
|
|
|
|
* \param[out] volatile_key_id On success, volatile key identifier
|
|
|
|
* associated to the returned slot.
|
|
|
|
* \param[out] p_slot On success, a pointer to the slot.
|
2019-05-27 14:53:10 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
2019-05-27 19:01:54 +02:00
|
|
|
* \retval #PSA_ERROR_BAD_STATE
|
2019-05-27 14:53:10 +02:00
|
|
|
*/
|
2019-08-07 18:19:59 +02:00
|
|
|
psa_status_t psa_get_empty_key_slot( psa_key_handle_t *handle,
|
2020-07-17 14:13:26 +02:00
|
|
|
psa_key_id_t *volatile_key_id,
|
2019-08-07 18:19:59 +02:00
|
|
|
psa_key_slot_t **p_slot );
|
2019-05-27 14:53:10 +02:00
|
|
|
|
2019-06-26 18:34:38 +02:00
|
|
|
/** Test whether a lifetime designates a key in an external cryptoprocessor.
|
|
|
|
*
|
|
|
|
* \param lifetime The lifetime to test.
|
|
|
|
*
|
|
|
|
* \retval 1
|
|
|
|
* The lifetime designates an external key. There should be a
|
|
|
|
* registered driver for this lifetime, otherwise the key cannot
|
|
|
|
* be created or manipulated.
|
|
|
|
* \retval 0
|
|
|
|
* The lifetime designates a key that is volatile or in internal
|
|
|
|
* storage.
|
|
|
|
*/
|
|
|
|
static inline int psa_key_lifetime_is_external( psa_key_lifetime_t lifetime )
|
|
|
|
{
|
2020-06-08 18:28:25 +02:00
|
|
|
return( PSA_KEY_LIFETIME_GET_LOCATION( lifetime )
|
|
|
|
!= PSA_KEY_LOCATION_LOCAL_STORAGE );
|
2019-06-26 18:34:38 +02:00
|
|
|
}
|
|
|
|
|
2020-06-17 14:52:05 +02:00
|
|
|
/** Validate a key's location.
|
2019-04-19 18:19:40 +02:00
|
|
|
*
|
2020-06-08 18:37:19 +02:00
|
|
|
* This function checks whether the key's attributes point to a location that
|
|
|
|
* is known to the PSA Core, and returns the driver function table if the key
|
|
|
|
* is to be found in an external location.
|
2019-04-19 18:19:40 +02:00
|
|
|
*
|
2020-06-17 14:52:05 +02:00
|
|
|
* \param[in] lifetime The key lifetime attribute.
|
2020-06-08 18:37:19 +02:00
|
|
|
* \param[out] p_drv On success, when a key is located in external
|
|
|
|
* storage, returns a pointer to the driver table
|
|
|
|
* associated with the key's storage location.
|
2019-06-26 18:34:38 +02:00
|
|
|
*
|
2020-06-08 18:37:19 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
*/
|
2020-06-17 14:52:05 +02:00
|
|
|
psa_status_t psa_validate_key_location( psa_key_lifetime_t lifetime,
|
2020-06-08 18:37:19 +02:00
|
|
|
psa_se_drv_table_entry_t **p_drv );
|
|
|
|
|
2020-07-17 16:11:30 +02:00
|
|
|
/** Validate the persistence of a key.
|
2020-06-08 18:37:19 +02:00
|
|
|
*
|
2020-07-23 12:30:41 +02:00
|
|
|
* \param[in] lifetime The key lifetime attribute.
|
2020-06-08 18:37:19 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
2020-07-17 16:11:30 +02:00
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT The key is persistent but persistent
|
|
|
|
* keys are not supported.
|
|
|
|
*/
|
|
|
|
psa_status_t psa_validate_key_persistence( psa_key_lifetime_t lifetime );
|
|
|
|
|
|
|
|
/** Validate a key identifier.
|
|
|
|
*
|
|
|
|
* \param[in] key The key identifier.
|
|
|
|
* \param[in] vendor_ok Non-zero to indicate that key identifiers in the
|
|
|
|
* vendor range are allowed, \c 0 otherwise.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS The identifier is valid.
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT The key identifier is not valid.
|
2019-04-19 18:19:40 +02:00
|
|
|
*/
|
2020-07-17 16:11:30 +02:00
|
|
|
psa_status_t psa_validate_key_id( mbedtls_svc_key_id_t key, int vendor_ok );
|
2019-04-19 18:19:40 +02:00
|
|
|
|
2018-11-30 18:54:54 +01:00
|
|
|
#endif /* PSA_CRYPTO_SLOT_MANAGEMENT_H */
|