1 /* 2 * Copyright (c) 2022-2023, 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 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #include "psa/crypto.h" 26 27 /** 28 * @brief This macro extracts the key ID from the library encoded key passed as parameter 29 * 30 */ 31 #define CRYPTO_LIBRARY_GET_KEY_ID(encoded_key_library) MBEDTLS_SVC_KEY_ID_GET_KEY_ID(encoded_key_library) 32 33 /** 34 * @brief This macro extracts the owner from the library encoded key passed as parameter 35 * 36 */ 37 #define CRYPTO_LIBRARY_GET_OWNER(encoded_key_library) MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(encoded_key_library) 38 39 /** 40 * @brief The following typedef must be defined to the type associated to the key_id in the underlying library 41 * 42 */ 43 typedef mbedtls_svc_key_id_t tfm_crypto_library_key_id_t; 44 45 /** 46 * @brief Function used to initialise an object of \ref tfm_crypto_library_key_id_t to a (owner, key_id) pair 47 * 48 * @param[in] owner Owner of the key 49 * @param[in] key_id key ID associated to the key of type \ref psa_key_id_t 50 * 51 * @return An object of type \ref tfm_crypto_library_key_id_t 52 * 53 */ 54 tfm_crypto_library_key_id_t tfm_crypto_library_key_id_init(int32_t owner, psa_key_id_t key_id); 55 56 /** 57 * @brief This function is used to retrieve a string describing the library used in the backend 58 * to provide information to the crypto service and the user 59 * 60 * @return A NULL terminated string describing the backend library 61 */ 62 char *tfm_crypto_library_get_info(void); 63 64 /** 65 * @brief This function initialises a \ref tfm_crypto_library_key_id_t with default values 66 * 67 */ tfm_crypto_library_key_id_init_default(void)68static inline tfm_crypto_library_key_id_t tfm_crypto_library_key_id_init_default(void) 69 { 70 return tfm_crypto_library_key_id_init(0, 0); 71 } 72 73 /** 74 * @brief Allows to set the owner of a library key embedded into the key attributes structure 75 * 76 * @param[in] owner The owner value to be written into the key attributes structure 77 * @param[out] attr Pointer to the key attributes into which we want to e 78 * 79 */ 80 void tfm_crypto_library_get_library_key_id_set_owner(int32_t owner, psa_key_attributes_t *attr); 81 82 /*! 83 * @brief This function is used to perform the necessary steps to initialise the underlying 84 * library that provides the implementation of the PSA Crypto core to the TF-M Crypto 85 * service 86 * 87 * @return PSA_SUCCESS on successful initialisation 88 */ 89 psa_status_t tfm_crypto_core_library_init(void); 90 91 #ifdef __cplusplus 92 } 93 #endif 94 95 #endif /* CRYPTO_LIBRARY_H */ 96