blob: 8fff29dcedbfa9ed969004e25dcf134d589be937 [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
Antonio de Angelis3fae3ae2023-10-01 00:28:56 +010015#include <limits.h>
Antonio de Angelis8908f472018-08-31 15:44:25 +010016#include <stdint.h>
17#include "tfm_crypto_defs.h"
Antonio de Angelis7557e682022-11-30 15:37:51 +000018#include "tfm_crypto_key.h"
Kevin Peng0e340ea2023-08-15 17:51:44 +080019#include "psa/client.h"
Soby Mathewd7b79f22020-05-21 15:06:54 +010020
Antonio de Angelis8908f472018-08-31 15:44:25 +010021/**
22 * \brief List of possible operation types supported by the TFM based
23 * implementation. This type is needed by the operation allocation,
24 * lookup and release functions.
25 *
26 */
27enum tfm_crypto_operation_type {
28 TFM_CRYPTO_OPERATION_NONE = 0,
29 TFM_CRYPTO_CIPHER_OPERATION = 1,
30 TFM_CRYPTO_MAC_OPERATION = 2,
31 TFM_CRYPTO_HASH_OPERATION = 3,
Antonio de Angelis04debbd2019-10-14 12:12:52 +010032 TFM_CRYPTO_KEY_DERIVATION_OPERATION = 4,
Antonio de Angelisc26af632021-10-07 15:04:12 +010033 TFM_CRYPTO_AEAD_OPERATION = 5,
Antonio de Angelis8908f472018-08-31 15:44:25 +010034
35 /* Used to force the enum size */
36 TFM_CRYPTO_OPERATION_TYPE_MAX = INT_MAX
37};
38
Antonio de Angelis202425a2022-04-06 11:13:15 +010039/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010040 * \brief Initialise the service
Antonio de Angelis8908f472018-08-31 15:44:25 +010041 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000042 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010043 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000044psa_status_t tfm_crypto_init(void);
Antonio de Angelis8908f472018-08-31 15:44:25 +010045
46/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010047 * \brief Initialise the Alloc module
48 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000049 * \return Return values as described in \ref psa_status_t
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010050 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000051psa_status_t tfm_crypto_init_alloc(void);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010052
53/**
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010054 * \brief Returns the ID of the caller
55 *
56 * \param[out] id Pointer to hold the ID of the caller
57 *
58 * \return Return values as described in \ref psa_status_t
59 */
60psa_status_t tfm_crypto_get_caller_id(int32_t *id);
61
62/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000063 * \brief Allocate an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +010064 *
Antonio de Angelis4743e672019-04-11 11:38:48 +010065 * \param[in] type Type of the operation context to allocate
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010066 * \param[out] handle Pointer to hold the allocated handle
Antonio de Angelis4743e672019-04-11 11:38:48 +010067 * \param[out ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +010068 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000069 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010070 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000071psa_status_t tfm_crypto_operation_alloc(enum tfm_crypto_operation_type type,
Antonio de Angelis4743e672019-04-11 11:38:48 +010072 uint32_t *handle,
Antonio de Angelis819c2f32019-02-06 14:32:02 +000073 void **ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +010074/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000075 * \brief Release an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +010076 *
David Huc9679cc2022-06-21 13:09:34 +080077 * \param[in/out] handle Pointer to the handle of the context to release
Antonio de Angelis8908f472018-08-31 15:44:25 +010078 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000079 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010080 */
Antonio de Angelis4743e672019-04-11 11:38:48 +010081psa_status_t tfm_crypto_operation_release(uint32_t *handle);
Antonio de Angelis8908f472018-08-31 15:44:25 +010082/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000083 * \brief Look up an operation context in the backend for the corresponding
84 * frontend operation
Antonio de Angelis8908f472018-08-31 15:44:25 +010085 *
Antonio de Angelis4743e672019-04-11 11:38:48 +010086 * \param[in] type Type of the operation context to look up
87 * \param[in] handle Handle of the context to lookup
88 * \param[out] ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +010089 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000090 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010091 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000092psa_status_t tfm_crypto_operation_lookup(enum tfm_crypto_operation_type type,
Antonio de Angelis4743e672019-04-11 11:38:48 +010093 uint32_t handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000094 void **ctx);
David Huc9679cc2022-06-21 13:09:34 +080095
Antonio de Angelis202425a2022-04-06 11:13:15 +010096/**
97 * \brief This function acts as interface from the framework dispatching
98 * calls to the set of functions that implement the PSA Crypto APIs.
99 * It is based on the Uniform Signatures prototype.
100 *
101 * \param[in] in_vec Array of invec parameters
102 * \param[in] in_len Length of the valid entries in in_vec
103 * \param[out] out_vec Array of outvec parameters
104 * \param[in] out_len Length of the valid entries in out_vec
105 *
106 * \return Return values as described in \ref psa_status_t
107 */
108psa_status_t tfm_crypto_api_dispatcher(psa_invec in_vec[],
109 size_t in_len,
110 psa_outvec out_vec[],
111 size_t out_len);
112/**
113 * \brief This function acts as interface for the Key management module
114 *
115 * \param[in] in_vec Array of invec parameters
116 * \param[out] out_vec Array of outvec parameters
117 * \param[in] encoded_key Key encoded with partition_id and key_id
118 *
119 * \return Return values as described in \ref psa_status_t
120 */
121psa_status_t tfm_crypto_key_management_interface(psa_invec in_vec[],
122 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000123 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100124/**
125 * \brief This function acts as interface for the MAC module
126 *
127 * \param[in] in_vec Array of invec parameters
128 * \param[out] out_vec Array of outvec parameters
129 * \param[in] encoded_key Key encoded with partition_id and key_id
130 *
131 * \return Return values as described in \ref psa_status_t
132 */
133psa_status_t tfm_crypto_mac_interface(psa_invec in_vec[],
134 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000135 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100136/**
137 * \brief This function acts as interface for the Cipher module
138 *
139 * \param[in] in_vec Array of invec parameters
140 * \param[out] out_vec Array of outvec parameters
141 * \param[in] encoded_key Key encoded with partition_id and key_id
142 *
143 * \return Return values as described in \ref psa_status_t
144 */
145psa_status_t tfm_crypto_cipher_interface(psa_invec in_vec[],
146 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000147 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100148/**
149 * \brief This function acts as interface for the AEAD module
150 *
151 * \param[in] in_vec Array of invec parameters
152 * \param[out] out_vec Array of outvec parameters
153 * \param[in] encoded_key Key encoded with partition_id and key_id
154 *
155 * \return Return values as described in \ref psa_status_t
156 */
157psa_status_t tfm_crypto_aead_interface(psa_invec in_vec[],
158 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000159 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800160
Antonio de Angelis202425a2022-04-06 11:13:15 +0100161/**
David Hu1eb11942022-07-05 11:36:34 +0800162 * \brief This function acts as interface for the Asymmetric signing module
Antonio de Angelis202425a2022-04-06 11:13:15 +0100163 *
164 * \param[in] in_vec Array of invec parameters
165 * \param[out] out_vec Array of outvec parameters
166 * \param[in] encoded_key Key encoded with partition_id and key_id
167 *
168 * \return Return values as described in \ref psa_status_t
169 */
David Hu1eb11942022-07-05 11:36:34 +0800170psa_status_t tfm_crypto_asymmetric_sign_interface(psa_invec in_vec[],
171 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000172 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800173
174/**
175 * \brief This function acts as interface for the Asymmetric encryption module
176 *
177 * \param[in] in_vec Array of invec parameters
178 * \param[out] out_vec Array of outvec parameters
179 * \param[in] encoded_key Key encoded with partition_id and key_id
180 *
181 * \return Return values as described in \ref psa_status_t
182 */
183psa_status_t tfm_crypto_asymmetric_encrypt_interface(psa_invec in_vec[],
184 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000185 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800186
Antonio de Angelis202425a2022-04-06 11:13:15 +0100187/**
188 * \brief This function acts as interface for the Key derivation module
189 *
190 * \param[in] in_vec Array of invec parameters
191 * \param[out] out_vec Array of outvec parameters
192 * \param[in] encoded_key Key encoded with partition_id and key_id
193 *
194 * \return Return values as described in \ref psa_status_t
195 */
196psa_status_t tfm_crypto_key_derivation_interface(psa_invec in_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000197 psa_outvec out_vec[],
198 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100199/**
200 * \brief This function acts as interface for the Random module
201 *
202 * \param[in] in_vec Array of invec parameters
203 * \param[out] out_vec Array of outvec parameters
204 *
205 * \return Return values as described in \ref psa_status_t
206 */
207psa_status_t tfm_crypto_random_interface(psa_invec in_vec[],
208 psa_outvec out_vec[]);
209/**
210 * \brief This function acts as interface for the Hash module
211 *
212 * \param[in] in_vec Array of invec parameters
213 * \param[out] out_vec Array of outvec parameters
214 *
215 * \return Return values as described in \ref psa_status_t
216 */
217psa_status_t tfm_crypto_hash_interface(psa_invec in_vec[],
218 psa_outvec out_vec[]);
Jamie Foxefd82732018-11-26 10:34:32 +0000219
Antonio de Angelis8908f472018-08-31 15:44:25 +0100220#ifdef __cplusplus
221}
222#endif
223
224#endif /* __TFM_CRYPTO_API_H__ */