blob: 36a09153d277fb5d60504c80aedd7b9f8894779f [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
Antonio de Angelis377a1552018-11-22 17:02:40 +00002 * Copyright (c) 2018-2019, 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>
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000016#include "tfm_api.h"
Antonio de Angelis8908f472018-08-31 15:44:25 +010017#include "tfm_crypto_defs.h"
18#include "psa_crypto.h"
Antonio de Angelis4743e672019-04-11 11:38:48 +010019#ifdef TFM_PSA_API
20#include "psa_service.h"
21
22/**
23 * \brief This define is a function pointer type to the Uniform Signature API
24 * prototype.
25 */
26typedef psa_status_t (*tfm_crypto_us_t)(psa_invec[],size_t,psa_outvec[],size_t);
27#endif
Antonio de Angelis8908f472018-08-31 15:44:25 +010028
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000029#define UNIFORM_SIGNATURE_API(api_name) \
30 psa_status_t api_name(psa_invec[], size_t, psa_outvec[], size_t)
31
Antonio de Angelis8908f472018-08-31 15:44:25 +010032/**
33 * \brief List of possible operation types supported by the TFM based
34 * implementation. This type is needed by the operation allocation,
35 * lookup and release functions.
36 *
37 */
38enum tfm_crypto_operation_type {
39 TFM_CRYPTO_OPERATION_NONE = 0,
40 TFM_CRYPTO_CIPHER_OPERATION = 1,
41 TFM_CRYPTO_MAC_OPERATION = 2,
42 TFM_CRYPTO_HASH_OPERATION = 3,
Antonio de Angelis8908f472018-08-31 15:44:25 +010043
44 /* Used to force the enum size */
45 TFM_CRYPTO_OPERATION_TYPE_MAX = INT_MAX
46};
47
48/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010049 * \brief Initialise the service
Antonio de Angelis8908f472018-08-31 15:44:25 +010050 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000051 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010052 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000053psa_status_t tfm_crypto_init(void);
Antonio de Angelis8908f472018-08-31 15:44:25 +010054
55/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010056 * \brief Initialise the Key module
57 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000058 * \return Return values as described in \ref psa_status_t
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010059 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000060psa_status_t tfm_crypto_init_key(void);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010061
62/**
63 * \brief Initialise the Alloc module
64 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000065 * \return Return values as described in \ref psa_status_t
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010066 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000067psa_status_t tfm_crypto_init_alloc(void);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010068
69/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000070 * \brief Allocate an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +010071 *
Antonio de Angelis4743e672019-04-11 11:38:48 +010072 * \param[in] type Type of the operation context to allocate
73 * \param[out] handle Pointer to the hold the allocated handle
74 * \param[out ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +010075 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000076 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010077 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000078psa_status_t tfm_crypto_operation_alloc(enum tfm_crypto_operation_type type,
Antonio de Angelis4743e672019-04-11 11:38:48 +010079 uint32_t *handle,
Antonio de Angelis819c2f32019-02-06 14:32:02 +000080 void **ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +010081/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000082 * \brief Release an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +010083 *
Antonio de Angelis4743e672019-04-11 11:38:48 +010084 * \param[in] handle Pointer to the handle of the context to release
Antonio de Angelis8908f472018-08-31 15:44:25 +010085 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000086 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010087 */
Antonio de Angelis4743e672019-04-11 11:38:48 +010088psa_status_t tfm_crypto_operation_release(uint32_t *handle);
Antonio de Angelis8908f472018-08-31 15:44:25 +010089/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000090 * \brief Look up an operation context in the backend for the corresponding
91 * frontend operation
Antonio de Angelis8908f472018-08-31 15:44:25 +010092 *
Antonio de Angelis4743e672019-04-11 11:38:48 +010093 * \param[in] type Type of the operation context to look up
94 * \param[in] handle Handle of the context to lookup
95 * \param[out] ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +010096 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000097 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010098 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000099psa_status_t tfm_crypto_operation_lookup(enum tfm_crypto_operation_type type,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100100 uint32_t handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000101 void **ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100102/**
Jamie Foxefd82732018-11-26 10:34:32 +0000103 * \brief Retrieve a key from the provided key slot according to the key
104 * policy and algorithm provided. This function is expected to be
105 * called intra-service
106 *
107 * \param[in] key Key slot
108 * \param[in] usage Usage policy to be used on the retrieved key
109 * \param[in] alg Algorithm to be used for the retrieved key
110 * \param[out] data Buffer to hold the exported key
111 * \param[in] data_size Length of the buffer pointed to by data
112 * \param[out] data_length Length of the exported key
113 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000114 * \return Return values as described in \ref psa_status_t
Jamie Foxefd82732018-11-26 10:34:32 +0000115 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000116psa_status_t tfm_crypto_get_key(psa_key_slot_t key,
117 psa_key_usage_t usage,
118 psa_algorithm_t alg,
119 uint8_t *data,
120 size_t data_size,
121 size_t *data_length);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100122
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000123#define LIST_TFM_CRYPTO_UNIFORM_SIGNATURE_API \
124 X(tfm_crypto_import_key); \
125 X(tfm_crypto_destroy_key); \
126 X(tfm_crypto_get_key_information); \
127 X(tfm_crypto_export_key); \
128 X(tfm_crypto_key_policy_init); \
129 X(tfm_crypto_key_policy_set_usage); \
130 X(tfm_crypto_key_policy_get_usage); \
131 X(tfm_crypto_key_policy_get_algorithm); \
132 X(tfm_crypto_set_key_policy); \
133 X(tfm_crypto_get_key_policy); \
134 X(tfm_crypto_set_key_lifetime); \
135 X(tfm_crypto_get_key_lifetime); \
136 X(tfm_crypto_export_public_key); \
137 X(tfm_crypto_cipher_set_iv); \
138 X(tfm_crypto_cipher_encrypt_setup); \
139 X(tfm_crypto_cipher_decrypt_setup); \
140 X(tfm_crypto_cipher_update); \
141 X(tfm_crypto_cipher_finish); \
142 X(tfm_crypto_cipher_abort); \
143 X(tfm_crypto_hash_setup); \
144 X(tfm_crypto_hash_update); \
145 X(tfm_crypto_hash_finish); \
146 X(tfm_crypto_hash_verify); \
147 X(tfm_crypto_hash_abort); \
148 X(tfm_crypto_mac_sign_setup); \
149 X(tfm_crypto_mac_verify_setup); \
150 X(tfm_crypto_mac_update); \
151 X(tfm_crypto_mac_sign_finish); \
152 X(tfm_crypto_mac_verify_finish); \
153 X(tfm_crypto_mac_abort); \
154 X(tfm_crypto_aead_encrypt); \
155 X(tfm_crypto_aead_decrypt); \
Jamie Foxefd82732018-11-26 10:34:32 +0000156
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000157#define X(api_name) UNIFORM_SIGNATURE_API(api_name)
158LIST_TFM_CRYPTO_UNIFORM_SIGNATURE_API
159#undef X
Jamie Foxefd82732018-11-26 10:34:32 +0000160
Antonio de Angelis8908f472018-08-31 15:44:25 +0100161#ifdef __cplusplus
162}
163#endif
164
165#endif /* __TFM_CRYPTO_API_H__ */