2018-10-15 23:14:24 +02:00
|
|
|
/**
|
2018-12-12 15:55:09 +01:00
|
|
|
* \file psa/crypto_se_driver.h
|
|
|
|
* \brief PSA external cryptoprocessor driver module
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-12-12 15:55:09 +01:00
|
|
|
* This header declares types and function signatures for cryptography
|
2019-02-16 00:23:42 +01:00
|
|
|
* drivers that access key material via opaque references.
|
|
|
|
* This is meant for cryptoprocessors that have a separate key storage from the
|
2018-12-12 15:55:09 +01:00
|
|
|
* space in which the PSA Crypto implementation runs, typically secure
|
2019-02-16 00:23:42 +01:00
|
|
|
* elements (SEs).
|
2018-12-12 15:55:09 +01:00
|
|
|
*
|
2019-06-24 13:46:37 +02:00
|
|
|
* This file is part of the PSA Crypto Driver HAL (hardware abstraction layer),
|
|
|
|
* containing functions for driver developers to implement to enable hardware
|
|
|
|
* to be called in a standardized way by a PSA Cryptography API
|
|
|
|
* implementation. The functions comprising the driver HAL, which driver
|
|
|
|
* authors implement, are not intended to be called by application developers.
|
2018-10-15 23:14:24 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2018, ARM Limited, All Rights Reserved
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-12-12 15:55:09 +01:00
|
|
|
#ifndef PSA_CRYPTO_SE_DRIVER_H
|
|
|
|
#define PSA_CRYPTO_SE_DRIVER_H
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2018-12-12 15:55:09 +01:00
|
|
|
#include "crypto_driver_common.h"
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2018-10-26 12:59:58 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-07-12 23:25:38 +02:00
|
|
|
/** \defgroup se_init Secure element driver initialization
|
|
|
|
*/
|
|
|
|
/**@{*/
|
|
|
|
|
|
|
|
/** \brief Driver context structure
|
|
|
|
*
|
|
|
|
* Driver functions receive a pointer to this structure.
|
|
|
|
* Each registered driver has one instance of this structure.
|
|
|
|
*
|
|
|
|
* Implementations must include the fields specified here and
|
|
|
|
* may include other fields.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/** A read-only pointer to the driver's persistent data.
|
|
|
|
*
|
2019-07-25 14:04:38 +02:00
|
|
|
* Drivers typically use this persistent data to keep track of
|
|
|
|
* which slot numbers are available. This is only a guideline:
|
|
|
|
* drivers may use the persistent data for any purpose, keeping
|
|
|
|
* in mind the restrictions on when the persistent data is saved
|
|
|
|
* to storage: the persistent data is only saved after calling
|
|
|
|
* certain functions that receive a writable pointer to the
|
|
|
|
* persistent data.
|
2019-07-12 23:25:38 +02:00
|
|
|
*
|
|
|
|
* The core allocates a memory buffer for the persistent data.
|
2019-07-25 10:56:39 +02:00
|
|
|
* The pointer is guaranteed to be suitably aligned for any data type,
|
2019-07-12 23:25:38 +02:00
|
|
|
* like a pointer returned by `malloc` (but the core can use any
|
|
|
|
* method to allocate the buffer, not necessarily `malloc`).
|
|
|
|
*
|
2019-07-23 18:26:43 +02:00
|
|
|
* The size of this buffer is in the \c persistent_data_size field of
|
|
|
|
* this structure.
|
2019-07-12 23:25:38 +02:00
|
|
|
*
|
|
|
|
* Before the driver is initialized for the first time, the content of
|
|
|
|
* the persistent data is all-bits-zero. After a driver upgrade, if the
|
|
|
|
* size of the persistent data has increased, the original data is padded
|
|
|
|
* on the right with zeros; if the size has decreased, the original data
|
|
|
|
* is truncated to the new size.
|
|
|
|
*
|
|
|
|
* This pointer is to read-only data. Only a few driver functions are
|
|
|
|
* allowed to modify the persistent data. These functions receive a
|
2019-07-25 14:04:38 +02:00
|
|
|
* writable pointer. These functions are:
|
|
|
|
* - psa_drv_se_t::p_init
|
|
|
|
* - psa_drv_se_key_management_t::p_allocate
|
|
|
|
* - psa_drv_se_key_management_t::p_destroy
|
|
|
|
*
|
|
|
|
* The PSA Cryptography core saves the persistent data from one
|
|
|
|
* session to the next. It does this before returning from API functions
|
|
|
|
* that call a driver method that is allowed to modify the persistent
|
|
|
|
* data, specifically:
|
|
|
|
* - psa_crypto_init() causes a call to psa_drv_se_t::p_init, and may call
|
|
|
|
* psa_drv_se_key_management_t::p_destroy to complete an action
|
|
|
|
* that was interrupted by a power failure.
|
|
|
|
* - Key creation functions cause a call to
|
|
|
|
* psa_drv_se_key_management_t::p_allocate, and may cause a call to
|
|
|
|
* psa_drv_se_key_management_t::p_destroy in case an error occurs.
|
|
|
|
* - psa_destroy_key() causes a call to
|
|
|
|
* psa_drv_se_key_management_t::p_destroy.
|
2019-07-12 23:25:38 +02:00
|
|
|
*/
|
|
|
|
const void *const persistent_data;
|
|
|
|
|
|
|
|
/** The size of \c persistent_data in bytes.
|
|
|
|
*
|
2019-07-23 18:26:43 +02:00
|
|
|
* This is always equal to the value of the `persistent_data_size` field
|
|
|
|
* of the ::psa_drv_se_t structure when the driver is registered.
|
2019-07-12 23:25:38 +02:00
|
|
|
*/
|
|
|
|
const size_t persistent_data_size;
|
|
|
|
|
|
|
|
/** Driver transient data.
|
|
|
|
*
|
|
|
|
* The core initializes this value to 0 and does not read or modify it
|
|
|
|
* afterwards. The driver may store whatever it wants in this field.
|
|
|
|
*/
|
|
|
|
uintptr_t transient_data;
|
|
|
|
} psa_drv_se_context_t;
|
|
|
|
|
|
|
|
/** \brief A driver initialization function.
|
|
|
|
*
|
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2019-07-12 23:34:20 +02:00
|
|
|
* \param[in,out] persistent_data A pointer to the persistent data
|
|
|
|
* that allows writing.
|
2020-05-10 00:39:18 +02:00
|
|
|
* \param location The location value for which this driver
|
|
|
|
* is registered. The driver will be invoked
|
|
|
|
* for all keys whose lifetime is in this
|
|
|
|
* location.
|
2019-07-12 23:25:38 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The driver is operational.
|
|
|
|
* The core will update the persistent data in storage.
|
|
|
|
* \return
|
|
|
|
* Any other return value prevents the driver from being used in
|
|
|
|
* this session.
|
|
|
|
* The core will NOT update the persistent data in storage.
|
|
|
|
*/
|
|
|
|
typedef psa_status_t (*psa_drv_se_init_t)(psa_drv_se_context_t *drv_context,
|
2019-07-12 23:34:20 +02:00
|
|
|
void *persistent_data,
|
2020-05-10 00:39:18 +02:00
|
|
|
psa_key_location_t location);
|
2019-07-12 23:25:38 +02:00
|
|
|
|
2019-08-02 20:15:51 +02:00
|
|
|
#if defined(__DOXYGEN_ONLY__) || !defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
|
|
|
/* Mbed Crypto with secure element support enabled defines this type in
|
|
|
|
* crypto_types.h because it is also visible to applications through an
|
|
|
|
* implementation-specific extension.
|
|
|
|
* For the PSA Cryptography specification, this type is only visible
|
|
|
|
* via crypto_se_driver.h. */
|
2018-12-12 13:51:19 +01:00
|
|
|
/** An internal designation of a key slot between the core part of the
|
|
|
|
* PSA Crypto implementation and the driver. The meaning of this value
|
|
|
|
* is driver-dependent. */
|
2019-07-12 23:18:29 +02:00
|
|
|
typedef uint64_t psa_key_slot_number_t;
|
2019-08-02 20:15:51 +02:00
|
|
|
#endif /* __DOXYGEN_ONLY__ || !MBEDTLS_PSA_CRYPTO_SE_C */
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-07-12 23:25:38 +02:00
|
|
|
/**@}*/
|
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \defgroup se_mac Secure Element Message Authentication Codes
|
2018-10-22 22:27:27 +02:00
|
|
|
* Generation and authentication of Message Authentication Codes (MACs) using
|
2019-02-16 00:23:42 +01:00
|
|
|
* a secure element can be done either as a single function call (via the
|
|
|
|
* `psa_drv_se_mac_generate_t` or `psa_drv_se_mac_verify_t` functions), or in
|
2018-10-22 22:27:27 +02:00
|
|
|
* parts using the following sequence:
|
2019-02-16 00:23:42 +01:00
|
|
|
* - `psa_drv_se_mac_setup_t`
|
|
|
|
* - `psa_drv_se_mac_update_t`
|
|
|
|
* - `psa_drv_se_mac_update_t`
|
2018-10-22 22:27:27 +02:00
|
|
|
* - ...
|
2019-02-16 00:23:42 +01:00
|
|
|
* - `psa_drv_se_mac_finish_t` or `psa_drv_se_mac_finish_verify_t`
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-02-16 00:23:42 +01:00
|
|
|
* If a previously started secure element MAC operation needs to be terminated,
|
|
|
|
* it should be done so by the `psa_drv_se_mac_abort_t`. Failure to do so may
|
2018-10-22 22:27:27 +02:00
|
|
|
* result in allocated resources not being freed or in other undefined
|
|
|
|
* behavior.
|
2018-10-11 00:55:03 +02:00
|
|
|
*/
|
2018-10-15 23:14:24 +02:00
|
|
|
/**@{*/
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that starts a secure element MAC operation for a PSA
|
|
|
|
* Crypto Driver implementation
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
|
|
|
* \param[in,out] op_context A structure that will contain the
|
2018-10-15 23:14:24 +02:00
|
|
|
* hardware-specific MAC context
|
|
|
|
* \param[in] key_slot The slot of the key to be used for the
|
|
|
|
* operation
|
2018-10-26 11:07:32 +02:00
|
|
|
* \param[in] algorithm The algorithm to be used to underly the MAC
|
2018-10-15 23:14:24 +02:00
|
|
|
* operation
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
* Success.
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_mac_setup_t)(psa_drv_se_context_t *drv_context,
|
|
|
|
void *op_context,
|
2019-02-16 00:03:42 +01:00
|
|
|
psa_key_slot_number_t key_slot,
|
2019-02-15 23:41:22 +01:00
|
|
|
psa_algorithm_t algorithm);
|
2018-10-15 23:14:24 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that continues a previously started secure element MAC
|
|
|
|
* operation
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] op_context A hardware-specific structure for the
|
2018-10-15 23:14:24 +02:00
|
|
|
* previously-established MAC operation to be
|
2019-02-16 00:23:42 +01:00
|
|
|
* updated
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] p_input A buffer containing the message to be appended
|
|
|
|
* to the MAC operation
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in] input_length The size in bytes of the input message buffer
|
2018-10-15 23:14:24 +02:00
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_mac_update_t)(void *op_context,
|
2019-02-15 23:41:22 +01:00
|
|
|
const uint8_t *p_input,
|
|
|
|
size_t input_length);
|
2018-10-15 23:14:24 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief a function that completes a previously started secure element MAC
|
|
|
|
* operation by returning the resulting MAC.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] op_context A hardware-specific structure for the
|
2018-10-26 11:07:32 +02:00
|
|
|
* previously started MAC operation to be
|
2018-10-15 23:14:24 +02:00
|
|
|
* finished
|
|
|
|
* \param[out] p_mac A buffer where the generated MAC will be
|
|
|
|
* placed
|
|
|
|
* \param[in] mac_size The size in bytes of the buffer that has been
|
|
|
|
* allocated for the `output` buffer
|
|
|
|
* \param[out] p_mac_length After completion, will contain the number of
|
2018-10-18 23:41:08 +02:00
|
|
|
* bytes placed in the `p_mac` buffer
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
* Success.
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_mac_finish_t)(void *op_context,
|
2019-02-15 23:41:22 +01:00
|
|
|
uint8_t *p_mac,
|
|
|
|
size_t mac_size,
|
|
|
|
size_t *p_mac_length);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that completes a previously started secure element MAC
|
|
|
|
* operation by comparing the resulting MAC against a provided value
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] op_context A hardware-specific structure for the previously
|
2019-07-25 10:56:39 +02:00
|
|
|
* started MAC operation to be fiinished
|
|
|
|
* \param[in] p_mac The MAC value against which the resulting MAC
|
|
|
|
* will be compared against
|
|
|
|
* \param[in] mac_length The size in bytes of the value stored in `p_mac`
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
2018-10-15 23:14:24 +02:00
|
|
|
* The operation completed successfully and the MACs matched each
|
|
|
|
* other
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_ERROR_INVALID_SIGNATURE
|
2018-10-15 23:14:24 +02:00
|
|
|
* The operation completed successfully, but the calculated MAC did
|
|
|
|
* not match the provided MAC
|
2018-10-11 00:55:03 +02:00
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_mac_finish_verify_t)(void *op_context,
|
2019-02-15 23:41:22 +01:00
|
|
|
const uint8_t *p_mac,
|
|
|
|
size_t mac_length);
|
2018-10-15 23:14:24 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that aborts a previous started secure element MAC
|
|
|
|
* operation
|
2019-03-06 18:29:57 +01:00
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] op_context A hardware-specific structure for the previously
|
2019-07-25 10:56:39 +02:00
|
|
|
* started MAC operation to be aborted
|
2018-10-15 23:14:24 +02:00
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_mac_abort_t)(void *op_context);
|
2018-10-15 23:14:24 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that performs a secure element MAC operation in one
|
|
|
|
* command and returns the calculated MAC
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] p_input A buffer containing the message to be MACed
|
2018-10-18 23:41:08 +02:00
|
|
|
* \param[in] input_length The size in bytes of `p_input`
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] key_slot The slot of the key to be used
|
2018-10-18 23:41:08 +02:00
|
|
|
* \param[in] alg The algorithm to be used to underlie the MAC
|
2018-10-15 23:14:24 +02:00
|
|
|
* operation
|
|
|
|
* \param[out] p_mac A buffer where the generated MAC will be
|
|
|
|
* placed
|
2018-10-23 21:55:32 +02:00
|
|
|
* \param[in] mac_size The size in bytes of the `p_mac` buffer
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[out] p_mac_length After completion, will contain the number of
|
|
|
|
* bytes placed in the `output` buffer
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
* Success.
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_mac_generate_t)(psa_drv_se_context_t *drv_context,
|
|
|
|
const uint8_t *p_input,
|
2019-02-15 23:41:22 +01:00
|
|
|
size_t input_length,
|
2019-02-16 00:03:42 +01:00
|
|
|
psa_key_slot_number_t key_slot,
|
2019-02-15 23:41:22 +01:00
|
|
|
psa_algorithm_t alg,
|
|
|
|
uint8_t *p_mac,
|
|
|
|
size_t mac_size,
|
|
|
|
size_t *p_mac_length);
|
2018-10-15 23:14:24 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that performs a secure element MAC operation in one
|
|
|
|
* command and compares the resulting MAC against a provided value
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] p_input A buffer containing the message to be MACed
|
|
|
|
* \param[in] input_length The size in bytes of `input`
|
|
|
|
* \param[in] key_slot The slot of the key to be used
|
|
|
|
* \param[in] alg The algorithm to be used to underlie the MAC
|
|
|
|
* operation
|
|
|
|
* \param[in] p_mac The MAC value against which the resulting MAC will
|
|
|
|
* be compared against
|
|
|
|
* \param[in] mac_length The size in bytes of `mac`
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
2018-10-15 23:14:24 +02:00
|
|
|
* The operation completed successfully and the MACs matched each
|
|
|
|
* other
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_ERROR_INVALID_SIGNATURE
|
2018-10-15 23:14:24 +02:00
|
|
|
* The operation completed successfully, but the calculated MAC did
|
|
|
|
* not match the provided MAC
|
2018-10-11 00:55:03 +02:00
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_mac_verify_t)(psa_drv_se_context_t *drv_context,
|
|
|
|
const uint8_t *p_input,
|
2019-02-15 23:41:22 +01:00
|
|
|
size_t input_length,
|
2019-02-16 00:03:42 +01:00
|
|
|
psa_key_slot_number_t key_slot,
|
2019-02-15 23:41:22 +01:00
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *p_mac,
|
|
|
|
size_t mac_length);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2018-10-15 23:14:24 +02:00
|
|
|
/** \brief A struct containing all of the function pointers needed to
|
2019-02-16 00:23:42 +01:00
|
|
|
* perform secure element MAC operations
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* PSA Crypto API implementations should populate the table as appropriate
|
|
|
|
* upon startup.
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
2018-10-22 22:27:27 +02:00
|
|
|
* If one of the functions is not implemented (such as
|
2019-02-16 00:23:42 +01:00
|
|
|
* `psa_drv_se_mac_generate_t`), it should be set to NULL.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* Driver implementers should ensure that they implement all of the functions
|
|
|
|
* that make sense for their hardware, and that they provide a full solution
|
|
|
|
* (for example, if they support `p_setup`, they should also support
|
|
|
|
* `p_update` and at least one of `p_finish` or `p_finish_verify`).
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
*/
|
2018-10-26 12:57:26 +02:00
|
|
|
typedef struct {
|
2019-02-16 00:23:42 +01:00
|
|
|
/**The size in bytes of the hardware-specific secure element MAC context
|
|
|
|
* structure
|
2018-10-15 23:14:24 +02:00
|
|
|
*/
|
2019-02-16 00:23:42 +01:00
|
|
|
size_t context_size;
|
|
|
|
/** Function that performs a MAC setup operation
|
2018-10-15 23:14:24 +02:00
|
|
|
*/
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_mac_setup_t p_setup;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs a MAC update operation
|
2018-10-15 23:14:24 +02:00
|
|
|
*/
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_mac_update_t p_update;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that completes a MAC operation
|
2018-10-15 23:14:24 +02:00
|
|
|
*/
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_mac_finish_t p_finish;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that completes a MAC operation with a verify check
|
2018-10-15 23:14:24 +02:00
|
|
|
*/
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_mac_finish_verify_t p_finish_verify;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that aborts a previoustly started MAC operation
|
2018-10-15 23:14:24 +02:00
|
|
|
*/
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_mac_abort_t p_abort;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs a MAC operation in one call
|
2018-10-15 23:14:24 +02:00
|
|
|
*/
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_mac_generate_t p_mac;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs a MAC and verify operation in one call
|
2018-10-15 23:14:24 +02:00
|
|
|
*/
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_mac_verify_t p_mac_verify;
|
2019-02-15 23:41:22 +01:00
|
|
|
} psa_drv_se_mac_t;
|
2018-10-15 23:14:24 +02:00
|
|
|
/**@}*/
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \defgroup se_cipher Secure Element Symmetric Ciphers
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-02-16 00:23:42 +01:00
|
|
|
* Encryption and Decryption using secure element keys in block modes other
|
|
|
|
* than ECB must be done in multiple parts, using the following flow:
|
|
|
|
* - `psa_drv_se_cipher_setup_t`
|
|
|
|
* - `psa_drv_se_cipher_set_iv_t` (optional depending upon block mode)
|
|
|
|
* - `psa_drv_se_cipher_update_t`
|
|
|
|
* - `psa_drv_se_cipher_update_t`
|
2018-10-22 22:27:27 +02:00
|
|
|
* - ...
|
2019-02-16 00:23:42 +01:00
|
|
|
* - `psa_drv_se_cipher_finish_t`
|
2019-03-06 18:29:57 +01:00
|
|
|
*
|
2019-02-16 00:23:42 +01:00
|
|
|
* If a previously started secure element Cipher operation needs to be
|
|
|
|
* terminated, it should be done so by the `psa_drv_se_cipher_abort_t`. Failure
|
|
|
|
* to do so may result in allocated resources not being freed or in other
|
|
|
|
* undefined behavior.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-22 22:27:27 +02:00
|
|
|
* In situations where a PSA Cryptographic API implementation is using a block
|
|
|
|
* mode not-supported by the underlying hardware or driver, it can construct
|
2019-02-16 00:23:42 +01:00
|
|
|
* the block mode itself, while calling the `psa_drv_se_cipher_ecb_t` function
|
|
|
|
* for the cipher operations.
|
2018-10-11 00:55:03 +02:00
|
|
|
*/
|
2018-10-15 23:14:24 +02:00
|
|
|
/**@{*/
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that provides the cipher setup function for a
|
|
|
|
* secure element driver
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] op_context A structure that will contain the
|
2018-10-15 23:14:24 +02:00
|
|
|
* hardware-specific cipher context.
|
|
|
|
* \param[in] key_slot The slot of the key to be used for the
|
|
|
|
* operation
|
|
|
|
* \param[in] algorithm The algorithm to be used in the cipher
|
|
|
|
* operation
|
|
|
|
* \param[in] direction Indicates whether the operation is an encrypt
|
|
|
|
* or decrypt
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
* \retval PSA_ERROR_NOT_SUPPORTED
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_cipher_setup_t)(psa_drv_se_context_t *drv_context,
|
|
|
|
void *op_context,
|
2019-02-16 00:03:42 +01:00
|
|
|
psa_key_slot_number_t key_slot,
|
2019-02-15 23:41:22 +01:00
|
|
|
psa_algorithm_t algorithm,
|
|
|
|
psa_encrypt_or_decrypt_t direction);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that sets the initialization vector (if
|
|
|
|
* necessary) for an secure element cipher operation
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-02-16 00:23:42 +01:00
|
|
|
* Rationale: The `psa_se_cipher_*` operation in the PSA Cryptographic API has
|
|
|
|
* two IV functions: one to set the IV, and one to generate it internally. The
|
2018-10-26 13:09:31 +02:00
|
|
|
* generate function is not necessary for the drivers to implement as the PSA
|
|
|
|
* Crypto implementation can do the generation using its RNG features.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] op_context A structure that contains the previously set up
|
2018-10-15 23:14:24 +02:00
|
|
|
* hardware-specific cipher context
|
|
|
|
* \param[in] p_iv A buffer containing the initialization vector
|
|
|
|
* \param[in] iv_length The size (in bytes) of the `p_iv` buffer
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_cipher_set_iv_t)(void *op_context,
|
2019-02-15 23:41:22 +01:00
|
|
|
const uint8_t *p_iv,
|
|
|
|
size_t iv_length);
|
2018-10-15 23:14:24 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that continues a previously started secure element cipher
|
2018-10-15 23:14:24 +02:00
|
|
|
* operation
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] op_context A hardware-specific structure for the
|
2018-10-15 23:14:24 +02:00
|
|
|
* previously started cipher operation
|
|
|
|
* \param[in] p_input A buffer containing the data to be
|
|
|
|
* encrypted/decrypted
|
|
|
|
* \param[in] input_size The size in bytes of the buffer pointed to
|
|
|
|
* by `p_input`
|
|
|
|
* \param[out] p_output The caller-allocated buffer where the
|
|
|
|
* output will be placed
|
|
|
|
* \param[in] output_size The allocated size in bytes of the
|
|
|
|
* `p_output` buffer
|
|
|
|
* \param[out] p_output_length After completion, will contain the number
|
|
|
|
* of bytes placed in the `p_output` buffer
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_cipher_update_t)(void *op_context,
|
2019-02-15 23:41:22 +01:00
|
|
|
const uint8_t *p_input,
|
|
|
|
size_t input_size,
|
|
|
|
uint8_t *p_output,
|
|
|
|
size_t output_size,
|
|
|
|
size_t *p_output_length);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that completes a previously started secure element cipher
|
2018-10-15 23:14:24 +02:00
|
|
|
* operation
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] op_context A hardware-specific structure for the
|
2018-10-15 23:14:24 +02:00
|
|
|
* previously started cipher operation
|
2018-10-18 23:41:08 +02:00
|
|
|
* \param[out] p_output The caller-allocated buffer where the output
|
2018-10-15 23:14:24 +02:00
|
|
|
* will be placed
|
|
|
|
* \param[in] output_size The allocated size in bytes of the `p_output`
|
|
|
|
* buffer
|
|
|
|
* \param[out] p_output_length After completion, will contain the number of
|
|
|
|
* bytes placed in the `p_output` buffer
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_cipher_finish_t)(void *op_context,
|
2019-02-15 23:41:22 +01:00
|
|
|
uint8_t *p_output,
|
|
|
|
size_t output_size,
|
|
|
|
size_t *p_output_length);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that aborts a previously started secure element cipher
|
2018-10-15 23:14:24 +02:00
|
|
|
* operation
|
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] op_context A hardware-specific structure for the
|
2018-10-15 23:14:24 +02:00
|
|
|
* previously started cipher operation
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_cipher_abort_t)(void *op_context);
|
2018-10-15 23:14:24 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that performs the ECB block mode for secure element
|
|
|
|
* cipher operations
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* Note: this function should only be used with implementations that do not
|
|
|
|
* provide a needed higher-level operation.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
|
|
|
* \param[in] key_slot The slot of the key to be used for the operation
|
|
|
|
* \param[in] algorithm The algorithm to be used in the cipher operation
|
|
|
|
* \param[in] direction Indicates whether the operation is an encrypt or
|
|
|
|
* decrypt
|
|
|
|
* \param[in] p_input A buffer containing the data to be
|
|
|
|
* encrypted/decrypted
|
|
|
|
* \param[in] input_size The size in bytes of the buffer pointed to by
|
|
|
|
* `p_input`
|
|
|
|
* \param[out] p_output The caller-allocated buffer where the output
|
|
|
|
* will be placed
|
|
|
|
* \param[in] output_size The allocated size in bytes of the `p_output`
|
|
|
|
* buffer
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
* \retval PSA_ERROR_NOT_SUPPORTED
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_cipher_ecb_t)(psa_drv_se_context_t *drv_context,
|
|
|
|
psa_key_slot_number_t key_slot,
|
2019-02-15 23:41:22 +01:00
|
|
|
psa_algorithm_t algorithm,
|
|
|
|
psa_encrypt_or_decrypt_t direction,
|
|
|
|
const uint8_t *p_input,
|
|
|
|
size_t input_size,
|
|
|
|
uint8_t *p_output,
|
|
|
|
size_t output_size);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
|
|
|
/**
|
2018-10-15 23:14:24 +02:00
|
|
|
* \brief A struct containing all of the function pointers needed to implement
|
2019-02-16 00:23:42 +01:00
|
|
|
* cipher operations using secure elements.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* PSA Crypto API implementations should populate instances of the table as
|
2019-02-16 00:23:42 +01:00
|
|
|
* appropriate upon startup or at build time.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* If one of the functions is not implemented (such as
|
2019-02-16 00:23:42 +01:00
|
|
|
* `psa_drv_se_cipher_ecb_t`), it should be set to NULL.
|
2018-10-11 00:55:03 +02:00
|
|
|
*/
|
2018-10-26 12:57:26 +02:00
|
|
|
typedef struct {
|
2019-02-16 00:23:42 +01:00
|
|
|
/** The size in bytes of the hardware-specific secure element cipher
|
|
|
|
* context structure
|
2018-10-15 23:14:24 +02:00
|
|
|
*/
|
2019-02-16 00:13:54 +01:00
|
|
|
size_t context_size;
|
|
|
|
/** Function that performs a cipher setup operation */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_cipher_setup_t p_setup;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that sets a cipher IV (if necessary) */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_cipher_set_iv_t p_set_iv;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs a cipher update operation */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_cipher_update_t p_update;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that completes a cipher operation */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_cipher_finish_t p_finish;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that aborts a cipher operation */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_cipher_abort_t p_abort;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs ECB mode for a cipher operation
|
2018-10-15 23:14:24 +02:00
|
|
|
* (Danger: ECB mode should not be used directly by clients of the PSA
|
|
|
|
* Crypto Client API)
|
|
|
|
*/
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_cipher_ecb_t p_ecb;
|
2019-02-15 23:41:22 +01:00
|
|
|
} psa_drv_se_cipher_t;
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2018-10-15 23:14:24 +02:00
|
|
|
/**@}*/
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \defgroup se_asymmetric Secure Element Asymmetric Cryptography
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-22 22:27:27 +02:00
|
|
|
* Since the amount of data that can (or should) be encrypted or signed using
|
|
|
|
* asymmetric keys is limited by the key size, asymmetric key operations using
|
2019-02-16 00:23:42 +01:00
|
|
|
* keys in a secure element must be done in single function calls.
|
2018-10-11 00:55:03 +02:00
|
|
|
*/
|
2018-10-15 23:14:24 +02:00
|
|
|
/**@{*/
|
2018-10-11 00:55:03 +02:00
|
|
|
|
|
|
|
/**
|
2019-02-16 00:23:42 +01:00
|
|
|
* \brief A function that signs a hash or short message with a private key in
|
|
|
|
* a secure element
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] key_slot Key slot of an asymmetric key pair
|
|
|
|
* \param[in] alg A signature algorithm that is compatible
|
|
|
|
* with the type of `key`
|
2018-10-22 22:27:27 +02:00
|
|
|
* \param[in] p_hash The hash to sign
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] hash_length Size of the `p_hash` buffer in bytes
|
|
|
|
* \param[out] p_signature Buffer where the signature is to be written
|
2018-10-18 23:41:08 +02:00
|
|
|
* \param[in] signature_size Size of the `p_signature` buffer in bytes
|
2018-10-11 00:55:03 +02:00
|
|
|
* \param[out] p_signature_length On success, the number of bytes
|
2018-10-15 23:14:24 +02:00
|
|
|
* that make up the returned signature value
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_asymmetric_sign_t)(psa_drv_se_context_t *drv_context,
|
|
|
|
psa_key_slot_number_t key_slot,
|
2019-02-15 23:41:22 +01:00
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *p_hash,
|
|
|
|
size_t hash_length,
|
|
|
|
uint8_t *p_signature,
|
|
|
|
size_t signature_size,
|
|
|
|
size_t *p_signature_length);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
|
|
|
/**
|
2018-10-15 23:14:24 +02:00
|
|
|
* \brief A function that verifies the signature a hash or short message using
|
2019-02-16 00:23:42 +01:00
|
|
|
* an asymmetric public key in a secure element
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] key_slot Key slot of a public key or an asymmetric key
|
|
|
|
* pair
|
|
|
|
* \param[in] alg A signature algorithm that is compatible with
|
|
|
|
* the type of `key`
|
2018-10-22 22:27:27 +02:00
|
|
|
* \param[in] p_hash The hash whose signature is to be verified
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] hash_length Size of the `p_hash` buffer in bytes
|
|
|
|
* \param[in] p_signature Buffer containing the signature to verify
|
|
|
|
* \param[in] signature_length Size of the `p_signature` buffer in bytes
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
* The signature is valid.
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_asymmetric_verify_t)(psa_drv_se_context_t *drv_context,
|
|
|
|
psa_key_slot_number_t key_slot,
|
2019-02-15 23:41:22 +01:00
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *p_hash,
|
|
|
|
size_t hash_length,
|
|
|
|
const uint8_t *p_signature,
|
|
|
|
size_t signature_length);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
|
|
|
/**
|
2018-10-22 22:27:27 +02:00
|
|
|
* \brief A function that encrypts a short message with an asymmetric public
|
2019-02-16 00:23:42 +01:00
|
|
|
* key in a secure element
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] key_slot Key slot of a public key or an asymmetric key
|
|
|
|
* pair
|
|
|
|
* \param[in] alg An asymmetric encryption algorithm that is
|
|
|
|
* compatible with the type of `key`
|
|
|
|
* \param[in] p_input The message to encrypt
|
|
|
|
* \param[in] input_length Size of the `p_input` buffer in bytes
|
2018-10-11 00:55:03 +02:00
|
|
|
* \param[in] p_salt A salt or label, if supported by the
|
2018-10-15 23:14:24 +02:00
|
|
|
* encryption algorithm
|
2018-10-11 00:55:03 +02:00
|
|
|
* If the algorithm does not support a
|
|
|
|
* salt, pass `NULL`.
|
|
|
|
* If the algorithm supports an optional
|
|
|
|
* salt and you do not want to pass a salt,
|
|
|
|
* pass `NULL`.
|
2018-10-15 23:14:24 +02:00
|
|
|
* For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
|
|
|
|
* supported.
|
|
|
|
* \param[in] salt_length Size of the `p_salt` buffer in bytes
|
2018-10-11 00:55:03 +02:00
|
|
|
* If `p_salt` is `NULL`, pass 0.
|
|
|
|
* \param[out] p_output Buffer where the encrypted message is to
|
2018-10-15 23:14:24 +02:00
|
|
|
* be written
|
|
|
|
* \param[in] output_size Size of the `p_output` buffer in bytes
|
|
|
|
* \param[out] p_output_length On success, the number of bytes that make up
|
|
|
|
* the returned output
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_asymmetric_encrypt_t)(psa_drv_se_context_t *drv_context,
|
|
|
|
psa_key_slot_number_t key_slot,
|
2019-02-15 23:41:22 +01:00
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *p_input,
|
|
|
|
size_t input_length,
|
|
|
|
const uint8_t *p_salt,
|
|
|
|
size_t salt_length,
|
|
|
|
uint8_t *p_output,
|
|
|
|
size_t output_size,
|
|
|
|
size_t *p_output_length);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
|
|
|
/**
|
2019-02-16 00:23:42 +01:00
|
|
|
* \brief A function that decrypts a short message with an asymmetric private
|
|
|
|
* key in a secure element.
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] key_slot Key slot of an asymmetric key pair
|
|
|
|
* \param[in] alg An asymmetric encryption algorithm that is
|
|
|
|
* compatible with the type of `key`
|
|
|
|
* \param[in] p_input The message to decrypt
|
|
|
|
* \param[in] input_length Size of the `p_input` buffer in bytes
|
2018-10-11 00:55:03 +02:00
|
|
|
* \param[in] p_salt A salt or label, if supported by the
|
2018-10-15 23:14:24 +02:00
|
|
|
* encryption algorithm
|
2018-10-11 00:55:03 +02:00
|
|
|
* If the algorithm does not support a
|
|
|
|
* salt, pass `NULL`.
|
|
|
|
* If the algorithm supports an optional
|
|
|
|
* salt and you do not want to pass a salt,
|
|
|
|
* pass `NULL`.
|
2018-10-15 23:14:24 +02:00
|
|
|
* For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
|
|
|
|
* supported.
|
|
|
|
* \param[in] salt_length Size of the `p_salt` buffer in bytes
|
2018-10-11 00:55:03 +02:00
|
|
|
* If `p_salt` is `NULL`, pass 0.
|
|
|
|
* \param[out] p_output Buffer where the decrypted message is to
|
2018-10-15 23:14:24 +02:00
|
|
|
* be written
|
|
|
|
* \param[in] output_size Size of the `p_output` buffer in bytes
|
2018-10-11 00:55:03 +02:00
|
|
|
* \param[out] p_output_length On success, the number of bytes
|
2018-10-15 23:14:24 +02:00
|
|
|
* that make up the returned output
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_asymmetric_decrypt_t)(psa_drv_se_context_t *drv_context,
|
|
|
|
psa_key_slot_number_t key_slot,
|
2019-02-15 23:41:22 +01:00
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *p_input,
|
|
|
|
size_t input_length,
|
|
|
|
const uint8_t *p_salt,
|
|
|
|
size_t salt_length,
|
|
|
|
uint8_t *p_output,
|
|
|
|
size_t output_size,
|
|
|
|
size_t *p_output_length);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
|
|
|
/**
|
2018-10-15 23:14:24 +02:00
|
|
|
* \brief A struct containing all of the function pointers needed to implement
|
2019-02-16 00:23:42 +01:00
|
|
|
* asymmetric cryptographic operations using secure elements.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* PSA Crypto API implementations should populate instances of the table as
|
2019-02-16 00:23:42 +01:00
|
|
|
* appropriate upon startup or at build time.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* If one of the functions is not implemented, it should be set to NULL.
|
|
|
|
*/
|
2018-10-26 12:57:26 +02:00
|
|
|
typedef struct {
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs an asymmetric sign operation */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_asymmetric_sign_t p_sign;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs an asymmetric verify operation */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_asymmetric_verify_t p_verify;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs an asymmetric encrypt operation */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_asymmetric_encrypt_t p_encrypt;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs an asymmetric decrypt operation */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_asymmetric_decrypt_t p_decrypt;
|
2019-02-15 23:41:22 +01:00
|
|
|
} psa_drv_se_asymmetric_t;
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2018-10-15 23:14:24 +02:00
|
|
|
/**@}*/
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \defgroup se_aead Secure Element Authenticated Encryption with Additional Data
|
|
|
|
* Authenticated Encryption with Additional Data (AEAD) operations with secure
|
|
|
|
* elements must be done in one function call. While this creates a burden for
|
2018-10-22 22:27:27 +02:00
|
|
|
* implementers as there must be sufficient space in memory for the entire
|
|
|
|
* message, it prevents decrypted data from being made available before the
|
|
|
|
* authentication operation is complete and the data is known to be authentic.
|
2018-10-11 00:55:03 +02:00
|
|
|
*/
|
2018-10-15 23:14:24 +02:00
|
|
|
/**@{*/
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that performs a secure element authenticated encryption
|
|
|
|
* operation
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] key_slot Slot containing the key to use.
|
|
|
|
* \param[in] algorithm The AEAD algorithm to compute
|
|
|
|
* (\c PSA_ALG_XXX value such that
|
|
|
|
* #PSA_ALG_IS_AEAD(`alg`) is true)
|
|
|
|
* \param[in] p_nonce Nonce or IV to use
|
|
|
|
* \param[in] nonce_length Size of the `p_nonce` buffer in bytes
|
|
|
|
* \param[in] p_additional_data Additional data that will be
|
|
|
|
* authenticated but not encrypted
|
|
|
|
* \param[in] additional_data_length Size of `p_additional_data` in bytes
|
|
|
|
* \param[in] p_plaintext Data that will be authenticated and
|
|
|
|
* encrypted
|
|
|
|
* \param[in] plaintext_length Size of `p_plaintext` in bytes
|
|
|
|
* \param[out] p_ciphertext Output buffer for the authenticated and
|
|
|
|
* encrypted data. The additional data is
|
|
|
|
* not part of this output. For algorithms
|
|
|
|
* where the encrypted data and the
|
|
|
|
* authentication tag are defined as
|
|
|
|
* separate outputs, the authentication
|
|
|
|
* tag is appended to the encrypted data.
|
|
|
|
* \param[in] ciphertext_size Size of the `p_ciphertext` buffer in
|
|
|
|
* bytes
|
|
|
|
* \param[out] p_ciphertext_length On success, the size of the output in
|
|
|
|
* the `p_ciphertext` buffer
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success.
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_aead_encrypt_t)(psa_drv_se_context_t *drv_context,
|
|
|
|
psa_key_slot_number_t key_slot,
|
2019-02-15 23:41:22 +01:00
|
|
|
psa_algorithm_t algorithm,
|
|
|
|
const uint8_t *p_nonce,
|
|
|
|
size_t nonce_length,
|
|
|
|
const uint8_t *p_additional_data,
|
|
|
|
size_t additional_data_length,
|
|
|
|
const uint8_t *p_plaintext,
|
|
|
|
size_t plaintext_length,
|
|
|
|
uint8_t *p_ciphertext,
|
|
|
|
size_t ciphertext_size,
|
|
|
|
size_t *p_ciphertext_length);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** A function that peforms a secure element authenticated decryption operation
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] key_slot Slot containing the key to use
|
|
|
|
* \param[in] algorithm The AEAD algorithm to compute
|
|
|
|
* (\c PSA_ALG_XXX value such that
|
|
|
|
* #PSA_ALG_IS_AEAD(`alg`) is true)
|
|
|
|
* \param[in] p_nonce Nonce or IV to use
|
|
|
|
* \param[in] nonce_length Size of the `p_nonce` buffer in bytes
|
|
|
|
* \param[in] p_additional_data Additional data that has been
|
|
|
|
* authenticated but not encrypted
|
|
|
|
* \param[in] additional_data_length Size of `p_additional_data` in bytes
|
|
|
|
* \param[in] p_ciphertext Data that has been authenticated and
|
|
|
|
* encrypted.
|
|
|
|
* For algorithms where the encrypted data
|
|
|
|
* and the authentication tag are defined
|
|
|
|
* as separate inputs, the buffer must
|
|
|
|
* contain the encrypted data followed by
|
|
|
|
* the authentication tag.
|
|
|
|
* \param[in] ciphertext_length Size of `p_ciphertext` in bytes
|
|
|
|
* \param[out] p_plaintext Output buffer for the decrypted data
|
|
|
|
* \param[in] plaintext_size Size of the `p_plaintext` buffer in
|
|
|
|
* bytes
|
|
|
|
* \param[out] p_plaintext_length On success, the size of the output in
|
|
|
|
* the `p_plaintext` buffer
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success.
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_aead_decrypt_t)(psa_drv_se_context_t *drv_context,
|
|
|
|
psa_key_slot_number_t key_slot,
|
2019-02-15 23:41:22 +01:00
|
|
|
psa_algorithm_t algorithm,
|
|
|
|
const uint8_t *p_nonce,
|
|
|
|
size_t nonce_length,
|
|
|
|
const uint8_t *p_additional_data,
|
|
|
|
size_t additional_data_length,
|
|
|
|
const uint8_t *p_ciphertext,
|
|
|
|
size_t ciphertext_length,
|
|
|
|
uint8_t *p_plaintext,
|
|
|
|
size_t plaintext_size,
|
|
|
|
size_t *p_plaintext_length);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
|
|
|
/**
|
2018-10-15 23:14:24 +02:00
|
|
|
* \brief A struct containing all of the function pointers needed to implement
|
2019-02-16 00:23:42 +01:00
|
|
|
* secure element Authenticated Encryption with Additional Data operations
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* PSA Crypto API implementations should populate instances of the table as
|
|
|
|
* appropriate upon startup.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* If one of the functions is not implemented, it should be set to NULL.
|
|
|
|
*/
|
2018-10-26 12:57:26 +02:00
|
|
|
typedef struct {
|
2018-10-15 23:14:24 +02:00
|
|
|
/** Function that performs the AEAD encrypt operation */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_aead_encrypt_t p_encrypt;
|
2018-10-15 23:14:24 +02:00
|
|
|
/** Function that performs the AEAD decrypt operation */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_aead_decrypt_t p_decrypt;
|
2019-02-15 23:41:22 +01:00
|
|
|
} psa_drv_se_aead_t;
|
2018-10-15 23:14:24 +02:00
|
|
|
/**@}*/
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \defgroup se_key_management Secure Element Key Management
|
2018-10-22 22:27:27 +02:00
|
|
|
* Currently, key management is limited to importing keys in the clear,
|
|
|
|
* destroying keys, and exporting keys in the clear.
|
|
|
|
* Whether a key may be exported is determined by the key policies in place
|
|
|
|
* on the key slot.
|
2018-10-11 00:55:03 +02:00
|
|
|
*/
|
2018-10-15 23:14:24 +02:00
|
|
|
/**@{*/
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-08-05 16:44:14 +02:00
|
|
|
/** An enumeration indicating how a key is created.
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PSA_KEY_CREATION_IMPORT, /**< During psa_import_key() */
|
|
|
|
PSA_KEY_CREATION_GENERATE, /**< During psa_generate_key() */
|
|
|
|
PSA_KEY_CREATION_DERIVE, /**< During psa_key_derivation_output_key() */
|
|
|
|
PSA_KEY_CREATION_COPY, /**< During psa_copy_key() */
|
2019-08-05 16:46:18 +02:00
|
|
|
|
|
|
|
#ifndef __DOXYGEN_ONLY__
|
|
|
|
/** A key is being registered with mbedtls_psa_register_se_key().
|
|
|
|
*
|
|
|
|
* The core only passes this value to
|
|
|
|
* psa_drv_se_key_management_t::p_validate_slot_number, not to
|
|
|
|
* psa_drv_se_key_management_t::p_allocate. The call to
|
|
|
|
* `p_validate_slot_number` is not followed by any other call to the
|
|
|
|
* driver: the key is considered successfully registered if the call to
|
|
|
|
* `p_validate_slot_number` succeeds, or if `p_validate_slot_number` is
|
|
|
|
* null.
|
|
|
|
*
|
|
|
|
* With this creation method, the driver must return #PSA_SUCCESS if
|
|
|
|
* the given attributes are compatible with the existing key in the slot,
|
|
|
|
* and #PSA_ERROR_DOES_NOT_EXIST if the driver can determine that there
|
|
|
|
* is no key with the specified slot number.
|
|
|
|
*
|
|
|
|
* This is an Mbed Crypto extension.
|
|
|
|
*/
|
|
|
|
PSA_KEY_CREATION_REGISTER,
|
|
|
|
#endif
|
2019-08-05 16:44:14 +02:00
|
|
|
} psa_key_creation_method_t;
|
|
|
|
|
2019-07-12 23:33:02 +02:00
|
|
|
/** \brief A function that allocates a slot for a key.
|
2019-08-09 11:33:48 +02:00
|
|
|
*
|
|
|
|
* To create a key in a specific slot in a secure element, the core
|
|
|
|
* first calls this function to determine a valid slot number,
|
|
|
|
* then calls a function to create the key material in that slot.
|
2019-08-05 16:44:14 +02:00
|
|
|
* In nominal conditions (that is, if no error occurs),
|
|
|
|
* the effect of a call to a key creation function in the PSA Cryptography
|
|
|
|
* API with a lifetime that places the key in a secure element is the
|
|
|
|
* following:
|
2019-08-09 11:33:48 +02:00
|
|
|
* -# The core calls psa_drv_se_key_management_t::p_allocate
|
|
|
|
* (or in some implementations
|
|
|
|
* psa_drv_se_key_management_t::p_validate_slot_number). The driver
|
|
|
|
* selects (or validates) a suitable slot number given the key attributes
|
|
|
|
* and the state of the secure element.
|
2019-08-05 16:44:14 +02:00
|
|
|
* -# The core calls a key creation function in the driver.
|
|
|
|
*
|
|
|
|
* The key creation functions in the PSA Cryptography API are:
|
|
|
|
* - psa_import_key(), which causes
|
|
|
|
* a call to `p_allocate` with \p method = #PSA_KEY_CREATION_IMPORT
|
|
|
|
* then a call to psa_drv_se_key_management_t::p_import.
|
|
|
|
* - psa_generate_key(), which causes
|
|
|
|
* a call to `p_allocate` with \p method = #PSA_KEY_CREATION_GENERATE
|
|
|
|
* then a call to psa_drv_se_key_management_t::p_import.
|
|
|
|
* - psa_key_derivation_output_key(), which causes
|
|
|
|
* a call to `p_allocate` with \p method = #PSA_KEY_CREATION_DERIVE
|
|
|
|
* then a call to psa_drv_se_key_derivation_t::p_derive.
|
|
|
|
* - psa_copy_key(), which causes
|
|
|
|
* a call to `p_allocate` with \p method = #PSA_KEY_CREATION_COPY
|
|
|
|
* then a call to psa_drv_se_key_management_t::p_export.
|
2019-08-09 11:33:48 +02:00
|
|
|
*
|
|
|
|
* In case of errors, other behaviors are possible.
|
|
|
|
* - If the PSA Cryptography subsystem dies after the first step,
|
|
|
|
* for example because the device has lost power abruptly,
|
|
|
|
* the second step may never happen, or may happen after a reset
|
|
|
|
* and re-initialization. Alternatively, after a reset and
|
|
|
|
* re-initialization, the core may call
|
|
|
|
* psa_drv_se_key_management_t::p_destroy on the slot number that
|
|
|
|
* was allocated (or validated) instead of calling a key creation function.
|
|
|
|
* - If an error occurs, the core may call
|
|
|
|
* psa_drv_se_key_management_t::p_destroy on the slot number that
|
|
|
|
* was allocated (or validated) instead of calling a key creation function.
|
|
|
|
*
|
|
|
|
* Errors and system resets also have an impact on the driver's persistent
|
|
|
|
* data. If a reset happens before the overall key creation process is
|
|
|
|
* completed (before or after the second step above), it is unspecified
|
|
|
|
* whether the persistent data after the reset is identical to what it
|
|
|
|
* was before or after the call to `p_allocate` (or `p_validate_slot_number`).
|
2019-07-12 23:33:02 +02:00
|
|
|
*
|
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2019-07-12 23:34:20 +02:00
|
|
|
* \param[in,out] persistent_data A pointer to the persistent data
|
|
|
|
* that allows writing.
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in] attributes Attributes of the key.
|
2019-08-05 16:44:14 +02:00
|
|
|
* \param method The way in which the key is being created.
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[out] key_slot Slot where the key will be stored.
|
|
|
|
* This must be a valid slot for a key of the
|
|
|
|
* chosen type. It must be unoccupied.
|
2019-07-12 23:33:02 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success.
|
|
|
|
* The core will record \c *key_slot as the key slot where the key
|
|
|
|
* is stored and will update the persistent data in storage.
|
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
|
|
|
|
*/
|
|
|
|
typedef psa_status_t (*psa_drv_se_allocate_key_t)(
|
|
|
|
psa_drv_se_context_t *drv_context,
|
2019-07-12 23:34:20 +02:00
|
|
|
void *persistent_data,
|
2019-07-12 23:33:02 +02:00
|
|
|
const psa_key_attributes_t *attributes,
|
2019-08-05 16:44:14 +02:00
|
|
|
psa_key_creation_method_t method,
|
2019-07-12 23:33:02 +02:00
|
|
|
psa_key_slot_number_t *key_slot);
|
|
|
|
|
2019-08-05 14:55:14 +02:00
|
|
|
/** \brief A function that determines whether a slot number is valid
|
|
|
|
* for a key.
|
|
|
|
*
|
2019-08-09 11:33:48 +02:00
|
|
|
* To create a key in a specific slot in a secure element, the core
|
|
|
|
* first calls this function to validate the choice of slot number,
|
|
|
|
* then calls a function to create the key material in that slot.
|
|
|
|
* See the documentation of #psa_drv_se_allocate_key_t for more details.
|
|
|
|
*
|
|
|
|
* As of the PSA Cryptography API specification version 1.0, there is no way
|
|
|
|
* for applications to trigger a call to this function. However some
|
|
|
|
* implementations offer the capability to create or declare a key in
|
|
|
|
* a specific slot via implementation-specific means, generally for the
|
|
|
|
* sake of initial device provisioning or onboarding. Such a mechanism may
|
|
|
|
* be added to a future version of the PSA Cryptography API specification.
|
|
|
|
*
|
2019-10-01 14:27:23 +02:00
|
|
|
* This function may update the driver's persistent data through
|
|
|
|
* \p persistent_data. The core will save the updated persistent data at the
|
|
|
|
* end of the key creation process. See the description of
|
|
|
|
* ::psa_drv_se_allocate_key_t for more information.
|
|
|
|
*
|
2019-08-05 16:44:14 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2019-10-01 14:27:23 +02:00
|
|
|
* \param[in,out] persistent_data A pointer to the persistent data
|
|
|
|
* that allows writing.
|
2019-08-05 16:44:14 +02:00
|
|
|
* \param[in] attributes Attributes of the key.
|
|
|
|
* \param method The way in which the key is being created.
|
|
|
|
* \param[in] key_slot Slot where the key is to be stored.
|
2019-08-05 14:55:14 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The given slot number is valid for a key with the given
|
|
|
|
* attributes.
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* The given slot number is not valid for a key with the
|
|
|
|
* given attributes. This includes the case where the slot
|
|
|
|
* number is not valid at all.
|
|
|
|
* \retval #PSA_ERROR_ALREADY_EXISTS
|
|
|
|
* There is already a key with the specified slot number.
|
|
|
|
* Drivers may choose to return this error from the key
|
|
|
|
* creation function instead.
|
|
|
|
*/
|
|
|
|
typedef psa_status_t (*psa_drv_se_validate_slot_number_t)(
|
|
|
|
psa_drv_se_context_t *drv_context,
|
2019-10-01 14:27:23 +02:00
|
|
|
void *persistent_data,
|
2019-08-05 14:55:14 +02:00
|
|
|
const psa_key_attributes_t *attributes,
|
2019-08-05 16:44:14 +02:00
|
|
|
psa_key_creation_method_t method,
|
2019-08-05 14:55:14 +02:00
|
|
|
psa_key_slot_number_t key_slot);
|
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that imports a key into a secure element in binary format
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
|
|
|
* This function can support any output from psa_export_key(). Refer to the
|
|
|
|
* documentation of psa_export_key() for the format for each key type.
|
|
|
|
*
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2019-08-06 17:32:04 +02:00
|
|
|
* \param key_slot Slot where the key will be stored.
|
2019-07-24 20:25:59 +02:00
|
|
|
* This must be a valid slot for a key of the
|
|
|
|
* chosen type. It must be unoccupied.
|
2019-08-06 17:32:04 +02:00
|
|
|
* \param[in] attributes The key attributes, including the lifetime,
|
|
|
|
* the key type and the usage policy.
|
|
|
|
* Drivers should not access the key size stored
|
|
|
|
* in the attributes: it may not match the
|
|
|
|
* data passed in \p data.
|
|
|
|
* Drivers can call psa_get_key_lifetime(),
|
|
|
|
* psa_get_key_type(),
|
|
|
|
* psa_get_key_usage_flags() and
|
|
|
|
* psa_get_key_algorithm() to access this
|
|
|
|
* information.
|
|
|
|
* \param[in] data Buffer containing the key data.
|
|
|
|
* \param[in] data_length Size of the \p data buffer in bytes.
|
2019-07-24 20:25:59 +02:00
|
|
|
* \param[out] bits On success, the key size in bits. The driver
|
|
|
|
* must determine this value after parsing the
|
|
|
|
* key according to the key type.
|
|
|
|
* This value is not used if the function fails.
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success.
|
|
|
|
*/
|
2019-08-06 17:32:04 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_import_key_t)(
|
|
|
|
psa_drv_se_context_t *drv_context,
|
|
|
|
psa_key_slot_number_t key_slot,
|
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t data_length,
|
|
|
|
size_t *bits);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
|
|
|
/**
|
2019-02-16 00:23:42 +01:00
|
|
|
* \brief A function that destroys a secure element key and restore the slot to
|
|
|
|
* its default state
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
2019-02-16 00:23:42 +01:00
|
|
|
* This function destroys the content of the key from a secure element.
|
|
|
|
* Implementations shall make a best effort to ensure that any previous content
|
|
|
|
* of the slot is unrecoverable.
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
2019-02-16 00:23:42 +01:00
|
|
|
* This function returns the specified slot to its default state.
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2019-07-12 23:34:20 +02:00
|
|
|
* \param[in,out] persistent_data A pointer to the persistent data
|
|
|
|
* that allows writing.
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param key_slot The key slot to erase.
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The slot's content, if any, has been erased.
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_destroy_key_t)(
|
|
|
|
psa_drv_se_context_t *drv_context,
|
2019-07-12 23:34:20 +02:00
|
|
|
void *persistent_data,
|
2019-07-12 23:28:46 +02:00
|
|
|
psa_key_slot_number_t key_slot);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
|
|
|
/**
|
2019-02-16 00:23:42 +01:00
|
|
|
* \brief A function that exports a secure element key in binary format
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
|
|
|
* The output of this function can be passed to psa_import_key() to
|
|
|
|
* create an equivalent object.
|
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* If a key is created with `psa_import_key()` and then exported with
|
2018-10-11 00:55:03 +02:00
|
|
|
* this function, it is not guaranteed that the resulting data is
|
|
|
|
* identical: the implementation may choose a different representation
|
|
|
|
* of the same key if the format permits it.
|
|
|
|
*
|
2019-02-16 00:23:42 +01:00
|
|
|
* This function should generate output in the same format that
|
|
|
|
* `psa_export_key()` does. Refer to the
|
|
|
|
* documentation of `psa_export_key()` for the format for each key type.
|
2018-10-11 00:55:03 +02:00
|
|
|
*
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] key Slot whose content is to be exported. This must
|
2018-10-11 00:55:03 +02:00
|
|
|
* be an occupied key slot.
|
|
|
|
* \param[out] p_data Buffer where the key data is to be written.
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[in] data_size Size of the `p_data` buffer in bytes.
|
2018-10-11 00:55:03 +02:00
|
|
|
* \param[out] p_data_length On success, the number of bytes
|
|
|
|
* that make up the key data.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
2019-02-14 12:48:10 +01:00
|
|
|
* \retval #PSA_ERROR_DOES_NOT_EXIST
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED
|
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
2019-05-16 21:35:18 +02:00
|
|
|
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
2018-10-11 00:55:03 +02:00
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_export_key_t)(psa_drv_se_context_t *drv_context,
|
|
|
|
psa_key_slot_number_t key,
|
2019-02-15 23:41:22 +01:00
|
|
|
uint8_t *p_data,
|
|
|
|
size_t data_size,
|
|
|
|
size_t *p_data_length);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
|
|
|
/**
|
2019-02-16 00:23:42 +01:00
|
|
|
* \brief A function that generates a symmetric or asymmetric key on a secure
|
|
|
|
* element
|
2019-03-06 17:56:28 +01:00
|
|
|
*
|
2019-07-23 18:26:43 +02:00
|
|
|
* If \p type is asymmetric (#PSA_KEY_TYPE_IS_ASYMMETRIC(\p type) = 1),
|
2019-08-06 17:32:04 +02:00
|
|
|
* the driver may export the public key at the time of generation,
|
|
|
|
* in the format documented for psa_export_public_key() by writing it
|
|
|
|
* to the \p pubkey buffer.
|
|
|
|
* This is optional, intended for secure elements that output the
|
|
|
|
* public key at generation time and that cannot export the public key
|
|
|
|
* later. Drivers that do not need this feature should leave
|
|
|
|
* \p *pubkey_length set to 0 and should
|
|
|
|
* implement the psa_drv_key_management_t::p_export_public function.
|
|
|
|
* Some implementations do not support this feature, in which case
|
|
|
|
* \p pubkey is \c NULL and \p pubkey_size is 0.
|
2019-03-06 17:56:28 +01:00
|
|
|
*
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2019-08-06 17:32:04 +02:00
|
|
|
* \param key_slot Slot where the key will be stored.
|
|
|
|
* This must be a valid slot for a key of the
|
|
|
|
* chosen type. It must be unoccupied.
|
|
|
|
* \param[in] attributes The key attributes, including the lifetime,
|
|
|
|
* the key type and size, and the usage policy.
|
|
|
|
* Drivers can call psa_get_key_lifetime(),
|
|
|
|
* psa_get_key_type(), psa_get_key_bits(),
|
|
|
|
* psa_get_key_usage_flags() and
|
|
|
|
* psa_get_key_algorithm() to access this
|
|
|
|
* information.
|
|
|
|
* \param[out] pubkey A buffer where the driver can write the
|
|
|
|
* public key, when generating an asymmetric
|
|
|
|
* key pair.
|
|
|
|
* This is \c NULL when generating a symmetric
|
|
|
|
* key or if the core does not support
|
|
|
|
* exporting the public key at generation time.
|
|
|
|
* \param pubkey_size The size of the `pubkey` buffer in bytes.
|
|
|
|
* This is 0 when generating a symmetric
|
|
|
|
* key or if the core does not support
|
|
|
|
* exporting the public key at generation time.
|
|
|
|
* \param[out] pubkey_length On entry, this is always 0.
|
|
|
|
* On success, the number of bytes written to
|
|
|
|
* \p pubkey. If this is 0 or unchanged on return,
|
|
|
|
* the core will not read the \p pubkey buffer,
|
|
|
|
* and will instead call the driver's
|
|
|
|
* psa_drv_key_management_t::p_export_public
|
|
|
|
* function to export the public key when needed.
|
2018-10-11 00:55:03 +02:00
|
|
|
*/
|
2019-08-06 17:32:04 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_generate_key_t)(
|
|
|
|
psa_drv_se_context_t *drv_context,
|
|
|
|
psa_key_slot_number_t key_slot,
|
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
uint8_t *pubkey, size_t pubkey_size, size_t *pubkey_length);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
|
|
|
/**
|
2019-02-16 00:23:42 +01:00
|
|
|
* \brief A struct containing all of the function pointers needed to for secure
|
|
|
|
* element key management
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* PSA Crypto API implementations should populate instances of the table as
|
2019-02-16 00:23:42 +01:00
|
|
|
* appropriate upon startup or at build time.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* If one of the functions is not implemented, it should be set to NULL.
|
|
|
|
*/
|
2018-10-26 12:57:26 +02:00
|
|
|
typedef struct {
|
2019-08-09 11:33:48 +02:00
|
|
|
/** Function that allocates a slot for a key. */
|
2019-07-12 23:33:02 +02:00
|
|
|
psa_drv_se_allocate_key_t p_allocate;
|
2019-08-09 11:33:48 +02:00
|
|
|
/** Function that checks the validity of a slot for a key. */
|
2019-08-05 14:55:14 +02:00
|
|
|
psa_drv_se_validate_slot_number_t p_validate_slot_number;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs a key import operation */
|
|
|
|
psa_drv_se_import_key_t p_import;
|
|
|
|
/** Function that performs a generation */
|
2019-02-16 00:10:49 +01:00
|
|
|
psa_drv_se_generate_key_t p_generate;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs a key destroy operation */
|
2019-02-16 00:10:49 +01:00
|
|
|
psa_drv_se_destroy_key_t p_destroy;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs a key export operation */
|
2019-02-16 00:10:49 +01:00
|
|
|
psa_drv_se_export_key_t p_export;
|
2019-06-25 15:25:09 +02:00
|
|
|
/** Function that performs a public key export operation */
|
|
|
|
psa_drv_se_export_key_t p_export_public;
|
2019-02-15 23:41:22 +01:00
|
|
|
} psa_drv_se_key_management_t;
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2018-10-15 23:14:24 +02:00
|
|
|
/**@}*/
|
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \defgroup driver_derivation Secure Element Key Derivation and Agreement
|
2018-10-15 23:14:24 +02:00
|
|
|
* Key derivation is the process of generating new key material using an
|
|
|
|
* existing key and additional parameters, iterating through a basic
|
2018-10-11 00:55:03 +02:00
|
|
|
* cryptographic function, such as a hash.
|
2018-10-15 23:14:24 +02:00
|
|
|
* Key agreement is a part of cryptographic protocols that allows two parties
|
|
|
|
* to agree on the same key value, but starting from different original key
|
|
|
|
* material.
|
2018-10-26 13:09:31 +02:00
|
|
|
* The flows are similar, and the PSA Crypto Driver Model uses the same functions
|
2018-10-15 23:14:24 +02:00
|
|
|
* for both of the flows.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* There are two different final functions for the flows,
|
2019-02-16 00:23:42 +01:00
|
|
|
* `psa_drv_se_key_derivation_derive` and `psa_drv_se_key_derivation_export`.
|
|
|
|
* `psa_drv_se_key_derivation_derive` is used when the key material should be
|
|
|
|
* placed in a slot on the hardware and not exposed to the caller.
|
|
|
|
* `psa_drv_se_key_derivation_export` is used when the key material should be
|
|
|
|
* returned to the PSA Cryptographic API implementation.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* Different key derivation algorithms require a different number of inputs.
|
|
|
|
* Instead of having an API that takes as input variable length arrays, which
|
|
|
|
* can be problemmatic to manage on embedded platforms, the inputs are passed
|
2019-02-16 00:23:42 +01:00
|
|
|
* to the driver via a function, `psa_drv_se_key_derivation_collateral`, that
|
|
|
|
* is called multiple times with different `collateral_id`s. Thus, for a key
|
2018-10-15 23:14:24 +02:00
|
|
|
* derivation algorithm that required 3 paramter inputs, the flow would look
|
|
|
|
* something like:
|
|
|
|
* ~~~~~~~~~~~~~{.c}
|
2019-02-16 00:23:42 +01:00
|
|
|
* psa_drv_se_key_derivation_setup(kdf_algorithm, source_key, dest_key_size_bytes);
|
|
|
|
* psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_0,
|
|
|
|
* p_collateral_0,
|
|
|
|
* collateral_0_size);
|
|
|
|
* psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_1,
|
|
|
|
* p_collateral_1,
|
|
|
|
* collateral_1_size);
|
|
|
|
* psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_2,
|
|
|
|
* p_collateral_2,
|
|
|
|
* collateral_2_size);
|
|
|
|
* psa_drv_se_key_derivation_derive();
|
2018-10-15 23:14:24 +02:00
|
|
|
* ~~~~~~~~~~~~~
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* key agreement example:
|
|
|
|
* ~~~~~~~~~~~~~{.c}
|
2019-02-16 00:23:42 +01:00
|
|
|
* psa_drv_se_key_derivation_setup(alg, source_key. dest_key_size_bytes);
|
|
|
|
* psa_drv_se_key_derivation_collateral(DHE_PUBKEY, p_pubkey, pubkey_size);
|
|
|
|
* psa_drv_se_key_derivation_export(p_session_key,
|
|
|
|
* session_key_size,
|
|
|
|
* &session_key_length);
|
2018-10-15 23:14:24 +02:00
|
|
|
* ~~~~~~~~~~~~~
|
|
|
|
*/
|
2018-10-22 22:27:27 +02:00
|
|
|
/**@{*/
|
2018-10-15 23:14:24 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that Sets up a secure element key derivation operation by
|
|
|
|
* specifying the algorithm and the source key sot
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-07-25 10:56:39 +02:00
|
|
|
* \param[in,out] drv_context The driver context structure.
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] op_context A hardware-specific structure containing any
|
2019-07-25 10:56:39 +02:00
|
|
|
* context information for the implementation
|
|
|
|
* \param[in] kdf_alg The algorithm to be used for the key derivation
|
|
|
|
* \param[in] source_key The key to be used as the source material for
|
|
|
|
* the key derivation
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_key_derivation_setup_t)(psa_drv_se_context_t *drv_context,
|
|
|
|
void *op_context,
|
2019-02-15 23:41:22 +01:00
|
|
|
psa_algorithm_t kdf_alg,
|
2019-02-16 00:03:42 +01:00
|
|
|
psa_key_slot_number_t source_key);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that provides collateral (parameters) needed for a secure
|
|
|
|
* element key derivation or key agreement operation
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* Since many key derivation algorithms require multiple parameters, it is
|
|
|
|
* expeced that this function may be called multiple times for the same
|
|
|
|
* operation, each with a different algorithm-specific `collateral_id`
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] op_context A hardware-specific structure containing any
|
2018-10-15 23:14:24 +02:00
|
|
|
* context information for the implementation
|
|
|
|
* \param[in] collateral_id An ID for the collateral being provided
|
|
|
|
* \param[in] p_collateral A buffer containing the collateral data
|
|
|
|
* \param[in] collateral_size The size in bytes of the collateral
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_key_derivation_collateral_t)(void *op_context,
|
2019-02-15 23:41:22 +01:00
|
|
|
uint32_t collateral_id,
|
|
|
|
const uint8_t *p_collateral,
|
|
|
|
size_t collateral_size);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that performs the final secure element key derivation
|
|
|
|
* step and place the generated key material in a slot
|
2019-03-06 17:56:28 +01:00
|
|
|
*
|
2019-07-12 23:28:46 +02:00
|
|
|
* \param[in,out] op_context A hardware-specific structure containing any
|
2018-10-15 23:14:24 +02:00
|
|
|
* context information for the implementation
|
|
|
|
* \param[in] dest_key The slot where the generated key material
|
|
|
|
* should be placed
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_key_derivation_derive_t)(void *op_context,
|
2019-02-16 00:12:26 +01:00
|
|
|
psa_key_slot_number_t dest_key);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-02-16 00:23:42 +01:00
|
|
|
/** \brief A function that performs the final step of a secure element key
|
|
|
|
* agreement and place the generated key material in a buffer
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* \param[out] p_output Buffer in which to place the generated key
|
|
|
|
* material
|
|
|
|
* \param[in] output_size The size in bytes of `p_output`
|
|
|
|
* \param[out] p_output_length Upon success, contains the number of bytes of
|
|
|
|
* key material placed in `p_output`
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* \retval PSA_SUCCESS
|
|
|
|
*/
|
2019-07-12 23:28:46 +02:00
|
|
|
typedef psa_status_t (*psa_drv_se_key_derivation_export_t)(void *op_context,
|
2019-02-16 00:12:26 +01:00
|
|
|
uint8_t *p_output,
|
|
|
|
size_t output_size,
|
|
|
|
size_t *p_output_length);
|
2018-10-11 00:55:03 +02:00
|
|
|
|
|
|
|
/**
|
2019-02-16 00:23:42 +01:00
|
|
|
* \brief A struct containing all of the function pointers needed to for secure
|
|
|
|
* element key derivation and agreement
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-15 23:14:24 +02:00
|
|
|
* PSA Crypto API implementations should populate instances of the table as
|
|
|
|
* appropriate upon startup.
|
2018-10-26 11:07:32 +02:00
|
|
|
*
|
2018-10-11 00:55:03 +02:00
|
|
|
* If one of the functions is not implemented, it should be set to NULL.
|
|
|
|
*/
|
2018-10-26 12:57:26 +02:00
|
|
|
typedef struct {
|
2019-02-16 00:12:26 +01:00
|
|
|
/** The driver-specific size of the key derivation context */
|
|
|
|
size_t context_size;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs a key derivation setup */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_key_derivation_setup_t p_setup;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that sets key derivation collateral */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_key_derivation_collateral_t p_collateral;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that performs a final key derivation step */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_key_derivation_derive_t p_derive;
|
2019-02-16 00:23:42 +01:00
|
|
|
/** Function that perforsm a final key derivation or agreement and
|
2018-10-15 23:14:24 +02:00
|
|
|
* exports the key */
|
2019-02-16 00:06:29 +01:00
|
|
|
psa_drv_se_key_derivation_export_t p_export;
|
2019-02-15 23:41:22 +01:00
|
|
|
} psa_drv_se_key_derivation_t;
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2018-10-15 23:14:24 +02:00
|
|
|
/**@}*/
|
2018-10-11 00:55:03 +02:00
|
|
|
|
2019-06-24 13:46:37 +02:00
|
|
|
/** \defgroup se_registration Secure element driver registration
|
|
|
|
*/
|
|
|
|
/**@{*/
|
|
|
|
|
|
|
|
/** A structure containing pointers to all the entry points of a
|
|
|
|
* secure element driver.
|
|
|
|
*
|
|
|
|
* Future versions of this specification may add extra substructures at
|
|
|
|
* the end of this structure.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2019-06-26 11:21:41 +02:00
|
|
|
/** The version of the driver HAL that this driver implements.
|
|
|
|
* This is a protection against loading driver binaries built against
|
2019-06-24 13:46:37 +02:00
|
|
|
* a different version of this specification.
|
|
|
|
* Use #PSA_DRV_SE_HAL_VERSION.
|
|
|
|
*/
|
|
|
|
uint32_t hal_version;
|
2019-07-12 23:25:38 +02:00
|
|
|
|
2019-07-25 14:04:38 +02:00
|
|
|
/** The size of the driver's persistent data in bytes.
|
|
|
|
*
|
|
|
|
* This can be 0 if the driver does not need persistent data.
|
|
|
|
*
|
|
|
|
* See the documentation of psa_drv_se_context_t::persistent_data
|
|
|
|
* for more information about why and how a driver can use
|
|
|
|
* persistent data.
|
|
|
|
*/
|
2019-07-12 23:25:38 +02:00
|
|
|
size_t persistent_data_size;
|
|
|
|
|
|
|
|
/** The driver initialization function.
|
|
|
|
*
|
|
|
|
* This function is called once during the initialization of the
|
|
|
|
* PSA Cryptography subsystem, before any other function of the
|
|
|
|
* driver is called. If this function returns a failure status,
|
|
|
|
* the driver will be unusable, at least until the next system reset.
|
|
|
|
*
|
|
|
|
* If this field is \c NULL, it is equivalent to a function that does
|
|
|
|
* nothing and returns #PSA_SUCCESS.
|
|
|
|
*/
|
|
|
|
psa_drv_se_init_t p_init;
|
|
|
|
|
2019-06-26 19:06:52 +02:00
|
|
|
const psa_drv_se_key_management_t *key_management;
|
|
|
|
const psa_drv_se_mac_t *mac;
|
|
|
|
const psa_drv_se_cipher_t *cipher;
|
|
|
|
const psa_drv_se_aead_t *aead;
|
|
|
|
const psa_drv_se_asymmetric_t *asymmetric;
|
|
|
|
const psa_drv_se_key_derivation_t *derivation;
|
2019-06-24 13:46:37 +02:00
|
|
|
} psa_drv_se_t;
|
|
|
|
|
2019-06-26 11:21:41 +02:00
|
|
|
/** The current version of the secure element driver HAL.
|
2019-06-24 13:46:37 +02:00
|
|
|
*/
|
|
|
|
/* 0.0.0 patchlevel 5 */
|
|
|
|
#define PSA_DRV_SE_HAL_VERSION 0x00000005
|
|
|
|
|
2019-06-26 11:21:41 +02:00
|
|
|
/** Register an external cryptoprocessor (secure element) driver.
|
2019-06-24 13:47:07 +02:00
|
|
|
*
|
|
|
|
* This function is only intended to be used by driver code, not by
|
|
|
|
* application code. In implementations with separation between the
|
|
|
|
* PSA cryptography module and applications, this function should
|
|
|
|
* only be available to callers that run in the same memory space as
|
|
|
|
* the cryptography module, and should not be exposed to applications
|
|
|
|
* running in a different memory space.
|
|
|
|
*
|
|
|
|
* This function may be called before psa_crypto_init(). It is
|
|
|
|
* implementation-defined whether this function may be called
|
|
|
|
* after psa_crypto_init().
|
|
|
|
*
|
2019-06-26 11:21:41 +02:00
|
|
|
* \note Implementations store metadata about keys including the lifetime
|
2020-05-10 00:39:18 +02:00
|
|
|
* value, which contains the driver's location indicator. Therefore,
|
|
|
|
* from one instantiation of the PSA Cryptography
|
2019-06-26 11:21:41 +02:00
|
|
|
* library to the next one, if there is a key in storage with a certain
|
|
|
|
* lifetime value, you must always register the same driver (or an
|
|
|
|
* updated version that communicates with the same secure element)
|
2020-05-10 00:39:18 +02:00
|
|
|
* with the same location value.
|
2019-06-26 11:21:41 +02:00
|
|
|
*
|
2020-05-10 00:39:18 +02:00
|
|
|
* \param location The location value through which this driver will
|
2019-06-24 13:47:07 +02:00
|
|
|
* be exposed to applications.
|
2020-05-10 00:39:18 +02:00
|
|
|
* This driver will be used for all keys such that
|
|
|
|
* `location == PSA_KEY_LIFETIME_LOCATION( lifetime )`.
|
|
|
|
* The value #PSA_KEY_LOCATION_LOCAL_STORAGE is reserved
|
|
|
|
* and may not be used for drivers. Implementations
|
2019-06-24 13:47:07 +02:00
|
|
|
* may reserve other values.
|
|
|
|
* \param[in] methods The method table of the driver. This structure must
|
|
|
|
* remain valid for as long as the cryptography
|
|
|
|
* module keeps running. It is typically a global
|
|
|
|
* constant.
|
|
|
|
*
|
|
|
|
* \return PSA_SUCCESS
|
|
|
|
* The driver was successfully registered. Applications can now
|
|
|
|
* use \p lifetime to access keys through the methods passed to
|
|
|
|
* this function.
|
|
|
|
* \return PSA_ERROR_BAD_STATE
|
|
|
|
* This function was called after the initialization of the
|
|
|
|
* cryptography module, and this implementation does not support
|
|
|
|
* driver registration at this stage.
|
|
|
|
* \return PSA_ERROR_ALREADY_EXISTS
|
|
|
|
* There is already a registered driver for this value of \p lifetime.
|
|
|
|
* \return PSA_ERROR_INVALID_ARGUMENT
|
2019-06-26 11:21:41 +02:00
|
|
|
* \p lifetime is a reserved value.
|
2019-06-24 13:47:07 +02:00
|
|
|
* \return PSA_ERROR_NOT_SUPPORTED
|
2019-06-26 11:21:41 +02:00
|
|
|
* `methods->hal_version` is not supported by this implementation.
|
2019-06-24 13:47:07 +02:00
|
|
|
* \return PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* \return PSA_ERROR_NOT_PERMITTED
|
|
|
|
*/
|
|
|
|
psa_status_t psa_register_se_driver(
|
|
|
|
psa_key_lifetime_t lifetime,
|
|
|
|
const psa_drv_se_t *methods);
|
|
|
|
|
2019-06-24 13:46:37 +02:00
|
|
|
/**@}*/
|
|
|
|
|
2018-10-26 12:59:58 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-12-12 15:55:09 +01:00
|
|
|
#endif /* PSA_CRYPTO_SE_DRIVER_H */
|