Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 1 | /* |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, Arm Limited. All rights reserved. |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 3 | * |
| 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 |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
| 15 | #include <stdint.h> |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 16 | #include "tfm_api.h" |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 17 | #include "tfm_crypto_defs.h" |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 18 | #include "psa/crypto.h" |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 19 | #ifdef TFM_PSA_API |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 20 | #include "psa/service.h" |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * \brief This define is a function pointer type to the Uniform Signature API |
| 24 | * prototype. |
| 25 | */ |
| 26 | typedef psa_status_t (*tfm_crypto_us_t)(psa_invec[],size_t,psa_outvec[],size_t); |
| 27 | #endif |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 28 | |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 29 | #define UNIFORM_SIGNATURE_API(api_name) \ |
| 30 | psa_status_t api_name(psa_invec[], size_t, psa_outvec[], size_t) |
| 31 | |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 32 | /** |
| 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 | */ |
| 38 | enum 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 Angelis | 25e2b2d | 2019-04-25 14:49:50 +0100 | [diff] [blame] | 43 | TFM_CRYPTO_GENERATOR_OPERATION = 4, |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 44 | |
| 45 | /* Used to force the enum size */ |
| 46 | TFM_CRYPTO_OPERATION_TYPE_MAX = INT_MAX |
| 47 | }; |
| 48 | |
| 49 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 50 | * \brief Initialise the service |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 51 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 52 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 53 | */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 54 | psa_status_t tfm_crypto_init(void); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 55 | |
| 56 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 57 | * \brief Initialise the Alloc module |
| 58 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 59 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 60 | */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 61 | psa_status_t tfm_crypto_init_alloc(void); |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 62 | |
| 63 | /** |
Antonio de Angelis | 60a6fe6 | 2019-06-18 15:27:34 +0100 | [diff] [blame] | 64 | * \brief Returns the ID of the caller |
| 65 | * |
| 66 | * \param[out] id Pointer to hold the ID of the caller |
| 67 | * |
| 68 | * \return Return values as described in \ref psa_status_t |
| 69 | */ |
| 70 | psa_status_t tfm_crypto_get_caller_id(int32_t *id); |
| 71 | |
| 72 | /** |
| 73 | * \brief Checks that the requested handle belongs to the requesting |
| 74 | * partition |
| 75 | * |
| 76 | * \param[in] handle Handle given as input |
| 77 | * \param[out] index Optionally, pointer to hold the internal index |
| 78 | * corresponding to the input handle. Valid only |
| 79 | * on PSA_SUCCESS, it's returned only if the input |
| 80 | * parameter is not NULL. |
| 81 | * |
| 82 | * \return Return values as described in \ref psa_status_t |
| 83 | */ |
| 84 | psa_status_t tfm_crypto_check_handle_owner(psa_key_handle_t handle, |
| 85 | uint32_t *index); |
| 86 | /** |
Antonio de Angelis | 819c2f3 | 2019-02-06 14:32:02 +0000 | [diff] [blame] | 87 | * \brief Allocate an operation context in the backend |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 88 | * |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 89 | * \param[in] type Type of the operation context to allocate |
Antonio de Angelis | 60a6fe6 | 2019-06-18 15:27:34 +0100 | [diff] [blame] | 90 | * \param[out] handle Pointer to hold the allocated handle |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 91 | * \param[out ctx Double pointer to the corresponding context |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 92 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 93 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 94 | */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 95 | psa_status_t tfm_crypto_operation_alloc(enum tfm_crypto_operation_type type, |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 96 | uint32_t *handle, |
Antonio de Angelis | 819c2f3 | 2019-02-06 14:32:02 +0000 | [diff] [blame] | 97 | void **ctx); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 98 | /** |
Antonio de Angelis | 819c2f3 | 2019-02-06 14:32:02 +0000 | [diff] [blame] | 99 | * \brief Release an operation context in the backend |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 100 | * |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 101 | * \param[in] handle Pointer to the handle of the context to release |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 102 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 103 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 104 | */ |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 105 | psa_status_t tfm_crypto_operation_release(uint32_t *handle); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 106 | /** |
Antonio de Angelis | 819c2f3 | 2019-02-06 14:32:02 +0000 | [diff] [blame] | 107 | * \brief Look up an operation context in the backend for the corresponding |
| 108 | * frontend operation |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 109 | * |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 110 | * \param[in] type Type of the operation context to look up |
| 111 | * \param[in] handle Handle of the context to lookup |
| 112 | * \param[out] ctx Double pointer to the corresponding context |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 113 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 114 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 115 | */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 116 | psa_status_t tfm_crypto_operation_lookup(enum tfm_crypto_operation_type type, |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 117 | uint32_t handle, |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 118 | void **ctx); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 119 | |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 120 | #define LIST_TFM_CRYPTO_UNIFORM_SIGNATURE_API \ |
Antonio de Angelis | 25e2b2d | 2019-04-25 14:49:50 +0100 | [diff] [blame] | 121 | X(tfm_crypto_allocate_key) \ |
Jamie Fox | dadb4e8 | 2019-09-03 17:59:41 +0100 | [diff] [blame^] | 122 | X(tfm_crypto_open_key) \ |
| 123 | X(tfm_crypto_close_key) \ |
Antonio de Angelis | 25e2b2d | 2019-04-25 14:49:50 +0100 | [diff] [blame] | 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_export_public_key) \ |
| 129 | X(tfm_crypto_copy_key) \ |
| 130 | X(tfm_crypto_set_key_policy) \ |
| 131 | X(tfm_crypto_get_key_policy) \ |
| 132 | X(tfm_crypto_get_key_lifetime) \ |
| 133 | X(tfm_crypto_cipher_generate_iv) \ |
| 134 | X(tfm_crypto_cipher_set_iv) \ |
| 135 | X(tfm_crypto_cipher_encrypt_setup) \ |
| 136 | X(tfm_crypto_cipher_decrypt_setup) \ |
| 137 | X(tfm_crypto_cipher_update) \ |
| 138 | X(tfm_crypto_cipher_abort) \ |
| 139 | X(tfm_crypto_cipher_finish) \ |
| 140 | X(tfm_crypto_hash_setup) \ |
| 141 | X(tfm_crypto_hash_update) \ |
| 142 | X(tfm_crypto_hash_finish) \ |
| 143 | X(tfm_crypto_hash_verify) \ |
| 144 | X(tfm_crypto_hash_abort) \ |
| 145 | X(tfm_crypto_hash_clone) \ |
| 146 | X(tfm_crypto_mac_sign_setup) \ |
| 147 | X(tfm_crypto_mac_verify_setup) \ |
| 148 | X(tfm_crypto_mac_update) \ |
| 149 | X(tfm_crypto_mac_sign_finish) \ |
| 150 | X(tfm_crypto_mac_verify_finish) \ |
| 151 | X(tfm_crypto_mac_abort) \ |
| 152 | X(tfm_crypto_aead_encrypt) \ |
| 153 | X(tfm_crypto_aead_decrypt) \ |
| 154 | X(tfm_crypto_asymmetric_sign) \ |
| 155 | X(tfm_crypto_asymmetric_verify) \ |
| 156 | X(tfm_crypto_asymmetric_encrypt) \ |
| 157 | X(tfm_crypto_asymmetric_decrypt) \ |
| 158 | X(tfm_crypto_get_generator_capacity) \ |
| 159 | X(tfm_crypto_generator_read) \ |
| 160 | X(tfm_crypto_generator_import_key) \ |
| 161 | X(tfm_crypto_generator_abort) \ |
| 162 | X(tfm_crypto_key_derivation) \ |
| 163 | X(tfm_crypto_key_agreement) \ |
| 164 | X(tfm_crypto_generate_random) \ |
| 165 | X(tfm_crypto_generate_key) \ |
Jamie Fox | efd8273 | 2018-11-26 10:34:32 +0000 | [diff] [blame] | 166 | |
Antonio de Angelis | 25e2b2d | 2019-04-25 14:49:50 +0100 | [diff] [blame] | 167 | #define X(api_name) UNIFORM_SIGNATURE_API(api_name); |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 168 | LIST_TFM_CRYPTO_UNIFORM_SIGNATURE_API |
| 169 | #undef X |
Jamie Fox | efd8273 | 2018-11-26 10:34:32 +0000 | [diff] [blame] | 170 | |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 171 | #ifdef __cplusplus |
| 172 | } |
| 173 | #endif |
| 174 | |
| 175 | #endif /* __TFM_CRYPTO_API_H__ */ |