blob: 5e6ffbd90d8cafa250d4ceba22844018f7d33c69 [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"
19
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000020#define UNIFORM_SIGNATURE_API(api_name) \
21 psa_status_t api_name(psa_invec[], size_t, psa_outvec[], size_t)
22
Antonio de Angelis8908f472018-08-31 15:44:25 +010023/**
24 * \brief List of possible operation types supported by the TFM based
25 * implementation. This type is needed by the operation allocation,
26 * lookup and release functions.
27 *
28 */
29enum tfm_crypto_operation_type {
30 TFM_CRYPTO_OPERATION_NONE = 0,
31 TFM_CRYPTO_CIPHER_OPERATION = 1,
32 TFM_CRYPTO_MAC_OPERATION = 2,
33 TFM_CRYPTO_HASH_OPERATION = 3,
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
39/**
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 Key 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_key(void);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010052
53/**
54 * \brief Initialise the Alloc module
55 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000056 * \return Return values as described in \ref psa_status_t
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010057 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000058psa_status_t tfm_crypto_init_alloc(void);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010059
60/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000061 * \brief Allocate an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +010062 *
Antonio de Angelis819c2f32019-02-06 14:32:02 +000063 * \param[in] type Type of the operation context to allocate
64 * \param[out] oper Pointer to the frontend operation
65 * \param[out ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +010066 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000067 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010068 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000069psa_status_t tfm_crypto_operation_alloc(enum tfm_crypto_operation_type type,
Antonio de Angelis819c2f32019-02-06 14:32:02 +000070 void *oper,
71 void **ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +010072/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000073 * \brief Release an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +010074 *
Antonio de Angelis819c2f32019-02-06 14:32:02 +000075 * \param[in] type Type of the operation context to release
76 * \param[in/out] oper Pointer to the frontend operation for the release
77 * of the corresponding backend context
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 Angelisab85ccd2019-03-25 15:14:29 +000081psa_status_t tfm_crypto_operation_release(enum tfm_crypto_operation_type type,
82 void *oper);
Antonio de Angelis8908f472018-08-31 15:44:25 +010083/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000084 * \brief Look up an operation context in the backend for the corresponding
85 * frontend operation
Antonio de Angelis8908f472018-08-31 15:44:25 +010086 *
Antonio de Angelis819c2f32019-02-06 14:32:02 +000087 * \param[in] type Type of the operation context to look up
88 * \param[in] oper Pointer to the frontend operation
89 * \param[out] ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +010090 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000091 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010092 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000093psa_status_t tfm_crypto_operation_lookup(enum tfm_crypto_operation_type type,
94 const void *oper,
95 void **ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +010096/**
Jamie Foxefd82732018-11-26 10:34:32 +000097 * \brief Retrieve a key from the provided key slot according to the key
98 * policy and algorithm provided. This function is expected to be
99 * called intra-service
100 *
101 * \param[in] key Key slot
102 * \param[in] usage Usage policy to be used on the retrieved key
103 * \param[in] alg Algorithm to be used for the retrieved key
104 * \param[out] data Buffer to hold the exported key
105 * \param[in] data_size Length of the buffer pointed to by data
106 * \param[out] data_length Length of the exported key
107 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000108 * \return Return values as described in \ref psa_status_t
Jamie Foxefd82732018-11-26 10:34:32 +0000109 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000110psa_status_t tfm_crypto_get_key(psa_key_slot_t key,
111 psa_key_usage_t usage,
112 psa_algorithm_t alg,
113 uint8_t *data,
114 size_t data_size,
115 size_t *data_length);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100116
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000117#define LIST_TFM_CRYPTO_UNIFORM_SIGNATURE_API \
118 X(tfm_crypto_import_key); \
119 X(tfm_crypto_destroy_key); \
120 X(tfm_crypto_get_key_information); \
121 X(tfm_crypto_export_key); \
122 X(tfm_crypto_key_policy_init); \
123 X(tfm_crypto_key_policy_set_usage); \
124 X(tfm_crypto_key_policy_get_usage); \
125 X(tfm_crypto_key_policy_get_algorithm); \
126 X(tfm_crypto_set_key_policy); \
127 X(tfm_crypto_get_key_policy); \
128 X(tfm_crypto_set_key_lifetime); \
129 X(tfm_crypto_get_key_lifetime); \
130 X(tfm_crypto_export_public_key); \
131 X(tfm_crypto_cipher_set_iv); \
132 X(tfm_crypto_cipher_encrypt_setup); \
133 X(tfm_crypto_cipher_decrypt_setup); \
134 X(tfm_crypto_cipher_update); \
135 X(tfm_crypto_cipher_finish); \
136 X(tfm_crypto_cipher_abort); \
137 X(tfm_crypto_hash_setup); \
138 X(tfm_crypto_hash_update); \
139 X(tfm_crypto_hash_finish); \
140 X(tfm_crypto_hash_verify); \
141 X(tfm_crypto_hash_abort); \
142 X(tfm_crypto_mac_sign_setup); \
143 X(tfm_crypto_mac_verify_setup); \
144 X(tfm_crypto_mac_update); \
145 X(tfm_crypto_mac_sign_finish); \
146 X(tfm_crypto_mac_verify_finish); \
147 X(tfm_crypto_mac_abort); \
148 X(tfm_crypto_aead_encrypt); \
149 X(tfm_crypto_aead_decrypt); \
Jamie Foxefd82732018-11-26 10:34:32 +0000150
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000151#define X(api_name) UNIFORM_SIGNATURE_API(api_name)
152LIST_TFM_CRYPTO_UNIFORM_SIGNATURE_API
153#undef X
Jamie Foxefd82732018-11-26 10:34:32 +0000154
Antonio de Angelis8908f472018-08-31 15:44:25 +0100155#ifdef __cplusplus
156}
157#endif
158
159#endif /* __TFM_CRYPTO_API_H__ */