blob: d983844d6947d77062d9a626ef3e2ef75cd19895 [file] [log] [blame]
Antonio de Angelis7557e682022-11-30 15:37:51 +00001/*
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 */
34typedef 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 */
45tfm_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 */
53char *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 */
59static 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}
Antonio de Angelisedbafb62022-12-01 13:52:15 +000063
64/*!
65 * \brief This function is used to perform the necessary steps to initialise the underlying
66 * library that provides the implementation of the PSA Crypto core to the TF-M Crypto
67 * service
68 *
69 * \return PSA_SUCCESS on successful initialisation
70 */
71psa_status_t tfm_crypto_core_library_init(void);
72
Antonio de Angelis7557e682022-11-30 15:37:51 +000073#endif /* CRYPTO_LIBRARY_H */