crypto_platform.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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
  19. *
  20. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  21. * not use this file except in compliance with the License.
  22. * You may obtain a copy of the License at
  23. *
  24. * http://www.apache.org/licenses/LICENSE-2.0
  25. *
  26. * Unless required by applicable law or agreed to in writing, software
  27. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  28. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  29. * See the License for the specific language governing permissions and
  30. * limitations under the License.
  31. */
  32. #ifndef PSA_CRYPTO_PLATFORM_H
  33. #define PSA_CRYPTO_PLATFORM_H
  34. /* Include the Mbed TLS configuration file, the way Mbed TLS does it
  35. * in each of its header files. */
  36. #if !defined(MBEDTLS_CONFIG_FILE)
  37. #include "mbedtls/config.h"
  38. #else
  39. #include MBEDTLS_CONFIG_FILE
  40. #endif
  41. /* Translate between classic MBEDTLS_xxx feature symbols and PSA_xxx
  42. * feature symbols. */
  43. #include "mbedtls/config_psa.h"
  44. /* PSA requires several types which C99 provides in stdint.h. */
  45. #include <stdint.h>
  46. #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
  47. !defined(inline) && !defined(__cplusplus)
  48. #define inline __inline
  49. #endif
  50. #if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
  51. /* Building for the PSA Crypto service on a PSA platform, a key owner is a PSA
  52. * partition identifier.
  53. *
  54. * The function psa_its_identifier_of_slot() in psa_crypto_storage.c that
  55. * translates a key identifier to a key storage file name assumes that
  56. * mbedtls_key_owner_id_t is an 32 bits integer. This function thus needs
  57. * reworking if mbedtls_key_owner_id_t is not defined as a 32 bits integer
  58. * here anymore.
  59. */
  60. typedef int32_t mbedtls_key_owner_id_t;
  61. /** Compare two key owner identifiers.
  62. *
  63. * \param id1 First key owner identifier.
  64. * \param id2 Second key owner identifier.
  65. *
  66. * \return Non-zero if the two key owner identifiers are equal, zero otherwise.
  67. */
  68. static inline int mbedtls_key_owner_id_equal( mbedtls_key_owner_id_t id1,
  69. mbedtls_key_owner_id_t id2 )
  70. {
  71. return( id1 == id2 );
  72. }
  73. #endif /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
  74. /*
  75. * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is being built for SPM
  76. * (Secure Partition Manager) integration which separates the code into two
  77. * parts: NSPE (Non-Secure Processing Environment) and SPE (Secure Processing
  78. * Environment). When building for the SPE, an additional header file should be
  79. * included.
  80. */
  81. #if defined(MBEDTLS_PSA_CRYPTO_SPM)
  82. #define PSA_CRYPTO_SECURE 1
  83. #include "crypto_spe.h"
  84. #endif // MBEDTLS_PSA_CRYPTO_SPM
  85. #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
  86. /** The type of the context passed to mbedtls_psa_external_get_random().
  87. *
  88. * Mbed TLS initializes the context to all-bits-zero before calling
  89. * mbedtls_psa_external_get_random() for the first time.
  90. *
  91. * The definition of this type in the Mbed TLS source code is for
  92. * demonstration purposes. Implementers of mbedtls_psa_external_get_random()
  93. * are expected to replace it with a custom definition.
  94. */
  95. typedef struct {
  96. uintptr_t opaque[2];
  97. } mbedtls_psa_external_random_context_t;
  98. #endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
  99. #endif /* PSA_CRYPTO_PLATFORM_H */