crypto_platform.h 3.5 KB

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