blob: d2c82bc0c08108faddc11176fcf9eed1ff18f298 [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
Antonio de Angelisc26af632021-10-07 15:04:12 +01002 * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
Antonio de Angelis8908f472018-08-31 15:44:25 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __TFM_CRYPTO_API_H__
9#define __TFM_CRYPTO_API_H__
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include <stdint.h>
16#include "tfm_crypto_defs.h"
Antonio de Angelis7557e682022-11-30 15:37:51 +000017#include "tfm_crypto_key.h"
Soby Mathewd7b79f22020-05-21 15:06:54 +010018#include "psa/crypto_client_struct.h"
19
Antonio de Angelis8908f472018-08-31 15:44:25 +010020/**
21 * \brief List of possible operation types supported by the TFM based
22 * implementation. This type is needed by the operation allocation,
23 * lookup and release functions.
24 *
25 */
26enum tfm_crypto_operation_type {
27 TFM_CRYPTO_OPERATION_NONE = 0,
28 TFM_CRYPTO_CIPHER_OPERATION = 1,
29 TFM_CRYPTO_MAC_OPERATION = 2,
30 TFM_CRYPTO_HASH_OPERATION = 3,
Antonio de Angelis04debbd2019-10-14 12:12:52 +010031 TFM_CRYPTO_KEY_DERIVATION_OPERATION = 4,
Antonio de Angelisc26af632021-10-07 15:04:12 +010032 TFM_CRYPTO_AEAD_OPERATION = 5,
Antonio de Angelis8908f472018-08-31 15:44:25 +010033
34 /* Used to force the enum size */
35 TFM_CRYPTO_OPERATION_TYPE_MAX = INT_MAX
36};
37
David Huc9679cc2022-06-21 13:09:34 +080038/*
39 * Macro to determine the group_id corresponding to a function_id by
40 * accessing the tfm_crypto_func_sid table
Antonio de Angelis202425a2022-04-06 11:13:15 +010041 */
David Huc9679cc2022-06-21 13:09:34 +080042#define TFM_CRYPTO_GET_GROUP_ID(_function_id) \
43 ((enum tfm_crypto_group_id)((_function_id) & 0xFF))
Antonio de Angelis202425a2022-04-06 11:13:15 +010044
45/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010046 * \brief Initialise the service
Antonio de Angelis8908f472018-08-31 15:44:25 +010047 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000048 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010049 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000050psa_status_t tfm_crypto_init(void);
Antonio de Angelis8908f472018-08-31 15:44:25 +010051
52/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010053 * \brief Initialise the Alloc module
54 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000055 * \return Return values as described in \ref psa_status_t
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010056 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000057psa_status_t tfm_crypto_init_alloc(void);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010058
59/**
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010060 * \brief Returns the ID of the caller
61 *
62 * \param[out] id Pointer to hold the ID of the caller
63 *
64 * \return Return values as described in \ref psa_status_t
65 */
66psa_status_t tfm_crypto_get_caller_id(int32_t *id);
67
68/**
Jamie Fox98ab4412020-01-17 17:12:30 +000069 * \brief Gets key attributes from client key attributes.
70 *
71 * \param[in] client_key_attr Client key attributes
72 * \param[in] client_id Partition ID of the calling client
73 * \param[out] key_attributes Key attributes
74 *
75 * \return Return values as described in \ref psa_status_t
76 */
77psa_status_t tfm_crypto_key_attributes_from_client(
Maulik Patel28659c42021-01-06 14:09:22 +000078 const struct psa_client_key_attributes_s *client_key_attr,
79 int32_t client_id,
80 psa_key_attributes_t *key_attributes);
Jamie Fox98ab4412020-01-17 17:12:30 +000081
82/**
83 * \brief Converts key attributes to client key attributes.
84 *
85 * \param[in] key_attributes Key attributes
86 * \param[out] client_key_attr Client key attributes
87 *
88 * \return Return values as described in \ref psa_status_t
89 */
90psa_status_t tfm_crypto_key_attributes_to_client(
Maulik Patel28659c42021-01-06 14:09:22 +000091 const psa_key_attributes_t *key_attributes,
92 struct psa_client_key_attributes_s *client_key_attr);
Jamie Fox98ab4412020-01-17 17:12:30 +000093
94/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000095 * \brief Allocate an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +010096 *
Antonio de Angelis4743e672019-04-11 11:38:48 +010097 * \param[in] type Type of the operation context to allocate
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010098 * \param[out] handle Pointer to hold the allocated handle
Antonio de Angelis4743e672019-04-11 11:38:48 +010099 * \param[out ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +0100100 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000101 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100102 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000103psa_status_t tfm_crypto_operation_alloc(enum tfm_crypto_operation_type type,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100104 uint32_t *handle,
Antonio de Angelis819c2f32019-02-06 14:32:02 +0000105 void **ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100106/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +0000107 * \brief Release an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +0100108 *
David Huc9679cc2022-06-21 13:09:34 +0800109 * \param[in/out] handle Pointer to the handle of the context to release
Antonio de Angelis8908f472018-08-31 15:44:25 +0100110 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000111 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100112 */
Antonio de Angelis4743e672019-04-11 11:38:48 +0100113psa_status_t tfm_crypto_operation_release(uint32_t *handle);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100114/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +0000115 * \brief Look up an operation context in the backend for the corresponding
116 * frontend operation
Antonio de Angelis8908f472018-08-31 15:44:25 +0100117 *
Antonio de Angelis4743e672019-04-11 11:38:48 +0100118 * \param[in] type Type of the operation context to look up
119 * \param[in] handle Handle of the context to lookup
120 * \param[out] ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +0100121 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000122 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100123 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000124psa_status_t tfm_crypto_operation_lookup(enum tfm_crypto_operation_type type,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100125 uint32_t handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000126 void **ctx);
David Huc9679cc2022-06-21 13:09:34 +0800127
Antonio de Angelis202425a2022-04-06 11:13:15 +0100128/**
129 * \brief This function acts as interface from the framework dispatching
130 * calls to the set of functions that implement the PSA Crypto APIs.
131 * It is based on the Uniform Signatures prototype.
132 *
133 * \param[in] in_vec Array of invec parameters
134 * \param[in] in_len Length of the valid entries in in_vec
135 * \param[out] out_vec Array of outvec parameters
136 * \param[in] out_len Length of the valid entries in out_vec
137 *
138 * \return Return values as described in \ref psa_status_t
139 */
140psa_status_t tfm_crypto_api_dispatcher(psa_invec in_vec[],
141 size_t in_len,
142 psa_outvec out_vec[],
143 size_t out_len);
144/**
145 * \brief This function acts as interface for the Key management module
146 *
147 * \param[in] in_vec Array of invec parameters
148 * \param[out] out_vec Array of outvec parameters
149 * \param[in] encoded_key Key encoded with partition_id and key_id
150 *
151 * \return Return values as described in \ref psa_status_t
152 */
153psa_status_t tfm_crypto_key_management_interface(psa_invec in_vec[],
154 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000155 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100156/**
157 * \brief This function acts as interface for the MAC module
158 *
159 * \param[in] in_vec Array of invec parameters
160 * \param[out] out_vec Array of outvec parameters
161 * \param[in] encoded_key Key encoded with partition_id and key_id
162 *
163 * \return Return values as described in \ref psa_status_t
164 */
165psa_status_t tfm_crypto_mac_interface(psa_invec in_vec[],
166 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000167 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100168/**
169 * \brief This function acts as interface for the Cipher module
170 *
171 * \param[in] in_vec Array of invec parameters
172 * \param[out] out_vec Array of outvec parameters
173 * \param[in] encoded_key Key encoded with partition_id and key_id
174 *
175 * \return Return values as described in \ref psa_status_t
176 */
177psa_status_t tfm_crypto_cipher_interface(psa_invec in_vec[],
178 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000179 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100180/**
181 * \brief This function acts as interface for the AEAD module
182 *
183 * \param[in] in_vec Array of invec parameters
184 * \param[out] out_vec Array of outvec parameters
185 * \param[in] encoded_key Key encoded with partition_id and key_id
186 *
187 * \return Return values as described in \ref psa_status_t
188 */
189psa_status_t tfm_crypto_aead_interface(psa_invec in_vec[],
190 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000191 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800192
Antonio de Angelis202425a2022-04-06 11:13:15 +0100193/**
David Hu1eb11942022-07-05 11:36:34 +0800194 * \brief This function acts as interface for the Asymmetric signing module
Antonio de Angelis202425a2022-04-06 11:13:15 +0100195 *
196 * \param[in] in_vec Array of invec parameters
197 * \param[out] out_vec Array of outvec parameters
198 * \param[in] encoded_key Key encoded with partition_id and key_id
199 *
200 * \return Return values as described in \ref psa_status_t
201 */
David Hu1eb11942022-07-05 11:36:34 +0800202psa_status_t tfm_crypto_asymmetric_sign_interface(psa_invec in_vec[],
203 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000204 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800205
206/**
207 * \brief This function acts as interface for the Asymmetric encryption module
208 *
209 * \param[in] in_vec Array of invec parameters
210 * \param[out] out_vec Array of outvec parameters
211 * \param[in] encoded_key Key encoded with partition_id and key_id
212 *
213 * \return Return values as described in \ref psa_status_t
214 */
215psa_status_t tfm_crypto_asymmetric_encrypt_interface(psa_invec in_vec[],
216 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000217 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800218
Antonio de Angelis202425a2022-04-06 11:13:15 +0100219/**
220 * \brief This function acts as interface for the Key derivation module
221 *
222 * \param[in] in_vec Array of invec parameters
223 * \param[out] out_vec Array of outvec parameters
224 * \param[in] encoded_key Key encoded with partition_id and key_id
225 *
226 * \return Return values as described in \ref psa_status_t
227 */
228psa_status_t tfm_crypto_key_derivation_interface(psa_invec in_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000229 psa_outvec out_vec[],
230 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100231/**
232 * \brief This function acts as interface for the Random module
233 *
234 * \param[in] in_vec Array of invec parameters
235 * \param[out] out_vec Array of outvec parameters
236 *
237 * \return Return values as described in \ref psa_status_t
238 */
239psa_status_t tfm_crypto_random_interface(psa_invec in_vec[],
240 psa_outvec out_vec[]);
241/**
242 * \brief This function acts as interface for the Hash module
243 *
244 * \param[in] in_vec Array of invec parameters
245 * \param[out] out_vec Array of outvec parameters
246 *
247 * \return Return values as described in \ref psa_status_t
248 */
249psa_status_t tfm_crypto_hash_interface(psa_invec in_vec[],
250 psa_outvec out_vec[]);
Jamie Foxefd82732018-11-26 10:34:32 +0000251
Antonio de Angelis8908f472018-08-31 15:44:25 +0100252#ifdef __cplusplus
253}
254#endif
255
256#endif /* __TFM_CRYPTO_API_H__ */