blob: b207820dd57ebfc85791f8ae55cbd899f850ba0c [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);
Antonio de Angelis202425a2022-04-06 11:13:15 +010095/**
96 * \brief This function acts as interface for the Key management module
97 *
98 * \param[in] in_vec Array of invec parameters
99 * \param[out] out_vec Array of outvec parameters
100 * \param[in] encoded_key Key encoded with partition_id and key_id
101 *
102 * \return Return values as described in \ref psa_status_t
103 */
104psa_status_t tfm_crypto_key_management_interface(psa_invec in_vec[],
105 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000106 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100107/**
108 * \brief This function acts as interface for the MAC module
109 *
110 * \param[in] in_vec Array of invec parameters
111 * \param[out] out_vec Array of outvec parameters
112 * \param[in] encoded_key Key encoded with partition_id and key_id
113 *
114 * \return Return values as described in \ref psa_status_t
115 */
116psa_status_t tfm_crypto_mac_interface(psa_invec in_vec[],
117 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000118 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100119/**
120 * \brief This function acts as interface for the Cipher module
121 *
122 * \param[in] in_vec Array of invec parameters
123 * \param[out] out_vec Array of outvec parameters
124 * \param[in] encoded_key Key encoded with partition_id and key_id
125 *
126 * \return Return values as described in \ref psa_status_t
127 */
128psa_status_t tfm_crypto_cipher_interface(psa_invec in_vec[],
129 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000130 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100131/**
132 * \brief This function acts as interface for the AEAD module
133 *
134 * \param[in] in_vec Array of invec parameters
135 * \param[out] out_vec Array of outvec parameters
136 * \param[in] encoded_key Key encoded with partition_id and key_id
137 *
138 * \return Return values as described in \ref psa_status_t
139 */
140psa_status_t tfm_crypto_aead_interface(psa_invec in_vec[],
141 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000142 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800143
Antonio de Angelis202425a2022-04-06 11:13:15 +0100144/**
David Hu1eb11942022-07-05 11:36:34 +0800145 * \brief This function acts as interface for the Asymmetric signing module
Antonio de Angelis202425a2022-04-06 11:13:15 +0100146 *
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 */
David Hu1eb11942022-07-05 11:36:34 +0800153psa_status_t tfm_crypto_asymmetric_sign_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);
David Hu1eb11942022-07-05 11:36:34 +0800156
157/**
158 * \brief This function acts as interface for the Asymmetric encryption module
159 *
160 * \param[in] in_vec Array of invec parameters
161 * \param[out] out_vec Array of outvec parameters
162 * \param[in] encoded_key Key encoded with partition_id and key_id
163 *
164 * \return Return values as described in \ref psa_status_t
165 */
166psa_status_t tfm_crypto_asymmetric_encrypt_interface(psa_invec in_vec[],
167 psa_outvec out_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000168 struct tfm_crypto_key_id_s *encoded_key);
David Hu1eb11942022-07-05 11:36:34 +0800169
Antonio de Angelis202425a2022-04-06 11:13:15 +0100170/**
171 * \brief This function acts as interface for the Key derivation module
172 *
173 * \param[in] in_vec Array of invec parameters
174 * \param[out] out_vec Array of outvec parameters
175 * \param[in] encoded_key Key encoded with partition_id and key_id
176 *
177 * \return Return values as described in \ref psa_status_t
178 */
179psa_status_t tfm_crypto_key_derivation_interface(psa_invec in_vec[],
Antonio de Angelis7557e682022-11-30 15:37:51 +0000180 psa_outvec out_vec[],
181 struct tfm_crypto_key_id_s *encoded_key);
Antonio de Angelis202425a2022-04-06 11:13:15 +0100182/**
183 * \brief This function acts as interface for the Random module
184 *
185 * \param[in] in_vec Array of invec parameters
186 * \param[out] out_vec Array of outvec parameters
187 *
188 * \return Return values as described in \ref psa_status_t
189 */
190psa_status_t tfm_crypto_random_interface(psa_invec in_vec[],
191 psa_outvec out_vec[]);
192/**
193 * \brief This function acts as interface for the Hash module
194 *
195 * \param[in] in_vec Array of invec parameters
196 * \param[out] out_vec Array of outvec parameters
197 *
198 * \return Return values as described in \ref psa_status_t
199 */
200psa_status_t tfm_crypto_hash_interface(psa_invec in_vec[],
201 psa_outvec out_vec[]);
Jamie Foxefd82732018-11-26 10:34:32 +0000202
Antonio de Angelis8908f472018-08-31 15:44:25 +0100203#ifdef __cplusplus
204}
205#endif
206
207#endif /* __TFM_CRYPTO_API_H__ */