blob: 5e4c2d3c6843c18a694887bbfadebbdcf1328357 [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
Antonio de Angelis8908f472018-08-31 15:44:25 +010019/**
20 * \brief List of possible operation types supported by the TFM based
21 * implementation. This type is needed by the operation allocation,
22 * lookup and release functions.
23 *
24 */
25enum tfm_crypto_operation_type {
26 TFM_CRYPTO_OPERATION_NONE = 0,
27 TFM_CRYPTO_CIPHER_OPERATION = 1,
28 TFM_CRYPTO_MAC_OPERATION = 2,
29 TFM_CRYPTO_HASH_OPERATION = 3,
Antonio de Angelis04debbd2019-10-14 12:12:52 +010030 TFM_CRYPTO_KEY_DERIVATION_OPERATION = 4,
Antonio de Angelisc26af632021-10-07 15:04:12 +010031 TFM_CRYPTO_AEAD_OPERATION = 5,
Antonio de Angelis8908f472018-08-31 15:44:25 +010032
33 /* Used to force the enum size */
34 TFM_CRYPTO_OPERATION_TYPE_MAX = INT_MAX
35};
36
David Huc9679cc2022-06-21 13:09:34 +080037/*
38 * Macro to determine the group_id corresponding to a function_id by
39 * accessing the tfm_crypto_func_sid table
Antonio de Angelis202425a2022-04-06 11:13:15 +010040 */
David Huc9679cc2022-06-21 13:09:34 +080041#define TFM_CRYPTO_GET_GROUP_ID(_function_id) \
42 ((enum tfm_crypto_group_id)((_function_id) & 0xFF))
Antonio de Angelis202425a2022-04-06 11:13:15 +010043
44/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010045 * \brief Initialise the service
Antonio de Angelis8908f472018-08-31 15:44:25 +010046 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000047 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010048 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000049psa_status_t tfm_crypto_init(void);
Antonio de Angelis8908f472018-08-31 15:44:25 +010050
51/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010052 * \brief Initialise the Alloc module
53 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000054 * \return Return values as described in \ref psa_status_t
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010055 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000056psa_status_t tfm_crypto_init_alloc(void);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010057
58/**
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010059 * \brief Returns the ID of the caller
60 *
61 * \param[out] id Pointer to hold the ID of the caller
62 *
63 * \return Return values as described in \ref psa_status_t
64 */
65psa_status_t tfm_crypto_get_caller_id(int32_t *id);
66
67/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000068 * \brief Allocate an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +010069 *
Antonio de Angelis4743e672019-04-11 11:38:48 +010070 * \param[in] type Type of the operation context to allocate
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010071 * \param[out] handle Pointer to hold the allocated handle
Antonio de Angelis4743e672019-04-11 11:38:48 +010072 * \param[out ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +010073 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000074 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010075 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000076psa_status_t tfm_crypto_operation_alloc(enum tfm_crypto_operation_type type,
Antonio de Angelis4743e672019-04-11 11:38:48 +010077 uint32_t *handle,
Antonio de Angelis819c2f32019-02-06 14:32:02 +000078 void **ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +010079/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000080 * \brief Release an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +010081 *
David Huc9679cc2022-06-21 13:09:34 +080082 * \param[in/out] handle Pointer to the handle of the context to release
Antonio de Angelis8908f472018-08-31 15:44:25 +010083 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000084 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010085 */
Antonio de Angelis4743e672019-04-11 11:38:48 +010086psa_status_t tfm_crypto_operation_release(uint32_t *handle);
Antonio de Angelis8908f472018-08-31 15:44:25 +010087/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000088 * \brief Look up an operation context in the backend for the corresponding
89 * frontend operation
Antonio de Angelis8908f472018-08-31 15:44:25 +010090 *
Antonio de Angelis4743e672019-04-11 11:38:48 +010091 * \param[in] type Type of the operation context to look up
92 * \param[in] handle Handle of the context to lookup
93 * \param[out] ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +010094 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000095 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010096 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000097psa_status_t tfm_crypto_operation_lookup(enum tfm_crypto_operation_type type,
Antonio de Angelis4743e672019-04-11 11:38:48 +010098 uint32_t handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000099 void **ctx);
David Huc9679cc2022-06-21 13:09:34 +0800100
Antonio de Angelis202425a2022-04-06 11:13:15 +0100101/**
102 * \brief This function acts as interface from the framework dispatching
103 * calls to the set of functions that implement the PSA Crypto APIs.
104 * It is based on the Uniform Signatures prototype.
105 *
106 * \param[in] in_vec Array of invec parameters
107 * \param[in] in_len Length of the valid entries in in_vec
108 * \param[out] out_vec Array of outvec parameters
109 * \param[in] out_len Length of the valid entries in out_vec
110 *
111 * \return Return values as described in \ref psa_status_t
112 */
113psa_status_t tfm_crypto_api_dispatcher(psa_invec in_vec[],
114 size_t in_len,
115 psa_outvec out_vec[],
116 size_t out_len);
117/**
118 * \brief This function acts as interface for the Key management module
119 *
120 * \param[in] in_vec Array of invec parameters
121 * \param[out] out_vec Array of outvec parameters
122 * \param[in] encoded_key Key encoded with partition_id and key_id
123 *
124 * \return Return values as described in \ref psa_status_t
125 */
126psa_status_t tfm_crypto_key_management_interface(psa_invec in_vec[],
127 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000128 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100129/**
130 * \brief This function acts as interface for the MAC module
131 *
132 * \param[in] in_vec Array of invec parameters
133 * \param[out] out_vec Array of outvec parameters
134 * \param[in] encoded_key Key encoded with partition_id and key_id
135 *
136 * \return Return values as described in \ref psa_status_t
137 */
138psa_status_t tfm_crypto_mac_interface(psa_invec in_vec[],
139 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000140 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100141/**
142 * \brief This function acts as interface for the Cipher module
143 *
144 * \param[in] in_vec Array of invec parameters
145 * \param[out] out_vec Array of outvec parameters
146 * \param[in] encoded_key Key encoded with partition_id and key_id
147 *
148 * \return Return values as described in \ref psa_status_t
149 */
150psa_status_t tfm_crypto_cipher_interface(psa_invec in_vec[],
151 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000152 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100153/**
154 * \brief This function acts as interface for the AEAD module
155 *
156 * \param[in] in_vec Array of invec parameters
157 * \param[out] out_vec Array of outvec parameters
158 * \param[in] encoded_key Key encoded with partition_id and key_id
159 *
160 * \return Return values as described in \ref psa_status_t
161 */
162psa_status_t tfm_crypto_aead_interface(psa_invec in_vec[],
163 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000164 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800165
Antonio de Angelis202425a2022-04-06 11:13:15 +0100166/**
David Hu1eb11942022-07-05 11:36:34 +0800167 * \brief This function acts as interface for the Asymmetric signing module
Antonio de Angelis202425a2022-04-06 11:13:15 +0100168 *
169 * \param[in] in_vec Array of invec parameters
170 * \param[out] out_vec Array of outvec parameters
171 * \param[in] encoded_key Key encoded with partition_id and key_id
172 *
173 * \return Return values as described in \ref psa_status_t
174 */
David Hu1eb11942022-07-05 11:36:34 +0800175psa_status_t tfm_crypto_asymmetric_sign_interface(psa_invec in_vec[],
176 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000177 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800178
179/**
180 * \brief This function acts as interface for the Asymmetric encryption module
181 *
182 * \param[in] in_vec Array of invec parameters
183 * \param[out] out_vec Array of outvec parameters
184 * \param[in] encoded_key Key encoded with partition_id and key_id
185 *
186 * \return Return values as described in \ref psa_status_t
187 */
188psa_status_t tfm_crypto_asymmetric_encrypt_interface(psa_invec in_vec[],
189 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000190 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800191
Antonio de Angelis202425a2022-04-06 11:13:15 +0100192/**
193 * \brief This function acts as interface for the Key derivation module
194 *
195 * \param[in] in_vec Array of invec parameters
196 * \param[out] out_vec Array of outvec parameters
197 * \param[in] encoded_key Key encoded with partition_id and key_id
198 *
199 * \return Return values as described in \ref psa_status_t
200 */
201psa_status_t tfm_crypto_key_derivation_interface(psa_invec in_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000202 psa_outvec out_vec[],
203 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100204/**
205 * \brief This function acts as interface for the Random module
206 *
207 * \param[in] in_vec Array of invec parameters
208 * \param[out] out_vec Array of outvec parameters
209 *
210 * \return Return values as described in \ref psa_status_t
211 */
212psa_status_t tfm_crypto_random_interface(psa_invec in_vec[],
213 psa_outvec out_vec[]);
214/**
215 * \brief This function acts as interface for the Hash module
216 *
217 * \param[in] in_vec Array of invec parameters
218 * \param[out] out_vec Array of outvec parameters
219 *
220 * \return Return values as described in \ref psa_status_t
221 */
222psa_status_t tfm_crypto_hash_interface(psa_invec in_vec[],
223 psa_outvec out_vec[]);
Jamie Foxefd82732018-11-26 10:34:32 +0000224
Antonio de Angelis8908f472018-08-31 15:44:25 +0100225#ifdef __cplusplus
226}
227#endif
228
229#endif /* __TFM_CRYPTO_API_H__ */