blob: 74b0624a15f328378e31d6c73ec49c08e0cab61e [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
Antonio de Angelis04debbd2019-10-14 12:12:52 +01002 * Copyright (c) 2018-2020, 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 Angelis4743e672019-04-11 11:38:48 +010017#ifdef TFM_PSA_API
Jamie Foxcc31d402019-01-28 17:13:52 +000018#include "psa/service.h"
Antonio de Angelis4743e672019-04-11 11:38:48 +010019
20/**
21 * \brief This define is a function pointer type to the Uniform Signature API
22 * prototype.
23 */
24typedef psa_status_t (*tfm_crypto_us_t)(psa_invec[],size_t,psa_outvec[],size_t);
25#endif
Antonio de Angelis8908f472018-08-31 15:44:25 +010026
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000027#define UNIFORM_SIGNATURE_API(api_name) \
28 psa_status_t api_name(psa_invec[], size_t, psa_outvec[], size_t)
29
Antonio de Angelis8908f472018-08-31 15:44:25 +010030/**
31 * \brief List of possible operation types supported by the TFM based
32 * implementation. This type is needed by the operation allocation,
33 * lookup and release functions.
34 *
35 */
36enum tfm_crypto_operation_type {
37 TFM_CRYPTO_OPERATION_NONE = 0,
38 TFM_CRYPTO_CIPHER_OPERATION = 1,
39 TFM_CRYPTO_MAC_OPERATION = 2,
40 TFM_CRYPTO_HASH_OPERATION = 3,
Antonio de Angelis04debbd2019-10-14 12:12:52 +010041 TFM_CRYPTO_KEY_DERIVATION_OPERATION = 4,
Antonio de Angelis8908f472018-08-31 15:44:25 +010042
43 /* Used to force the enum size */
44 TFM_CRYPTO_OPERATION_TYPE_MAX = INT_MAX
45};
46
47/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010048 * \brief Initialise the service
Antonio de Angelis8908f472018-08-31 15:44:25 +010049 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000050 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010051 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000052psa_status_t tfm_crypto_init(void);
Antonio de Angelis8908f472018-08-31 15:44:25 +010053
54/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010055 * \brief Initialise the Alloc module
56 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000057 * \return Return values as described in \ref psa_status_t
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010058 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000059psa_status_t tfm_crypto_init_alloc(void);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010060
61/**
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010062 * \brief Returns the ID of the caller
63 *
64 * \param[out] id Pointer to hold the ID of the caller
65 *
66 * \return Return values as described in \ref psa_status_t
67 */
68psa_status_t tfm_crypto_get_caller_id(int32_t *id);
69
70/**
71 * \brief Checks that the requested handle belongs to the requesting
72 * partition
73 *
74 * \param[in] handle Handle given as input
75 * \param[out] index Optionally, pointer to hold the internal index
76 * corresponding to the input handle. Valid only
77 * on PSA_SUCCESS, it's returned only if the input
78 * parameter is not NULL.
79 *
80 * \return Return values as described in \ref psa_status_t
81 */
82psa_status_t tfm_crypto_check_handle_owner(psa_key_handle_t handle,
83 uint32_t *index);
Antonio de Angelis04debbd2019-10-14 12:12:52 +010084
85/**
Jamie Fox99360e82020-02-20 16:00:09 +000086 * \brief Checks that there is enough local storage in RAM to keep another key,
87 * and returns the index of the storage to use.
Antonio de Angelis04debbd2019-10-14 12:12:52 +010088 *
Jamie Fox99360e82020-02-20 16:00:09 +000089 * \param[out] index Index of the local storage to use
Antonio de Angelis04debbd2019-10-14 12:12:52 +010090 *
91 * \return Return values as described in \ref psa_status_t
92 */
Jamie Fox99360e82020-02-20 16:00:09 +000093psa_status_t tfm_crypto_check_key_storage(uint32_t *index);
Antonio de Angelis04debbd2019-10-14 12:12:52 +010094
95/**
Jamie Fox99360e82020-02-20 16:00:09 +000096 * \brief Sets the index of the local storage in use with a key requested by the
97 * calling partition, and stores the corresponding key_handle.
Antonio de Angelis04debbd2019-10-14 12:12:52 +010098 *
Jamie Fox99360e82020-02-20 16:00:09 +000099 * \param[in] index Index of the local storage to use
100 * \param[in] key_handle Corresponding key handle to associate
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100101 *
102 * \return Return values as described in \ref psa_status_t
103 */
Jamie Fox99360e82020-02-20 16:00:09 +0000104psa_status_t tfm_crypto_set_key_storage(uint32_t index,
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100105 psa_key_handle_t key_handle);
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100106/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +0000107 * \brief Allocate an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +0100108 *
Antonio de Angelis4743e672019-04-11 11:38:48 +0100109 * \param[in] type Type of the operation context to allocate
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100110 * \param[out] handle Pointer to hold the allocated handle
Antonio de Angelis4743e672019-04-11 11:38:48 +0100111 * \param[out ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +0100112 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000113 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100114 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000115psa_status_t tfm_crypto_operation_alloc(enum tfm_crypto_operation_type type,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100116 uint32_t *handle,
Antonio de Angelis819c2f32019-02-06 14:32:02 +0000117 void **ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100118/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +0000119 * \brief Release an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +0100120 *
Antonio de Angelis4743e672019-04-11 11:38:48 +0100121 * \param[in] handle Pointer to the handle of the context to release
Antonio de Angelis8908f472018-08-31 15:44:25 +0100122 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000123 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100124 */
Antonio de Angelis4743e672019-04-11 11:38:48 +0100125psa_status_t tfm_crypto_operation_release(uint32_t *handle);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100126/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +0000127 * \brief Look up an operation context in the backend for the corresponding
128 * frontend operation
Antonio de Angelis8908f472018-08-31 15:44:25 +0100129 *
Antonio de Angelis4743e672019-04-11 11:38:48 +0100130 * \param[in] type Type of the operation context to look up
131 * \param[in] handle Handle of the context to lookup
132 * \param[out] ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +0100133 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000134 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100135 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000136psa_status_t tfm_crypto_operation_lookup(enum tfm_crypto_operation_type type,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100137 uint32_t handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000138 void **ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100139
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000140#define LIST_TFM_CRYPTO_UNIFORM_SIGNATURE_API \
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100141 X(tfm_crypto_get_key_attributes) \
142 X(tfm_crypto_reset_key_attributes) \
Jamie Foxdadb4e82019-09-03 17:59:41 +0100143 X(tfm_crypto_open_key) \
144 X(tfm_crypto_close_key) \
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100145 X(tfm_crypto_import_key) \
146 X(tfm_crypto_destroy_key) \
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100147 X(tfm_crypto_export_key) \
148 X(tfm_crypto_export_public_key) \
149 X(tfm_crypto_copy_key) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100150 X(tfm_crypto_hash_compute) \
151 X(tfm_crypto_hash_compare) \
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100152 X(tfm_crypto_hash_setup) \
153 X(tfm_crypto_hash_update) \
154 X(tfm_crypto_hash_finish) \
155 X(tfm_crypto_hash_verify) \
156 X(tfm_crypto_hash_abort) \
157 X(tfm_crypto_hash_clone) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100158 X(tfm_crypto_mac_compute) \
159 X(tfm_crypto_mac_verify) \
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100160 X(tfm_crypto_mac_sign_setup) \
161 X(tfm_crypto_mac_verify_setup) \
162 X(tfm_crypto_mac_update) \
163 X(tfm_crypto_mac_sign_finish) \
164 X(tfm_crypto_mac_verify_finish) \
165 X(tfm_crypto_mac_abort) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100166 X(tfm_crypto_cipher_encrypt) \
167 X(tfm_crypto_cipher_decrypt) \
168 X(tfm_crypto_cipher_encrypt_setup) \
169 X(tfm_crypto_cipher_decrypt_setup) \
170 X(tfm_crypto_cipher_generate_iv) \
171 X(tfm_crypto_cipher_set_iv) \
172 X(tfm_crypto_cipher_update) \
173 X(tfm_crypto_cipher_finish) \
174 X(tfm_crypto_cipher_abort) \
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100175 X(tfm_crypto_aead_encrypt) \
176 X(tfm_crypto_aead_decrypt) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100177 X(tfm_crypto_aead_encrypt_setup) \
178 X(tfm_crypto_aead_decrypt_setup) \
179 X(tfm_crypto_aead_generate_nonce) \
180 X(tfm_crypto_aead_set_nonce) \
181 X(tfm_crypto_aead_set_lengths) \
182 X(tfm_crypto_aead_update_ad) \
183 X(tfm_crypto_aead_update) \
184 X(tfm_crypto_aead_finish) \
185 X(tfm_crypto_aead_verify) \
186 X(tfm_crypto_aead_abort) \
187 X(tfm_crypto_sign_hash) \
188 X(tfm_crypto_verify_hash) \
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100189 X(tfm_crypto_asymmetric_encrypt) \
190 X(tfm_crypto_asymmetric_decrypt) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100191 X(tfm_crypto_key_derivation_setup) \
192 X(tfm_crypto_key_derivation_get_capacity) \
193 X(tfm_crypto_key_derivation_set_capacity) \
194 X(tfm_crypto_key_derivation_input_bytes) \
195 X(tfm_crypto_key_derivation_input_key) \
196 X(tfm_crypto_key_derivation_key_agreement)\
197 X(tfm_crypto_key_derivation_output_bytes) \
198 X(tfm_crypto_key_derivation_output_key) \
199 X(tfm_crypto_key_derivation_abort) \
200 X(tfm_crypto_raw_key_agreement) \
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100201 X(tfm_crypto_generate_random) \
202 X(tfm_crypto_generate_key) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100203 X(tfm_crypto_set_key_domain_parameters) \
204 X(tfm_crypto_get_key_domain_parameters) \
Jamie Foxefd82732018-11-26 10:34:32 +0000205
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100206#define X(api_name) UNIFORM_SIGNATURE_API(api_name);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000207LIST_TFM_CRYPTO_UNIFORM_SIGNATURE_API
208#undef X
Jamie Foxefd82732018-11-26 10:34:32 +0000209
Antonio de Angelis8908f472018-08-31 15:44:25 +0100210#ifdef __cplusplus
211}
212#endif
213
214#endif /* __TFM_CRYPTO_API_H__ */