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" |
| 18 | #include "psa_crypto.h" |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 19 | #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 | */ |
| 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 | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 43 | |
| 44 | /* Used to force the enum size */ |
| 45 | TFM_CRYPTO_OPERATION_TYPE_MAX = INT_MAX |
| 46 | }; |
| 47 | |
| 48 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 49 | * \brief Initialise the service |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 50 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 51 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 52 | */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 53 | psa_status_t tfm_crypto_init(void); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 54 | |
| 55 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 56 | * \brief Initialise the Alloc module |
| 57 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 58 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 59 | */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 60 | psa_status_t tfm_crypto_init_alloc(void); |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 61 | |
| 62 | /** |
Antonio de Angelis | 819c2f3 | 2019-02-06 14:32:02 +0000 | [diff] [blame] | 63 | * \brief Allocate an operation context in the backend |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 64 | * |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 65 | * \param[in] type Type of the operation context to allocate |
| 66 | * \param[out] handle Pointer to the hold the allocated handle |
| 67 | * \param[out ctx Double pointer to the corresponding context |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 68 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 69 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 70 | */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 71 | 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] | 72 | uint32_t *handle, |
Antonio de Angelis | 819c2f3 | 2019-02-06 14:32:02 +0000 | [diff] [blame] | 73 | void **ctx); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 74 | /** |
Antonio de Angelis | 819c2f3 | 2019-02-06 14:32:02 +0000 | [diff] [blame] | 75 | * \brief Release an operation context in the backend |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 76 | * |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 77 | * \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] | 78 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 79 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 80 | */ |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 81 | psa_status_t tfm_crypto_operation_release(uint32_t *handle); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 82 | /** |
Antonio de Angelis | 819c2f3 | 2019-02-06 14:32:02 +0000 | [diff] [blame] | 83 | * \brief Look up an operation context in the backend for the corresponding |
| 84 | * frontend operation |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 85 | * |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 86 | * \param[in] type Type of the operation context to look up |
| 87 | * \param[in] handle Handle of the context to lookup |
| 88 | * \param[out] ctx Double pointer to the corresponding context |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 89 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 90 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 91 | */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 92 | 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] | 93 | uint32_t handle, |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 94 | void **ctx); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 95 | |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 96 | #define LIST_TFM_CRYPTO_UNIFORM_SIGNATURE_API \ |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 97 | X(tfm_crypto_allocate_key); \ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 98 | X(tfm_crypto_import_key); \ |
| 99 | X(tfm_crypto_destroy_key); \ |
| 100 | X(tfm_crypto_get_key_information); \ |
| 101 | X(tfm_crypto_export_key); \ |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 102 | X(tfm_crypto_export_public_key); \ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 103 | X(tfm_crypto_set_key_policy); \ |
| 104 | X(tfm_crypto_get_key_policy); \ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 105 | X(tfm_crypto_get_key_lifetime); \ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 106 | X(tfm_crypto_cipher_set_iv); \ |
| 107 | X(tfm_crypto_cipher_encrypt_setup); \ |
| 108 | X(tfm_crypto_cipher_decrypt_setup); \ |
| 109 | X(tfm_crypto_cipher_update); \ |
| 110 | X(tfm_crypto_cipher_finish); \ |
| 111 | X(tfm_crypto_cipher_abort); \ |
| 112 | X(tfm_crypto_hash_setup); \ |
| 113 | X(tfm_crypto_hash_update); \ |
| 114 | X(tfm_crypto_hash_finish); \ |
| 115 | X(tfm_crypto_hash_verify); \ |
| 116 | X(tfm_crypto_hash_abort); \ |
| 117 | X(tfm_crypto_mac_sign_setup); \ |
| 118 | X(tfm_crypto_mac_verify_setup); \ |
| 119 | X(tfm_crypto_mac_update); \ |
| 120 | X(tfm_crypto_mac_sign_finish); \ |
| 121 | X(tfm_crypto_mac_verify_finish); \ |
| 122 | X(tfm_crypto_mac_abort); \ |
| 123 | X(tfm_crypto_aead_encrypt); \ |
| 124 | X(tfm_crypto_aead_decrypt); \ |
Jamie Fox | efd8273 | 2018-11-26 10:34:32 +0000 | [diff] [blame] | 125 | |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 126 | #define X(api_name) UNIFORM_SIGNATURE_API(api_name) |
| 127 | LIST_TFM_CRYPTO_UNIFORM_SIGNATURE_API |
| 128 | #undef X |
Jamie Fox | efd8273 | 2018-11-26 10:34:32 +0000 | [diff] [blame] | 129 | |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 130 | #ifdef __cplusplus |
| 131 | } |
| 132 | #endif |
| 133 | |
| 134 | #endif /* __TFM_CRYPTO_API_H__ */ |