mbedtls_config.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (c) 2015-2022, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef MBEDTLS_CONFIG_H
  7. #define MBEDTLS_CONFIG_H
  8. /*
  9. * Key algorithms currently supported on mbed TLS libraries
  10. */
  11. #define TF_MBEDTLS_RSA 1
  12. #define TF_MBEDTLS_ECDSA 2
  13. #define TF_MBEDTLS_RSA_AND_ECDSA 3
  14. #define TF_MBEDTLS_USE_RSA (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA \
  15. || TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA_AND_ECDSA)
  16. #define TF_MBEDTLS_USE_ECDSA (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA \
  17. || TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA_AND_ECDSA)
  18. /*
  19. * Hash algorithms currently supported on mbed TLS libraries
  20. */
  21. #define TF_MBEDTLS_SHA256 1
  22. #define TF_MBEDTLS_SHA384 2
  23. #define TF_MBEDTLS_SHA512 3
  24. /*
  25. * Configuration file to build mbed TLS with the required features for
  26. * Trusted Boot
  27. */
  28. #define MBEDTLS_PLATFORM_MEMORY
  29. #define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
  30. /* Prevent mbed TLS from using snprintf so that it can use tf_snprintf. */
  31. #define MBEDTLS_PLATFORM_SNPRINTF_ALT
  32. #define MBEDTLS_PKCS1_V21
  33. #define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
  34. #define MBEDTLS_X509_CHECK_KEY_USAGE
  35. #define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
  36. #define MBEDTLS_ASN1_PARSE_C
  37. #define MBEDTLS_ASN1_WRITE_C
  38. #define MBEDTLS_BASE64_C
  39. #define MBEDTLS_BIGNUM_C
  40. #define MBEDTLS_ERROR_C
  41. #define MBEDTLS_MD_C
  42. #define MBEDTLS_MEMORY_BUFFER_ALLOC_C
  43. #define MBEDTLS_OID_C
  44. #define MBEDTLS_PK_C
  45. #define MBEDTLS_PK_PARSE_C
  46. #define MBEDTLS_PK_WRITE_C
  47. #define MBEDTLS_PLATFORM_C
  48. #if TF_MBEDTLS_USE_ECDSA
  49. #define MBEDTLS_ECDSA_C
  50. #define MBEDTLS_ECP_C
  51. #define MBEDTLS_ECP_DP_SECP256R1_ENABLED
  52. #define MBEDTLS_ECP_NO_INTERNAL_RNG
  53. #endif
  54. #if TF_MBEDTLS_USE_RSA
  55. #define MBEDTLS_RSA_C
  56. #define MBEDTLS_X509_RSASSA_PSS_SUPPORT
  57. #endif
  58. #define MBEDTLS_SHA256_C
  59. /*
  60. * If either Trusted Boot or Measured Boot require a stronger algorithm than
  61. * SHA-256, pull in SHA-512 support.
  62. */
  63. #if (TF_MBEDTLS_HASH_ALG_ID != TF_MBEDTLS_SHA256) /* TBB hash algo */
  64. #define MBEDTLS_SHA512_C
  65. #else
  66. /* TBB uses SHA-256, what about measured boot? */
  67. #if defined(TF_MBEDTLS_MBOOT_USE_SHA512)
  68. #define MBEDTLS_SHA512_C
  69. #endif
  70. #endif
  71. #define MBEDTLS_VERSION_C
  72. #define MBEDTLS_X509_USE_C
  73. #define MBEDTLS_X509_CRT_PARSE_C
  74. #if TF_MBEDTLS_USE_AES_GCM
  75. #define MBEDTLS_AES_C
  76. #define MBEDTLS_CIPHER_C
  77. #define MBEDTLS_GCM_C
  78. #endif
  79. /* MPI / BIGNUM options */
  80. #define MBEDTLS_MPI_WINDOW_SIZE 2
  81. #if TF_MBEDTLS_USE_RSA
  82. #if TF_MBEDTLS_KEY_SIZE <= 2048
  83. #define MBEDTLS_MPI_MAX_SIZE 256
  84. #else
  85. #define MBEDTLS_MPI_MAX_SIZE 512
  86. #endif
  87. #else
  88. #define MBEDTLS_MPI_MAX_SIZE 256
  89. #endif
  90. /* Memory buffer allocator options */
  91. #define MBEDTLS_MEMORY_ALIGN_MULTIPLE 8
  92. /*
  93. * Prevent the use of 128-bit division which
  94. * creates dependency on external libraries.
  95. */
  96. #define MBEDTLS_NO_UDBL_DIVISION
  97. #ifndef __ASSEMBLER__
  98. /* System headers required to build mbed TLS with the current configuration */
  99. #include <stdlib.h>
  100. #include <mbedtls/check_config.h>
  101. #endif
  102. /*
  103. * Determine Mbed TLS heap size
  104. * 13312 = 13*1024
  105. * 11264 = 11*1024
  106. * 7168 = 7*1024
  107. */
  108. #if TF_MBEDTLS_USE_ECDSA
  109. #define TF_MBEDTLS_HEAP_SIZE U(13312)
  110. #elif TF_MBEDTLS_USE_RSA
  111. #if TF_MBEDTLS_KEY_SIZE <= 2048
  112. #define TF_MBEDTLS_HEAP_SIZE U(7168)
  113. #else
  114. #define TF_MBEDTLS_HEAP_SIZE U(11264)
  115. #endif
  116. #endif
  117. /*
  118. * Warn if errors from certain functions are ignored.
  119. *
  120. * The warnings are always enabled (where supported) for critical functions
  121. * where ignoring the return value is almost always a bug. This macro extends
  122. * the warnings to more functions.
  123. */
  124. #define MBEDTLS_CHECK_RETURN_WARNING
  125. #endif /* MBEDTLS_CONFIG_H */