Antonio de Angelis | 7557e68 | 2022-11-30 15:37:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * \file crypto_library.h |
| 10 | * |
| 11 | * \brief This file contains some abstractions required to interface the |
| 12 | * TF-M Crypto service to an underlying cryptographic library that |
| 13 | * implements the PSA Crypto API. The TF-M Crypto service uses this |
| 14 | * library to provide a PSA Crypto core layer implementation and |
| 15 | * a software or hardware based implementation of crypto algorithms. |
| 16 | */ |
| 17 | |
| 18 | #ifndef CRYPTO_LIBRARY_H |
| 19 | #define CRYPTO_LIBRARY_H |
| 20 | |
| 21 | #include "psa/crypto.h" |
| 22 | #include "tfm_crypto_api.h" |
| 23 | |
| 24 | /** |
| 25 | * \brief This macro extracts the key ID from the library encoded key passed as parameter |
| 26 | * |
| 27 | */ |
| 28 | #define CRYPTO_LIBRARY_GET_KEY_ID(encoded_key_library) MBEDTLS_SVC_KEY_ID_GET_KEY_ID(encoded_key_library) |
| 29 | |
| 30 | /** |
| 31 | * \brief The following typedef must be defined to the type associated to the key_id in the underlying library |
| 32 | * |
| 33 | */ |
| 34 | typedef mbedtls_svc_key_id_t tfm_crypto_library_key_id_t; |
| 35 | |
| 36 | /** |
| 37 | * \brief Function used to initialise an object of \ref tfm_crypto_library_key_id_t to a (owner, key_id) pair |
| 38 | * |
| 39 | * \param[in] owner Owner of the key |
| 40 | * \param[in] key_id key ID associated to the key of type \ref psa_key_id_t |
| 41 | * |
| 42 | * \return An object of type \ref tfm_crypto_library_key_id_t |
| 43 | * |
| 44 | */ |
| 45 | tfm_crypto_library_key_id_t tfm_crypto_library_key_id_init(int32_t owner, psa_key_id_t key_id); |
| 46 | |
| 47 | /** |
| 48 | * \brief This function is used to retrieve a string describing the library used in the backend |
| 49 | * to provide information to the crypto service and the user |
| 50 | * |
| 51 | * \return A NULL terminated string describing the backend library |
| 52 | */ |
| 53 | char *tfm_crypto_library_get_info(void); |
| 54 | |
| 55 | /** |
| 56 | * \brief This function initialises a \ref tfm_crypto_library_key_id_t with default values |
| 57 | * |
| 58 | */ |
| 59 | static inline tfm_crypto_library_key_id_t tfm_crypto_library_key_id_init_default(void) |
| 60 | { |
| 61 | return tfm_crypto_library_key_id_init(0, 0); |
| 62 | } |
| 63 | #endif /* CRYPTO_LIBRARY_H */ |