blob: 0edc713aae899edc8a062da178573c6d117ab671 [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"
Kevin Peng0e340ea2023-08-15 17:51:44 +080018#include "psa/client.h"
Soby Mathewd7b79f22020-05-21 15:06:54 +010019
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
Antonio de Angelis202425a2022-04-06 11:13:15 +010038/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010039 * \brief Initialise the service
Antonio de Angelis8908f472018-08-31 15:44:25 +010040 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000041 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010042 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000043psa_status_t tfm_crypto_init(void);
Antonio de Angelis8908f472018-08-31 15:44:25 +010044
45/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010046 * \brief Initialise the Alloc module
47 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000048 * \return Return values as described in \ref psa_status_t
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010049 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000050psa_status_t tfm_crypto_init_alloc(void);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010051
52/**
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010053 * \brief Returns the ID of the caller
54 *
55 * \param[out] id Pointer to hold the ID of the caller
56 *
57 * \return Return values as described in \ref psa_status_t
58 */
59psa_status_t tfm_crypto_get_caller_id(int32_t *id);
60
61/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000062 * \brief Allocate an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +010063 *
Antonio de Angelis4743e672019-04-11 11:38:48 +010064 * \param[in] type Type of the operation context to allocate
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010065 * \param[out] handle Pointer to hold the allocated handle
Antonio de Angelis4743e672019-04-11 11:38:48 +010066 * \param[out ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +010067 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000068 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010069 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000070psa_status_t tfm_crypto_operation_alloc(enum tfm_crypto_operation_type type,
Antonio de Angelis4743e672019-04-11 11:38:48 +010071 uint32_t *handle,
Antonio de Angelis819c2f32019-02-06 14:32:02 +000072 void **ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +010073/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000074 * \brief Release an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +010075 *
David Huc9679cc2022-06-21 13:09:34 +080076 * \param[in/out] handle Pointer to the handle of the context to release
Antonio de Angelis8908f472018-08-31 15:44:25 +010077 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000078 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010079 */
Antonio de Angelis4743e672019-04-11 11:38:48 +010080psa_status_t tfm_crypto_operation_release(uint32_t *handle);
Antonio de Angelis8908f472018-08-31 15:44:25 +010081/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000082 * \brief Look up an operation context in the backend for the corresponding
83 * frontend operation
Antonio de Angelis8908f472018-08-31 15:44:25 +010084 *
Antonio de Angelis4743e672019-04-11 11:38:48 +010085 * \param[in] type Type of the operation context to look up
86 * \param[in] handle Handle of the context to lookup
87 * \param[out] ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +010088 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000089 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010090 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000091psa_status_t tfm_crypto_operation_lookup(enum tfm_crypto_operation_type type,
Antonio de Angelis4743e672019-04-11 11:38:48 +010092 uint32_t handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000093 void **ctx);
David Huc9679cc2022-06-21 13:09:34 +080094
Antonio de Angelis202425a2022-04-06 11:13:15 +010095/**
96 * \brief This function acts as interface from the framework dispatching
97 * calls to the set of functions that implement the PSA Crypto APIs.
98 * It is based on the Uniform Signatures prototype.
99 *
100 * \param[in] in_vec Array of invec parameters
101 * \param[in] in_len Length of the valid entries in in_vec
102 * \param[out] out_vec Array of outvec parameters
103 * \param[in] out_len Length of the valid entries in out_vec
104 *
105 * \return Return values as described in \ref psa_status_t
106 */
107psa_status_t tfm_crypto_api_dispatcher(psa_invec in_vec[],
108 size_t in_len,
109 psa_outvec out_vec[],
110 size_t out_len);
111/**
112 * \brief This function acts as interface for the Key management module
113 *
114 * \param[in] in_vec Array of invec parameters
115 * \param[out] out_vec Array of outvec parameters
116 * \param[in] encoded_key Key encoded with partition_id and key_id
117 *
118 * \return Return values as described in \ref psa_status_t
119 */
120psa_status_t tfm_crypto_key_management_interface(psa_invec in_vec[],
121 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000122 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100123/**
124 * \brief This function acts as interface for the MAC module
125 *
126 * \param[in] in_vec Array of invec parameters
127 * \param[out] out_vec Array of outvec parameters
128 * \param[in] encoded_key Key encoded with partition_id and key_id
129 *
130 * \return Return values as described in \ref psa_status_t
131 */
132psa_status_t tfm_crypto_mac_interface(psa_invec in_vec[],
133 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000134 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100135/**
136 * \brief This function acts as interface for the Cipher module
137 *
138 * \param[in] in_vec Array of invec parameters
139 * \param[out] out_vec Array of outvec parameters
140 * \param[in] encoded_key Key encoded with partition_id and key_id
141 *
142 * \return Return values as described in \ref psa_status_t
143 */
144psa_status_t tfm_crypto_cipher_interface(psa_invec in_vec[],
145 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000146 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100147/**
148 * \brief This function acts as interface for the AEAD module
149 *
150 * \param[in] in_vec Array of invec parameters
151 * \param[out] out_vec Array of outvec parameters
152 * \param[in] encoded_key Key encoded with partition_id and key_id
153 *
154 * \return Return values as described in \ref psa_status_t
155 */
156psa_status_t tfm_crypto_aead_interface(psa_invec in_vec[],
157 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000158 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800159
Antonio de Angelis202425a2022-04-06 11:13:15 +0100160/**
David Hu1eb11942022-07-05 11:36:34 +0800161 * \brief This function acts as interface for the Asymmetric signing module
Antonio de Angelis202425a2022-04-06 11:13:15 +0100162 *
163 * \param[in] in_vec Array of invec parameters
164 * \param[out] out_vec Array of outvec parameters
165 * \param[in] encoded_key Key encoded with partition_id and key_id
166 *
167 * \return Return values as described in \ref psa_status_t
168 */
David Hu1eb11942022-07-05 11:36:34 +0800169psa_status_t tfm_crypto_asymmetric_sign_interface(psa_invec in_vec[],
170 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000171 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800172
173/**
174 * \brief This function acts as interface for the Asymmetric encryption module
175 *
176 * \param[in] in_vec Array of invec parameters
177 * \param[out] out_vec Array of outvec parameters
178 * \param[in] encoded_key Key encoded with partition_id and key_id
179 *
180 * \return Return values as described in \ref psa_status_t
181 */
182psa_status_t tfm_crypto_asymmetric_encrypt_interface(psa_invec in_vec[],
183 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000184 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800185
Antonio de Angelis202425a2022-04-06 11:13:15 +0100186/**
187 * \brief This function acts as interface for the Key derivation module
188 *
189 * \param[in] in_vec Array of invec parameters
190 * \param[out] out_vec Array of outvec parameters
191 * \param[in] encoded_key Key encoded with partition_id and key_id
192 *
193 * \return Return values as described in \ref psa_status_t
194 */
195psa_status_t tfm_crypto_key_derivation_interface(psa_invec in_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000196 psa_outvec out_vec[],
197 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100198/**
199 * \brief This function acts as interface for the Random module
200 *
201 * \param[in] in_vec Array of invec parameters
202 * \param[out] out_vec Array of outvec parameters
203 *
204 * \return Return values as described in \ref psa_status_t
205 */
206psa_status_t tfm_crypto_random_interface(psa_invec in_vec[],
207 psa_outvec out_vec[]);
208/**
209 * \brief This function acts as interface for the Hash module
210 *
211 * \param[in] in_vec Array of invec parameters
212 * \param[out] out_vec Array of outvec parameters
213 *
214 * \return Return values as described in \ref psa_status_t
215 */
216psa_status_t tfm_crypto_hash_interface(psa_invec in_vec[],
217 psa_outvec out_vec[]);
Jamie Foxefd82732018-11-26 10:34:32 +0000218
Antonio de Angelis8908f472018-08-31 15:44:25 +0100219#ifdef __cplusplus
220}
221#endif
222
223#endif /* __TFM_CRYPTO_API_H__ */