xref: /optee_os/lib/libmbedtls/mbedtls/include/psa/crypto_platform.h (revision b0563631928755fe864b97785160fb3088e9efdc)
132b31808SJens Wiklander /**
232b31808SJens Wiklander  * \file psa/crypto_platform.h
332b31808SJens Wiklander  *
432b31808SJens Wiklander  * \brief PSA cryptography module: Mbed TLS platform definitions
532b31808SJens Wiklander  *
632b31808SJens Wiklander  * \note This file may not be included directly. Applications must
732b31808SJens Wiklander  * include psa/crypto.h.
832b31808SJens Wiklander  *
932b31808SJens Wiklander  * This file contains platform-dependent type definitions.
1032b31808SJens Wiklander  *
1132b31808SJens Wiklander  * In implementations with isolation between the application and the
1232b31808SJens Wiklander  * cryptography module, implementers should take care to ensure that
1332b31808SJens Wiklander  * the definitions that are exposed to applications match what the
1432b31808SJens Wiklander  * module implements.
1532b31808SJens Wiklander  */
1632b31808SJens Wiklander /*
1732b31808SJens Wiklander  *  Copyright The Mbed TLS Contributors
18*b0563631STom Van Eyck  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
1932b31808SJens Wiklander  */
2032b31808SJens Wiklander 
2132b31808SJens Wiklander #ifndef PSA_CRYPTO_PLATFORM_H
2232b31808SJens Wiklander #define PSA_CRYPTO_PLATFORM_H
2332b31808SJens Wiklander #include "mbedtls/private_access.h"
2432b31808SJens Wiklander 
25*b0563631STom Van Eyck /*
26*b0563631STom Van Eyck  * Include the build-time configuration information header. Here, we do not
27*b0563631STom Van Eyck  * include `"mbedtls/build_info.h"` directly but `"psa/build_info.h"`, which
28*b0563631STom Van Eyck  * is basically just an alias to it. This is to ease the maintenance of the
29*b0563631STom Van Eyck  * TF-PSA-Crypto repository which has a different build system and
30*b0563631STom Van Eyck  * configuration.
31*b0563631STom Van Eyck  */
32*b0563631STom Van Eyck #include "psa/build_info.h"
3332b31808SJens Wiklander 
3432b31808SJens Wiklander /* PSA requires several types which C99 provides in stdint.h. */
3532b31808SJens Wiklander #include <stdint.h>
3632b31808SJens Wiklander 
3732b31808SJens Wiklander #if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
3832b31808SJens Wiklander 
3932b31808SJens Wiklander /* Building for the PSA Crypto service on a PSA platform, a key owner is a PSA
4032b31808SJens Wiklander  * partition identifier.
4132b31808SJens Wiklander  *
4232b31808SJens Wiklander  * The function psa_its_identifier_of_slot() in psa_crypto_storage.c that
4332b31808SJens Wiklander  * translates a key identifier to a key storage file name assumes that
4432b31808SJens Wiklander  * mbedtls_key_owner_id_t is a 32-bit integer. This function thus needs
4532b31808SJens Wiklander  * reworking if mbedtls_key_owner_id_t is not defined as a 32-bit integer
4632b31808SJens Wiklander  * here anymore.
4732b31808SJens Wiklander  */
4832b31808SJens Wiklander typedef int32_t mbedtls_key_owner_id_t;
4932b31808SJens Wiklander 
5032b31808SJens Wiklander /** Compare two key owner identifiers.
5132b31808SJens Wiklander  *
5232b31808SJens Wiklander  * \param id1 First key owner identifier.
5332b31808SJens Wiklander  * \param id2 Second key owner identifier.
5432b31808SJens Wiklander  *
5532b31808SJens Wiklander  * \return Non-zero if the two key owner identifiers are equal, zero otherwise.
5632b31808SJens Wiklander  */
mbedtls_key_owner_id_equal(mbedtls_key_owner_id_t id1,mbedtls_key_owner_id_t id2)5732b31808SJens Wiklander static inline int mbedtls_key_owner_id_equal(mbedtls_key_owner_id_t id1,
5832b31808SJens Wiklander                                              mbedtls_key_owner_id_t id2)
5932b31808SJens Wiklander {
6032b31808SJens Wiklander     return id1 == id2;
6132b31808SJens Wiklander }
6232b31808SJens Wiklander 
6332b31808SJens Wiklander #endif /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
6432b31808SJens Wiklander 
6532b31808SJens Wiklander /*
6632b31808SJens Wiklander  * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is being built for SPM
6732b31808SJens Wiklander  * (Secure Partition Manager) integration which separates the code into two
6832b31808SJens Wiklander  * parts: NSPE (Non-Secure Processing Environment) and SPE (Secure Processing
6932b31808SJens Wiklander  * Environment). When building for the SPE, an additional header file should be
7032b31808SJens Wiklander  * included.
7132b31808SJens Wiklander  */
7232b31808SJens Wiklander #if defined(MBEDTLS_PSA_CRYPTO_SPM)
7332b31808SJens Wiklander #define PSA_CRYPTO_SECURE 1
7432b31808SJens Wiklander #include "crypto_spe.h"
7532b31808SJens Wiklander #endif // MBEDTLS_PSA_CRYPTO_SPM
7632b31808SJens Wiklander 
7732b31808SJens Wiklander #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
7832b31808SJens Wiklander /** The type of the context passed to mbedtls_psa_external_get_random().
7932b31808SJens Wiklander  *
8032b31808SJens Wiklander  * Mbed TLS initializes the context to all-bits-zero before calling
8132b31808SJens Wiklander  * mbedtls_psa_external_get_random() for the first time.
8232b31808SJens Wiklander  *
8332b31808SJens Wiklander  * The definition of this type in the Mbed TLS source code is for
8432b31808SJens Wiklander  * demonstration purposes. Implementers of mbedtls_psa_external_get_random()
8532b31808SJens Wiklander  * are expected to replace it with a custom definition.
8632b31808SJens Wiklander  */
8732b31808SJens Wiklander typedef struct {
8832b31808SJens Wiklander     uintptr_t MBEDTLS_PRIVATE(opaque)[2];
8932b31808SJens Wiklander } mbedtls_psa_external_random_context_t;
9032b31808SJens Wiklander #endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
9132b31808SJens Wiklander 
92*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
93*b0563631STom Van Eyck /** The type of the client handle used in context structures
94*b0563631STom Van Eyck  *
95*b0563631STom Van Eyck  * When a client view of the multipart context structures is required,
96*b0563631STom Van Eyck  * this handle is used to keep a mapping with the service side of the
97*b0563631STom Van Eyck  * context which contains the actual data.
98*b0563631STom Van Eyck  */
99*b0563631STom Van Eyck typedef uint32_t mbedtls_psa_client_handle_t;
100*b0563631STom Van Eyck #endif
101*b0563631STom Van Eyck 
10232b31808SJens Wiklander #endif /* PSA_CRYPTO_PLATFORM_H */
103