config_adjust_legacy_crypto.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. /**
  2. * \file mbedtls/config_adjust_legacy_crypto.h
  3. * \brief Adjust legacy configuration configuration
  4. *
  5. * This is an internal header. Do not include it directly.
  6. *
  7. * Automatically enable certain dependencies. Generally, MBEDTLS_xxx
  8. * configurations need to be explicitly enabled by the user: enabling
  9. * MBEDTLS_xxx_A but not MBEDTLS_xxx_B when A requires B results in a
  10. * compilation error. However, we do automatically enable certain options
  11. * in some circumstances. One case is if MBEDTLS_xxx_B is an internal option
  12. * used to identify parts of a module that are used by other module, and we
  13. * don't want to make the symbol MBEDTLS_xxx_B part of the public API.
  14. * Another case is if A didn't depend on B in earlier versions, and we
  15. * want to use B in A but we need to preserve backward compatibility with
  16. * configurations that explicitly activate MBEDTLS_xxx_A but not
  17. * MBEDTLS_xxx_B.
  18. */
  19. /*
  20. * Copyright The Mbed TLS Contributors
  21. * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  22. */
  23. #ifndef MBEDTLS_CONFIG_ADJUST_LEGACY_CRYPTO_H
  24. #define MBEDTLS_CONFIG_ADJUST_LEGACY_CRYPTO_H
  25. #if !defined(MBEDTLS_CONFIG_FILES_READ)
  26. #error "Do not include mbedtls/config_adjust_*.h manually! This can lead to problems, " \
  27. "up to and including runtime errors such as buffer overflows. " \
  28. "If you're trying to fix a complaint from check_config.h, just remove " \
  29. "it from your configuration file: since Mbed TLS 3.0, it is included " \
  30. "automatically at the right point."
  31. #endif /* */
  32. /* Ideally, we'd set those as defaults in mbedtls_config.h, but
  33. * putting an #ifdef _WIN32 in mbedtls_config.h would confuse config.py.
  34. *
  35. * So, adjust it here.
  36. * Not related to crypto, but this is the bottom of the stack. */
  37. #if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER <= 1900)
  38. #if !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && \
  39. !defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
  40. #define MBEDTLS_PLATFORM_SNPRINTF_ALT
  41. #endif
  42. #if !defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT) && \
  43. !defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO)
  44. #define MBEDTLS_PLATFORM_VSNPRINTF_ALT
  45. #endif
  46. #endif /* _MINGW32__ || (_MSC_VER && (_MSC_VER <= 1900)) */
  47. /* If MBEDTLS_PSA_CRYPTO_C is defined, make sure MBEDTLS_PSA_CRYPTO_CLIENT
  48. * is defined as well to include all PSA code.
  49. */
  50. #if defined(MBEDTLS_PSA_CRYPTO_C)
  51. #define MBEDTLS_PSA_CRYPTO_CLIENT
  52. #endif /* MBEDTLS_PSA_CRYPTO_C */
  53. /* Auto-enable CIPHER_C when any of the unauthenticated ciphers is builtin
  54. * in PSA. */
  55. #if defined(MBEDTLS_PSA_CRYPTO_C) && \
  56. (defined(MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER) || \
  57. defined(MBEDTLS_PSA_BUILTIN_ALG_CTR) || \
  58. defined(MBEDTLS_PSA_BUILTIN_ALG_CFB) || \
  59. defined(MBEDTLS_PSA_BUILTIN_ALG_OFB) || \
  60. defined(MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING) || \
  61. defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING) || \
  62. defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7) || \
  63. defined(MBEDTLS_PSA_BUILTIN_ALG_CCM_STAR_NO_TAG) || \
  64. defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC))
  65. #define MBEDTLS_CIPHER_C
  66. #endif
  67. /* Auto-enable MBEDTLS_MD_LIGHT based on MBEDTLS_MD_C.
  68. * This allows checking for MD_LIGHT rather than MD_LIGHT || MD_C.
  69. */
  70. #if defined(MBEDTLS_MD_C)
  71. #define MBEDTLS_MD_LIGHT
  72. #endif
  73. /* Auto-enable MBEDTLS_MD_LIGHT if needed by a module that didn't require it
  74. * in a previous release, to ensure backwards compatibility.
  75. */
  76. #if defined(MBEDTLS_ECJPAKE_C) || \
  77. defined(MBEDTLS_PEM_PARSE_C) || \
  78. defined(MBEDTLS_ENTROPY_C) || \
  79. defined(MBEDTLS_PK_C) || \
  80. defined(MBEDTLS_PKCS12_C) || \
  81. defined(MBEDTLS_RSA_C) || \
  82. defined(MBEDTLS_SSL_TLS_C) || \
  83. defined(MBEDTLS_X509_USE_C) || \
  84. defined(MBEDTLS_X509_CREATE_C)
  85. #define MBEDTLS_MD_LIGHT
  86. #endif
  87. #if defined(MBEDTLS_MD_LIGHT)
  88. /*
  89. * - MBEDTLS_MD_CAN_xxx is defined if the md module can perform xxx.
  90. * - MBEDTLS_MD_xxx_VIA_PSA is defined if the md module may perform xxx via PSA
  91. * (see below).
  92. * - MBEDTLS_MD_SOME_PSA is defined if at least one algorithm may be performed
  93. * via PSA (see below).
  94. * - MBEDTLS_MD_SOME_LEGACY is defined if at least one algorithm may be performed
  95. * via a direct legacy call (see below).
  96. *
  97. * The md module performs an algorithm via PSA if there is a PSA hash
  98. * accelerator and the PSA driver subsytem is initialized at the time the
  99. * operation is started, and makes a direct legacy call otherwise.
  100. */
  101. /* PSA accelerated implementations */
  102. #if defined(MBEDTLS_PSA_CRYPTO_C)
  103. #if defined(MBEDTLS_PSA_ACCEL_ALG_MD5)
  104. #define MBEDTLS_MD_CAN_MD5
  105. #define MBEDTLS_MD_MD5_VIA_PSA
  106. #define MBEDTLS_MD_SOME_PSA
  107. #endif
  108. #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1)
  109. #define MBEDTLS_MD_CAN_SHA1
  110. #define MBEDTLS_MD_SHA1_VIA_PSA
  111. #define MBEDTLS_MD_SOME_PSA
  112. #endif
  113. #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224)
  114. #define MBEDTLS_MD_CAN_SHA224
  115. #define MBEDTLS_MD_SHA224_VIA_PSA
  116. #define MBEDTLS_MD_SOME_PSA
  117. #endif
  118. #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
  119. #define MBEDTLS_MD_CAN_SHA256
  120. #define MBEDTLS_MD_SHA256_VIA_PSA
  121. #define MBEDTLS_MD_SOME_PSA
  122. #endif
  123. #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384)
  124. #define MBEDTLS_MD_CAN_SHA384
  125. #define MBEDTLS_MD_SHA384_VIA_PSA
  126. #define MBEDTLS_MD_SOME_PSA
  127. #endif
  128. #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512)
  129. #define MBEDTLS_MD_CAN_SHA512
  130. #define MBEDTLS_MD_SHA512_VIA_PSA
  131. #define MBEDTLS_MD_SOME_PSA
  132. #endif
  133. #if defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160)
  134. #define MBEDTLS_MD_CAN_RIPEMD160
  135. #define MBEDTLS_MD_RIPEMD160_VIA_PSA
  136. #define MBEDTLS_MD_SOME_PSA
  137. #endif
  138. #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_224)
  139. #define MBEDTLS_MD_CAN_SHA3_224
  140. #define MBEDTLS_MD_SHA3_224_VIA_PSA
  141. #define MBEDTLS_MD_SOME_PSA
  142. #endif
  143. #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_256)
  144. #define MBEDTLS_MD_CAN_SHA3_256
  145. #define MBEDTLS_MD_SHA3_256_VIA_PSA
  146. #define MBEDTLS_MD_SOME_PSA
  147. #endif
  148. #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_384)
  149. #define MBEDTLS_MD_CAN_SHA3_384
  150. #define MBEDTLS_MD_SHA3_384_VIA_PSA
  151. #define MBEDTLS_MD_SOME_PSA
  152. #endif
  153. #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_512)
  154. #define MBEDTLS_MD_CAN_SHA3_512
  155. #define MBEDTLS_MD_SHA3_512_VIA_PSA
  156. #define MBEDTLS_MD_SOME_PSA
  157. #endif
  158. #elif defined(MBEDTLS_PSA_CRYPTO_CLIENT)
  159. #if defined(PSA_WANT_ALG_MD5)
  160. #define MBEDTLS_MD_CAN_MD5
  161. #define MBEDTLS_MD_MD5_VIA_PSA
  162. #define MBEDTLS_MD_SOME_PSA
  163. #endif
  164. #if defined(PSA_WANT_ALG_SHA_1)
  165. #define MBEDTLS_MD_CAN_SHA1
  166. #define MBEDTLS_MD_SHA1_VIA_PSA
  167. #define MBEDTLS_MD_SOME_PSA
  168. #endif
  169. #if defined(PSA_WANT_ALG_SHA_224)
  170. #define MBEDTLS_MD_CAN_SHA224
  171. #define MBEDTLS_MD_SHA224_VIA_PSA
  172. #define MBEDTLS_MD_SOME_PSA
  173. #endif
  174. #if defined(PSA_WANT_ALG_SHA_256)
  175. #define MBEDTLS_MD_CAN_SHA256
  176. #define MBEDTLS_MD_SHA256_VIA_PSA
  177. #define MBEDTLS_MD_SOME_PSA
  178. #endif
  179. #if defined(PSA_WANT_ALG_SHA_384)
  180. #define MBEDTLS_MD_CAN_SHA384
  181. #define MBEDTLS_MD_SHA384_VIA_PSA
  182. #define MBEDTLS_MD_SOME_PSA
  183. #endif
  184. #if defined(PSA_WANT_ALG_SHA_512)
  185. #define MBEDTLS_MD_CAN_SHA512
  186. #define MBEDTLS_MD_SHA512_VIA_PSA
  187. #define MBEDTLS_MD_SOME_PSA
  188. #endif
  189. #if defined(PSA_WANT_ALG_RIPEMD160)
  190. #define MBEDTLS_MD_CAN_RIPEMD160
  191. #define MBEDTLS_MD_RIPEMD160_VIA_PSA
  192. #define MBEDTLS_MD_SOME_PSA
  193. #endif
  194. #if defined(PSA_WANT_ALG_SHA3_224)
  195. #define MBEDTLS_MD_CAN_SHA3_224
  196. #define MBEDTLS_MD_SHA3_224_VIA_PSA
  197. #define MBEDTLS_MD_SOME_PSA
  198. #endif
  199. #if defined(PSA_WANT_ALG_SHA3_256)
  200. #define MBEDTLS_MD_CAN_SHA3_256
  201. #define MBEDTLS_MD_SHA3_256_VIA_PSA
  202. #define MBEDTLS_MD_SOME_PSA
  203. #endif
  204. #if defined(PSA_WANT_ALG_SHA3_384)
  205. #define MBEDTLS_MD_CAN_SHA3_384
  206. #define MBEDTLS_MD_SHA3_384_VIA_PSA
  207. #define MBEDTLS_MD_SOME_PSA
  208. #endif
  209. #if defined(PSA_WANT_ALG_SHA3_512)
  210. #define MBEDTLS_MD_CAN_SHA3_512
  211. #define MBEDTLS_MD_SHA3_512_VIA_PSA
  212. #define MBEDTLS_MD_SOME_PSA
  213. #endif
  214. #endif /* !MBEDTLS_PSA_CRYPTO_CLIENT && !MBEDTLS_PSA_CRYPTO_C */
  215. /* Built-in implementations */
  216. #if defined(MBEDTLS_MD5_C)
  217. #define MBEDTLS_MD_CAN_MD5
  218. #define MBEDTLS_MD_SOME_LEGACY
  219. #endif
  220. #if defined(MBEDTLS_SHA1_C)
  221. #define MBEDTLS_MD_CAN_SHA1
  222. #define MBEDTLS_MD_SOME_LEGACY
  223. #endif
  224. #if defined(MBEDTLS_SHA224_C)
  225. #define MBEDTLS_MD_CAN_SHA224
  226. #define MBEDTLS_MD_SOME_LEGACY
  227. #endif
  228. #if defined(MBEDTLS_SHA256_C)
  229. #define MBEDTLS_MD_CAN_SHA256
  230. #define MBEDTLS_MD_SOME_LEGACY
  231. #endif
  232. #if defined(MBEDTLS_SHA384_C)
  233. #define MBEDTLS_MD_CAN_SHA384
  234. #define MBEDTLS_MD_SOME_LEGACY
  235. #endif
  236. #if defined(MBEDTLS_SHA512_C)
  237. #define MBEDTLS_MD_CAN_SHA512
  238. #define MBEDTLS_MD_SOME_LEGACY
  239. #endif
  240. #if defined(MBEDTLS_SHA3_C)
  241. #define MBEDTLS_MD_CAN_SHA3_224
  242. #define MBEDTLS_MD_CAN_SHA3_256
  243. #define MBEDTLS_MD_CAN_SHA3_384
  244. #define MBEDTLS_MD_CAN_SHA3_512
  245. #define MBEDTLS_MD_SOME_LEGACY
  246. #endif
  247. #if defined(MBEDTLS_RIPEMD160_C)
  248. #define MBEDTLS_MD_CAN_RIPEMD160
  249. #define MBEDTLS_MD_SOME_LEGACY
  250. #endif
  251. #endif /* MBEDTLS_MD_LIGHT */
  252. /* BLOCK_CIPHER module can dispatch to PSA when:
  253. * - PSA is enabled and drivers have been initialized
  254. * - desired key type is supported on the PSA side
  255. * If the above conditions are not met, but the legacy support is enabled, then
  256. * BLOCK_CIPHER will dynamically fallback to it.
  257. *
  258. * In case BLOCK_CIPHER is defined (see below) the following symbols/helpers
  259. * can be used to define its capabilities:
  260. * - MBEDTLS_BLOCK_CIPHER_SOME_PSA: there is at least 1 key type between AES,
  261. * ARIA and Camellia which is supported through a driver;
  262. * - MBEDTLS_BLOCK_CIPHER_xxx_VIA_PSA: xxx key type is supported through a
  263. * driver;
  264. * - MBEDTLS_BLOCK_CIPHER_xxx_VIA_LEGACY: xxx key type is supported through
  265. * a legacy module (i.e. MBEDTLS_xxx_C)
  266. */
  267. #if defined(MBEDTLS_PSA_CRYPTO_C)
  268. #if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_AES)
  269. #define MBEDTLS_BLOCK_CIPHER_AES_VIA_PSA
  270. #define MBEDTLS_BLOCK_CIPHER_SOME_PSA
  271. #endif
  272. #if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ARIA)
  273. #define MBEDTLS_BLOCK_CIPHER_ARIA_VIA_PSA
  274. #define MBEDTLS_BLOCK_CIPHER_SOME_PSA
  275. #endif
  276. #if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA)
  277. #define MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_PSA
  278. #define MBEDTLS_BLOCK_CIPHER_SOME_PSA
  279. #endif
  280. #endif /* MBEDTLS_PSA_CRYPTO_C */
  281. #if defined(MBEDTLS_AES_C)
  282. #define MBEDTLS_BLOCK_CIPHER_AES_VIA_LEGACY
  283. #endif
  284. #if defined(MBEDTLS_ARIA_C)
  285. #define MBEDTLS_BLOCK_CIPHER_ARIA_VIA_LEGACY
  286. #endif
  287. #if defined(MBEDTLS_CAMELLIA_C)
  288. #define MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_LEGACY
  289. #endif
  290. /* Helpers to state that BLOCK_CIPHER module supports AES, ARIA and/or Camellia
  291. * block ciphers via either PSA or legacy. */
  292. #if defined(MBEDTLS_BLOCK_CIPHER_AES_VIA_PSA) || \
  293. defined(MBEDTLS_BLOCK_CIPHER_AES_VIA_LEGACY)
  294. #define MBEDTLS_BLOCK_CIPHER_CAN_AES
  295. #endif
  296. #if defined(MBEDTLS_BLOCK_CIPHER_ARIA_VIA_PSA) || \
  297. defined(MBEDTLS_BLOCK_CIPHER_ARIA_VIA_LEGACY)
  298. #define MBEDTLS_BLOCK_CIPHER_CAN_ARIA
  299. #endif
  300. #if defined(MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_PSA) || \
  301. defined(MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_LEGACY)
  302. #define MBEDTLS_BLOCK_CIPHER_CAN_CAMELLIA
  303. #endif
  304. /* GCM_C and CCM_C can either depend on (in order of preference) BLOCK_CIPHER_C
  305. * or CIPHER_C. The former is auto-enabled when:
  306. * - CIPHER_C is not defined, which is also the legacy solution;
  307. * - BLOCK_CIPHER_SOME_PSA because in this case BLOCK_CIPHER can take advantage
  308. * of the driver's acceleration.
  309. */
  310. #if (defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C)) && \
  311. (!defined(MBEDTLS_CIPHER_C) || defined(MBEDTLS_BLOCK_CIPHER_SOME_PSA))
  312. #define MBEDTLS_BLOCK_CIPHER_C
  313. #endif
  314. /* Helpers for GCM/CCM capabilities */
  315. #if (defined(MBEDTLS_CIPHER_C) && defined(MBEDTLS_AES_C)) || \
  316. (defined(MBEDTLS_BLOCK_CIPHER_C) && defined(MBEDTLS_BLOCK_CIPHER_CAN_AES))
  317. #define MBEDTLS_CCM_GCM_CAN_AES
  318. #endif
  319. #if (defined(MBEDTLS_CIPHER_C) && defined(MBEDTLS_ARIA_C)) || \
  320. (defined(MBEDTLS_BLOCK_CIPHER_C) && defined(MBEDTLS_BLOCK_CIPHER_CAN_ARIA))
  321. #define MBEDTLS_CCM_GCM_CAN_ARIA
  322. #endif
  323. #if (defined(MBEDTLS_CIPHER_C) && defined(MBEDTLS_CAMELLIA_C)) || \
  324. (defined(MBEDTLS_BLOCK_CIPHER_C) && defined(MBEDTLS_BLOCK_CIPHER_CAN_CAMELLIA))
  325. #define MBEDTLS_CCM_GCM_CAN_CAMELLIA
  326. #endif
  327. /* MBEDTLS_ECP_LIGHT is auto-enabled by the following symbols:
  328. * - MBEDTLS_ECP_C because now it consists of MBEDTLS_ECP_LIGHT plus functions
  329. * for curve arithmetic. As a consequence if MBEDTLS_ECP_C is required for
  330. * some reason, then MBEDTLS_ECP_LIGHT should be enabled as well.
  331. * - MBEDTLS_PK_PARSE_EC_EXTENDED and MBEDTLS_PK_PARSE_EC_COMPRESSED because
  332. * these features are not supported in PSA so the only way to have them is
  333. * to enable the built-in solution.
  334. * Both of them are temporary dependencies:
  335. * - PK_PARSE_EC_EXTENDED will be removed after #7779 and #7789
  336. * - support for compressed points should also be added to PSA, but in this
  337. * case there is no associated issue to track it yet.
  338. * - PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE because Weierstrass key derivation
  339. * still depends on ECP_LIGHT.
  340. * - PK_C + USE_PSA + PSA_WANT_ALG_ECDSA is a temporary dependency which will
  341. * be fixed by #7453.
  342. */
  343. #if defined(MBEDTLS_ECP_C) || \
  344. defined(MBEDTLS_PK_PARSE_EC_EXTENDED) || \
  345. defined(MBEDTLS_PK_PARSE_EC_COMPRESSED) || \
  346. defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR_DERIVE)
  347. #define MBEDTLS_ECP_LIGHT
  348. #endif
  349. /* Backward compatibility: after #8740 the RSA module offers functions to parse
  350. * and write RSA private/public keys without relying on the PK one. Of course
  351. * this needs ASN1 support to do so, so we enable it here. */
  352. #if defined(MBEDTLS_RSA_C)
  353. #define MBEDTLS_ASN1_PARSE_C
  354. #define MBEDTLS_ASN1_WRITE_C
  355. #endif
  356. /* MBEDTLS_PK_PARSE_EC_COMPRESSED is introduced in Mbed TLS version 3.5, while
  357. * in previous version compressed points were automatically supported as long
  358. * as PK_PARSE_C and ECP_C were enabled. As a consequence, for backward
  359. * compatibility, we auto-enable PK_PARSE_EC_COMPRESSED when these conditions
  360. * are met. */
  361. #if defined(MBEDTLS_PK_PARSE_C) && defined(MBEDTLS_ECP_C)
  362. #define MBEDTLS_PK_PARSE_EC_COMPRESSED
  363. #endif
  364. /* Helper symbol to state that there is support for ECDH, either through
  365. * library implementation (ECDH_C) or through PSA. */
  366. #if (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_ECDH)) || \
  367. (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_ECDH_C))
  368. #define MBEDTLS_CAN_ECDH
  369. #endif
  370. /* PK module can achieve ECDSA functionalities by means of either software
  371. * implementations (ECDSA_C) or through a PSA driver. The following defines
  372. * are meant to list these capabilities in a general way which abstracts how
  373. * they are implemented under the hood. */
  374. #if !defined(MBEDTLS_USE_PSA_CRYPTO)
  375. #if defined(MBEDTLS_ECDSA_C)
  376. #define MBEDTLS_PK_CAN_ECDSA_SIGN
  377. #define MBEDTLS_PK_CAN_ECDSA_VERIFY
  378. #endif /* MBEDTLS_ECDSA_C */
  379. #else /* MBEDTLS_USE_PSA_CRYPTO */
  380. #if defined(PSA_WANT_ALG_ECDSA)
  381. #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC)
  382. #define MBEDTLS_PK_CAN_ECDSA_SIGN
  383. #endif /* PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC */
  384. #if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)
  385. #define MBEDTLS_PK_CAN_ECDSA_VERIFY
  386. #endif /* PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY */
  387. #endif /* PSA_WANT_ALG_ECDSA */
  388. #endif /* MBEDTLS_USE_PSA_CRYPTO */
  389. #if defined(MBEDTLS_PK_CAN_ECDSA_VERIFY) || defined(MBEDTLS_PK_CAN_ECDSA_SIGN)
  390. #define MBEDTLS_PK_CAN_ECDSA_SOME
  391. #endif
  392. /* Helpers to state that each key is supported either on the builtin or PSA side. */
  393. #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_521)
  394. #define MBEDTLS_ECP_HAVE_SECP521R1
  395. #endif
  396. #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) || defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512)
  397. #define MBEDTLS_ECP_HAVE_BP512R1
  398. #endif
  399. #if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) || defined(PSA_WANT_ECC_MONTGOMERY_448)
  400. #define MBEDTLS_ECP_HAVE_CURVE448
  401. #endif
  402. #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) || defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384)
  403. #define MBEDTLS_ECP_HAVE_BP384R1
  404. #endif
  405. #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_384)
  406. #define MBEDTLS_ECP_HAVE_SECP384R1
  407. #endif
  408. #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) || defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
  409. #define MBEDTLS_ECP_HAVE_BP256R1
  410. #endif
  411. #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) || defined(PSA_WANT_ECC_SECP_K1_256)
  412. #define MBEDTLS_ECP_HAVE_SECP256K1
  413. #endif
  414. #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_256)
  415. #define MBEDTLS_ECP_HAVE_SECP256R1
  416. #endif
  417. #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) || defined(PSA_WANT_ECC_MONTGOMERY_255)
  418. #define MBEDTLS_ECP_HAVE_CURVE25519
  419. #endif
  420. #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || defined(PSA_WANT_ECC_SECP_K1_224)
  421. #define MBEDTLS_ECP_HAVE_SECP224K1
  422. #endif
  423. #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_224)
  424. #define MBEDTLS_ECP_HAVE_SECP224R1
  425. #endif
  426. #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || defined(PSA_WANT_ECC_SECP_K1_192)
  427. #define MBEDTLS_ECP_HAVE_SECP192K1
  428. #endif
  429. #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_192)
  430. #define MBEDTLS_ECP_HAVE_SECP192R1
  431. #endif
  432. /* Helper symbol to state that the PK module has support for EC keys. This
  433. * can either be provided through the legacy ECP solution or through the
  434. * PSA friendly MBEDTLS_PK_USE_PSA_EC_DATA (see pk.h for its description). */
  435. #if defined(MBEDTLS_ECP_C) || \
  436. (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY))
  437. #define MBEDTLS_PK_HAVE_ECC_KEYS
  438. #endif /* MBEDTLS_PK_USE_PSA_EC_DATA || MBEDTLS_ECP_C */
  439. /* Historically pkparse did not check the CBC padding when decrypting
  440. * a key. This was a bug, which is now fixed. As a consequence, pkparse
  441. * now needs PKCS7 padding support, but existing configurations might not
  442. * enable it, so we enable it here. */
  443. #if defined(MBEDTLS_PK_PARSE_C) && defined(MBEDTLS_PKCS5_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
  444. #define MBEDTLS_CIPHER_PADDING_PKCS7
  445. #endif
  446. /* Backwards compatibility for some macros which were renamed to reflect that
  447. * they are related to Armv8, not aarch64. */
  448. #if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) && \
  449. !defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT)
  450. #define MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
  451. #endif
  452. #if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY) && !defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY)
  453. #define MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
  454. #endif
  455. /* psa_util file features some ECDSA conversion functions, to convert between
  456. * legacy's ASN.1 DER format and PSA's raw one. */
  457. #if (defined(MBEDTLS_PSA_CRYPTO_CLIENT) && \
  458. (defined(PSA_WANT_ALG_ECDSA) || defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA)))
  459. #define MBEDTLS_PSA_UTIL_HAVE_ECDSA
  460. #endif
  461. /* Some internal helpers to determine which keys are available. */
  462. #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_AES_C)) || \
  463. (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_AES))
  464. #define MBEDTLS_SSL_HAVE_AES
  465. #endif
  466. #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_ARIA_C)) || \
  467. (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_ARIA))
  468. #define MBEDTLS_SSL_HAVE_ARIA
  469. #endif
  470. #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CAMELLIA_C)) || \
  471. (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_CAMELLIA))
  472. #define MBEDTLS_SSL_HAVE_CAMELLIA
  473. #endif
  474. /* Some internal helpers to determine which operation modes are available. */
  475. #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CIPHER_MODE_CBC)) || \
  476. (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CBC_NO_PADDING))
  477. #define MBEDTLS_SSL_HAVE_CBC
  478. #endif
  479. #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_GCM_C)) || \
  480. (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_GCM))
  481. #define MBEDTLS_SSL_HAVE_GCM
  482. #endif
  483. #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CCM_C)) || \
  484. (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CCM))
  485. #define MBEDTLS_SSL_HAVE_CCM
  486. #endif
  487. #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CHACHAPOLY_C)) || \
  488. (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CHACHA20_POLY1305))
  489. #define MBEDTLS_SSL_HAVE_CHACHAPOLY
  490. #endif
  491. #if defined(MBEDTLS_SSL_HAVE_GCM) || defined(MBEDTLS_SSL_HAVE_CCM) || \
  492. defined(MBEDTLS_SSL_HAVE_CHACHAPOLY)
  493. #define MBEDTLS_SSL_HAVE_AEAD
  494. #endif
  495. #endif /* MBEDTLS_CONFIG_ADJUST_LEGACY_CRYPTO_H */