1a8e1175bSopenharmony_ci/** 2a8e1175bSopenharmony_ci * \file psa/crypto_platform.h 3a8e1175bSopenharmony_ci * 4a8e1175bSopenharmony_ci * \brief PSA cryptography module: Mbed TLS platform definitions 5a8e1175bSopenharmony_ci * 6a8e1175bSopenharmony_ci * \note This file may not be included directly. Applications must 7a8e1175bSopenharmony_ci * include psa/crypto.h. 8a8e1175bSopenharmony_ci * 9a8e1175bSopenharmony_ci * This file contains platform-dependent type definitions. 10a8e1175bSopenharmony_ci * 11a8e1175bSopenharmony_ci * In implementations with isolation between the application and the 12a8e1175bSopenharmony_ci * cryptography module, implementers should take care to ensure that 13a8e1175bSopenharmony_ci * the definitions that are exposed to applications match what the 14a8e1175bSopenharmony_ci * module implements. 15a8e1175bSopenharmony_ci */ 16a8e1175bSopenharmony_ci/* 17a8e1175bSopenharmony_ci * Copyright The Mbed TLS Contributors 18a8e1175bSopenharmony_ci * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 19a8e1175bSopenharmony_ci */ 20a8e1175bSopenharmony_ci 21a8e1175bSopenharmony_ci#ifndef PSA_CRYPTO_PLATFORM_H 22a8e1175bSopenharmony_ci#define PSA_CRYPTO_PLATFORM_H 23a8e1175bSopenharmony_ci#include "mbedtls/private_access.h" 24a8e1175bSopenharmony_ci 25a8e1175bSopenharmony_ci/* 26a8e1175bSopenharmony_ci * Include the build-time configuration information header. Here, we do not 27a8e1175bSopenharmony_ci * include `"mbedtls/build_info.h"` directly but `"psa/build_info.h"`, which 28a8e1175bSopenharmony_ci * is basically just an alias to it. This is to ease the maintenance of the 29a8e1175bSopenharmony_ci * TF-PSA-Crypto repository which has a different build system and 30a8e1175bSopenharmony_ci * configuration. 31a8e1175bSopenharmony_ci */ 32a8e1175bSopenharmony_ci#include "psa/build_info.h" 33a8e1175bSopenharmony_ci 34a8e1175bSopenharmony_ci/* PSA requires several types which C99 provides in stdint.h. */ 35a8e1175bSopenharmony_ci#include <stdint.h> 36a8e1175bSopenharmony_ci 37a8e1175bSopenharmony_ci#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER) 38a8e1175bSopenharmony_ci 39a8e1175bSopenharmony_ci/* Building for the PSA Crypto service on a PSA platform, a key owner is a PSA 40a8e1175bSopenharmony_ci * partition identifier. 41a8e1175bSopenharmony_ci * 42a8e1175bSopenharmony_ci * The function psa_its_identifier_of_slot() in psa_crypto_storage.c that 43a8e1175bSopenharmony_ci * translates a key identifier to a key storage file name assumes that 44a8e1175bSopenharmony_ci * mbedtls_key_owner_id_t is a 32-bit integer. This function thus needs 45a8e1175bSopenharmony_ci * reworking if mbedtls_key_owner_id_t is not defined as a 32-bit integer 46a8e1175bSopenharmony_ci * here anymore. 47a8e1175bSopenharmony_ci */ 48a8e1175bSopenharmony_citypedef int32_t mbedtls_key_owner_id_t; 49a8e1175bSopenharmony_ci 50a8e1175bSopenharmony_ci/** Compare two key owner identifiers. 51a8e1175bSopenharmony_ci * 52a8e1175bSopenharmony_ci * \param id1 First key owner identifier. 53a8e1175bSopenharmony_ci * \param id2 Second key owner identifier. 54a8e1175bSopenharmony_ci * 55a8e1175bSopenharmony_ci * \return Non-zero if the two key owner identifiers are equal, zero otherwise. 56a8e1175bSopenharmony_ci */ 57a8e1175bSopenharmony_cistatic inline int mbedtls_key_owner_id_equal(mbedtls_key_owner_id_t id1, 58a8e1175bSopenharmony_ci mbedtls_key_owner_id_t id2) 59a8e1175bSopenharmony_ci{ 60a8e1175bSopenharmony_ci return id1 == id2; 61a8e1175bSopenharmony_ci} 62a8e1175bSopenharmony_ci 63a8e1175bSopenharmony_ci#endif /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */ 64a8e1175bSopenharmony_ci 65a8e1175bSopenharmony_ci/* 66a8e1175bSopenharmony_ci * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is being built for SPM 67a8e1175bSopenharmony_ci * (Secure Partition Manager) integration which separates the code into two 68a8e1175bSopenharmony_ci * parts: NSPE (Non-Secure Processing Environment) and SPE (Secure Processing 69a8e1175bSopenharmony_ci * Environment). When building for the SPE, an additional header file should be 70a8e1175bSopenharmony_ci * included. 71a8e1175bSopenharmony_ci */ 72a8e1175bSopenharmony_ci#if defined(MBEDTLS_PSA_CRYPTO_SPM) 73a8e1175bSopenharmony_ci#define PSA_CRYPTO_SECURE 1 74a8e1175bSopenharmony_ci#include "crypto_spe.h" 75a8e1175bSopenharmony_ci#endif // MBEDTLS_PSA_CRYPTO_SPM 76a8e1175bSopenharmony_ci 77a8e1175bSopenharmony_ci#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) 78a8e1175bSopenharmony_ci/** The type of the context passed to mbedtls_psa_external_get_random(). 79a8e1175bSopenharmony_ci * 80a8e1175bSopenharmony_ci * Mbed TLS initializes the context to all-bits-zero before calling 81a8e1175bSopenharmony_ci * mbedtls_psa_external_get_random() for the first time. 82a8e1175bSopenharmony_ci * 83a8e1175bSopenharmony_ci * The definition of this type in the Mbed TLS source code is for 84a8e1175bSopenharmony_ci * demonstration purposes. Implementers of mbedtls_psa_external_get_random() 85a8e1175bSopenharmony_ci * are expected to replace it with a custom definition. 86a8e1175bSopenharmony_ci */ 87a8e1175bSopenharmony_citypedef struct { 88a8e1175bSopenharmony_ci uintptr_t MBEDTLS_PRIVATE(opaque)[2]; 89a8e1175bSopenharmony_ci} mbedtls_psa_external_random_context_t; 90a8e1175bSopenharmony_ci#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */ 91a8e1175bSopenharmony_ci 92a8e1175bSopenharmony_ci#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) 93a8e1175bSopenharmony_ci/** The type of the client handle used in context structures 94a8e1175bSopenharmony_ci * 95a8e1175bSopenharmony_ci * When a client view of the multipart context structures is required, 96a8e1175bSopenharmony_ci * this handle is used to keep a mapping with the service side of the 97a8e1175bSopenharmony_ci * context which contains the actual data. 98a8e1175bSopenharmony_ci */ 99a8e1175bSopenharmony_citypedef uint32_t mbedtls_psa_client_handle_t; 100a8e1175bSopenharmony_ci#endif 101a8e1175bSopenharmony_ci 102a8e1175bSopenharmony_ci#endif /* PSA_CRYPTO_PLATFORM_H */ 103