blob: e1d0f1d2029d2b9697199a9850a259f5bb1c5736 [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 Angelis25e2b2d2019-04-25 14:49:50 +010043 TFM_CRYPTO_GENERATOR_OPERATION = 4,
Antonio de Angelis8908f472018-08-31 15:44:25 +010044
45 /* Used to force the enum size */
46 TFM_CRYPTO_OPERATION_TYPE_MAX = INT_MAX
47};
48
49/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010050 * \brief Initialise the service
Antonio de Angelis8908f472018-08-31 15:44:25 +010051 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000052 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010053 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000054psa_status_t tfm_crypto_init(void);
Antonio de Angelis8908f472018-08-31 15:44:25 +010055
56/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010057 * \brief Initialise the Alloc module
58 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000059 * \return Return values as described in \ref psa_status_t
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010060 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000061psa_status_t tfm_crypto_init_alloc(void);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010062
63/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000064 * \brief Allocate an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +010065 *
Antonio de Angelis4743e672019-04-11 11:38:48 +010066 * \param[in] type Type of the operation context to allocate
67 * \param[out] handle Pointer to the hold the allocated handle
68 * \param[out ctx Double pointer to the corresponding context
Antonio de Angelis8908f472018-08-31 15:44:25 +010069 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000070 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010071 */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000072psa_status_t tfm_crypto_operation_alloc(enum tfm_crypto_operation_type type,
Antonio de Angelis4743e672019-04-11 11:38:48 +010073 uint32_t *handle,
Antonio de Angelis819c2f32019-02-06 14:32:02 +000074 void **ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +010075/**
Antonio de Angelis819c2f32019-02-06 14:32:02 +000076 * \brief Release an operation context in the backend
Antonio de Angelis8908f472018-08-31 15:44:25 +010077 *
Antonio de Angelis4743e672019-04-11 11:38:48 +010078 * \param[in] handle Pointer to the handle of the context to release
Antonio de Angelis8908f472018-08-31 15:44:25 +010079 *
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000080 * \return Return values as described in \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010081 */
Antonio de Angelis4743e672019-04-11 11:38:48 +010082psa_status_t tfm_crypto_operation_release(uint32_t *handle);
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 Angelis4743e672019-04-11 11:38:48 +010087 * \param[in] type Type of the operation context to look up
88 * \param[in] handle Handle of the context to lookup
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,
Antonio de Angelis4743e672019-04-11 11:38:48 +010094 uint32_t handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000095 void **ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +010096
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000097#define LIST_TFM_CRYPTO_UNIFORM_SIGNATURE_API \
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +010098 X(tfm_crypto_allocate_key) \
99 X(tfm_crypto_import_key) \
100 X(tfm_crypto_destroy_key) \
101 X(tfm_crypto_get_key_information) \
102 X(tfm_crypto_export_key) \
103 X(tfm_crypto_export_public_key) \
104 X(tfm_crypto_copy_key) \
105 X(tfm_crypto_set_key_policy) \
106 X(tfm_crypto_get_key_policy) \
107 X(tfm_crypto_get_key_lifetime) \
108 X(tfm_crypto_cipher_generate_iv) \
109 X(tfm_crypto_cipher_set_iv) \
110 X(tfm_crypto_cipher_encrypt_setup) \
111 X(tfm_crypto_cipher_decrypt_setup) \
112 X(tfm_crypto_cipher_update) \
113 X(tfm_crypto_cipher_abort) \
114 X(tfm_crypto_cipher_finish) \
115 X(tfm_crypto_hash_setup) \
116 X(tfm_crypto_hash_update) \
117 X(tfm_crypto_hash_finish) \
118 X(tfm_crypto_hash_verify) \
119 X(tfm_crypto_hash_abort) \
120 X(tfm_crypto_hash_clone) \
121 X(tfm_crypto_mac_sign_setup) \
122 X(tfm_crypto_mac_verify_setup) \
123 X(tfm_crypto_mac_update) \
124 X(tfm_crypto_mac_sign_finish) \
125 X(tfm_crypto_mac_verify_finish) \
126 X(tfm_crypto_mac_abort) \
127 X(tfm_crypto_aead_encrypt) \
128 X(tfm_crypto_aead_decrypt) \
129 X(tfm_crypto_asymmetric_sign) \
130 X(tfm_crypto_asymmetric_verify) \
131 X(tfm_crypto_asymmetric_encrypt) \
132 X(tfm_crypto_asymmetric_decrypt) \
133 X(tfm_crypto_get_generator_capacity) \
134 X(tfm_crypto_generator_read) \
135 X(tfm_crypto_generator_import_key) \
136 X(tfm_crypto_generator_abort) \
137 X(tfm_crypto_key_derivation) \
138 X(tfm_crypto_key_agreement) \
139 X(tfm_crypto_generate_random) \
140 X(tfm_crypto_generate_key) \
Jamie Foxefd82732018-11-26 10:34:32 +0000141
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100142#define X(api_name) UNIFORM_SIGNATURE_API(api_name);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000143LIST_TFM_CRYPTO_UNIFORM_SIGNATURE_API
144#undef X
Jamie Foxefd82732018-11-26 10:34:32 +0000145
Antonio de Angelis8908f472018-08-31 15:44:25 +0100146#ifdef __cplusplus
147}
148#endif
149
150#endif /* __TFM_CRYPTO_API_H__ */