user_settings.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /* user_settings.h
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* This user_settings.h is for Espressif ESP-IDF
  22. *
  23. * Standardized wolfSSL Espressif ESP32 + ESP8266 user_settings.h V5.7.0-1
  24. *
  25. * Do not include any wolfssl headers here
  26. *
  27. * When editing this file:
  28. * ensure wolfssl_test and wolfssl_benchmark settings match.
  29. */
  30. /* The Espressif project config file. See also sdkconfig.defaults */
  31. #include "sdkconfig.h"
  32. /* The Espressif sdkconfig will have chipset info.
  33. **
  34. ** Some possible values:
  35. **
  36. ** CONFIG_IDF_TARGET_ESP32
  37. ** CONFIG_IDF_TARGET_ESP32S2
  38. ** CONFIG_IDF_TARGET_ESP32S3
  39. ** CONFIG_IDF_TARGET_ESP32C3
  40. ** CONFIG_IDF_TARGET_ESP32C6
  41. */
  42. #undef WOLFSSL_ESPIDF
  43. #define WOLFSSL_ESPIDF
  44. /* We don't use WiFi, so don't compile in the esp-sdk-lib WiFi helpers: */
  45. #define NO_ESP_SDK_WIFI
  46. /* Experimental Kyber */
  47. #if 0
  48. /* Kyber typically needs a minimum 10K stack */
  49. #define WOLFSSL_EXPERIMENTAL_SETTINGS
  50. #define WOLFSSL_HAVE_KYBER
  51. #define WOLFSSL_WC_KYBER
  52. #define WOLFSSL_SHA3
  53. #endif
  54. /*
  55. * ONE of these Espressif chip families will be detected from sdkconfig:
  56. *
  57. * WOLFSSL_ESP32
  58. * WOLFSSL_ESP8266
  59. */
  60. #undef WOLFSSL_ESPWROOM32SE
  61. #undef WOLFSSL_ESP8266
  62. #undef WOLFSSL_ESP32
  63. /* See below for chipset detection from sdkconfig.h */
  64. /* when you want to use SINGLE THREAD. Note Default ESP-IDF is FreeRTOS */
  65. /* #define SINGLE_THREADED */
  66. /* SMALL_SESSION_CACHE saves a lot of RAM for ClientCache and SessionCache.
  67. * Memory requirement is about 5KB, otherwise 20K is needed when not specified.
  68. * If extra small footprint is needed, try MICRO_SESSION_CACHE (< 1K)
  69. * When really desperate or no TLS used, try NO_SESSION_CACHE. */
  70. #define NO_SESSION_CACHE
  71. /* Small Stack uses more heap. */
  72. #define WOLFSSL_SMALL_STACK
  73. /* Full debugging turned off, but show malloc failure detail */
  74. /* #define DEBUG_WOLFSSL */
  75. #define DEBUG_WOLFSSL_MALLOC
  76. /* See test.c that sets cert buffers; we'll set them here: */
  77. #define USE_CERT_BUFFERS_256
  78. #define USE_CERT_BUFFERS_2048
  79. /* RSA_LOW_MEM: Half as much memory but twice as slow. */
  80. #define RSA_LOW_MEM
  81. /* Uncommon settings for testing only */
  82. #define TEST_ESPIDF_ALL_WOLFSSL
  83. #ifdef TEST_ESPIDF_ALL_WOLFSSL
  84. #define WOLFSSL_MD2
  85. #define HAVE_BLAKE2
  86. #define HAVE_BLAKE2B
  87. #define HAVE_BLAKE2S
  88. #define WC_RC2
  89. #define WOLFSSL_ALLOW_RC4
  90. #define HAVE_POLY1305
  91. #define WOLFSSL_AES_128
  92. #define WOLFSSL_AES_OFB
  93. #define WOLFSSL_AES_CFB
  94. #define WOLFSSL_AES_XTS
  95. /* #define WC_SRTP_KDF */
  96. /* TODO Causes failure with Espressif AES HW Enabled */
  97. /* #define HAVE_AES_ECB */
  98. /* #define HAVE_AESCCM */
  99. /* TODO sanity check when missing HAVE_AES_ECB */
  100. #define WOLFSSL_WOLFSSH
  101. #define HAVE_AESGCM
  102. #define WOLFSSL_AES_COUNTER
  103. #define HAVE_FFDHE
  104. #define HAVE_FFDHE_2048
  105. #if defined(CONFIG_IDF_TARGET_ESP8266)
  106. /* TODO Full size SRP is disabled on the ESP8266 at this time.
  107. * Low memory issue? */
  108. #define WOLFCRYPT_HAVE_SRP
  109. /* MIN_FFDHE_FP_MAX_BITS = (MIN_FFDHE_BITS * 2); see settings.h */
  110. #define FP_MAX_BITS MIN_FFDHE_FP_MAX_BITS
  111. #elif defined(CONFIG_IDF_TARGET_ESP32) || \
  112. defined(CONFIG_IDF_TARGET_ESP32S2) || \
  113. defined(CONFIG_IDF_TARGET_ESP32S3)
  114. /* TODO: SRP Not enabled, known to fail on this target
  115. * See https://github.com/wolfSSL/wolfssl/issues/7210 */
  116. #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
  117. defined(CONFIG_IDF_TARGET_ESP32H2)
  118. /* SRP Known to be working on this target::*/
  119. #define WOLFCRYPT_HAVE_SRP
  120. #define FP_MAX_BITS (8192 * 2)
  121. #else
  122. /* For everything else, give a try and see if SRP working: */
  123. #define WOLFCRYPT_HAVE_SRP
  124. #define FP_MAX_BITS (8192 * 2)
  125. #endif
  126. #define HAVE_DH
  127. /* TODO: there may be a problem with HAVE_CAMELLIA with HW AES disabled.
  128. * Do not define NO_WOLFSSL_ESP32_CRYPT_AES when enabled: */
  129. /* #define HAVE_CAMELLIA */
  130. /* DSA requires old SHA */
  131. #define HAVE_DSA
  132. /* Needs SHA512 ? */
  133. #define HAVE_HPKE
  134. /* Not for Espressif? */
  135. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  136. defined(CONFIG_IDF_TARGET_ESP8684) || \
  137. defined(CONFIG_IDF_TARGET_ESP32H2) || \
  138. defined(CONFIG_IDF_TARGET_ESP8266)
  139. #if defined(CONFIG_IDF_TARGET_ESP8266)
  140. #undef HAVE_ECC
  141. #undef HAVE_ECC_CDH
  142. #undef HAVE_CURVE25519
  143. /* TODO does CHACHA also need alignment? Failing on ESP8266
  144. * See SHA256 __attribute__((aligned(4))); and WC_SHA256_ALIGN */
  145. #ifdef HAVE_CHACHA
  146. #error "HAVE_CHACHA not supported on ESP8266"
  147. #endif
  148. #ifdef HAVE_XCHACHA
  149. #error "HAVE_XCHACHA not supported on ESP8266"
  150. #endif
  151. #else
  152. #define HAVE_XCHACHA
  153. #define HAVE_CHACHA
  154. /* TODO Not enabled at this time, needs further testing:
  155. * #define WC_SRTP_KDF
  156. * #define HAVE_COMP_KEY
  157. * #define WOLFSSL_HAVE_XMSS
  158. */
  159. #endif
  160. /* TODO AES-EAX not working on this platform */
  161. /* Optionally disable DH
  162. * #undef HAVE_DH
  163. * #undef HAVE_FFDHE
  164. */
  165. /* ECC_SHAMIR out of memory on ESP32-C2 during ECC */
  166. #ifndef HAVE_ECC
  167. #define ECC_SHAMIR
  168. #endif
  169. #else
  170. #define WOLFSSL_AES_EAX
  171. #define ECC_SHAMIR
  172. #endif
  173. /* Only for WOLFSSL_IMX6_CAAM / WOLFSSL_QNX_CAAM ? */
  174. /* #define WOLFSSL_CAAM */
  175. /* #define WOLFSSL_CAAM_BLOB */
  176. #define WOLFSSL_AES_SIV
  177. #define WOLFSSL_CMAC
  178. #define WOLFSSL_CERT_PIV
  179. /* HAVE_SCRYPT may turn on HAVE_PBKDF2 see settings.h */
  180. /* #define HAVE_SCRYPT */
  181. #define SCRYPT_TEST_ALL
  182. #define HAVE_X963_KDF
  183. #endif
  184. /* optionally turn off SHA512/224 SHA512/256 */
  185. /* #define WOLFSSL_NOSHA512_224 */
  186. /* #define WOLFSSL_NOSHA512_256 */
  187. /* when you want to use SINGLE THREAD. Note Default ESP-IDF is FreeRTOS */
  188. /* #define SINGLE_THREADED */
  189. /* When you don't want to use the old SHA */
  190. /* #define NO_SHA */
  191. /* #define NO_OLD_TLS */
  192. #define BENCH_EMBEDDED
  193. /* TLS 1.3 */
  194. #define WOLFSSL_TLS13
  195. #define HAVE_TLS_EXTENSIONS
  196. #define WC_RSA_PSS
  197. #define HAVE_HKDF
  198. #define HAVE_AEAD
  199. #define HAVE_SUPPORTED_CURVES
  200. #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  201. #define NO_FILESYSTEM
  202. #define NO_OLD_TLS
  203. #define HAVE_AESGCM
  204. /* Optional RIPEMD: RACE Integrity Primitives Evaluation Message Digest */
  205. /* #define WOLFSSL_RIPEMD */
  206. /* when you want to use SHA224 */
  207. #define WOLFSSL_SHA224
  208. /* when you want to use SHA384 */
  209. #define WOLFSSL_SHA384
  210. /* when you want to use SHA512 */
  211. #define WOLFSSL_SHA512
  212. /* when you want to use SHA3 */
  213. #define WOLFSSL_SHA3
  214. /* ED25519 requires SHA512 */
  215. #define HAVE_ED25519
  216. /* Some features not enabled for ESP8266: */
  217. #if defined(CONFIG_IDF_TARGET_ESP8266) || \
  218. defined(CONFIG_IDF_TARGET_ESP32C2)
  219. /* TODO determine low memory configuration for ECC. */
  220. #else
  221. #define HAVE_ECC
  222. #define HAVE_CURVE25519
  223. #define CURVE25519_SMALL
  224. #endif
  225. #define HAVE_ED25519
  226. /* Optional OPENSSL compatibility */
  227. #define OPENSSL_EXTRA
  228. /* #Optional HAVE_PKCS7 */
  229. #define HAVE_PKCS7
  230. #if defined(HAVE_PKCS7)
  231. /* HAVE_PKCS7 may enable HAVE_PBKDF2 see settings.h */
  232. #define NO_PBKDF2
  233. #define HAVE_AES_KEYWRAP
  234. #define HAVE_X963_KDF
  235. #define WOLFSSL_AES_DIRECT
  236. #endif
  237. /* when you want to use AES counter mode */
  238. /* #define WOLFSSL_AES_DIRECT */
  239. /* #define WOLFSSL_AES_COUNTER */
  240. /* esp32-wroom-32se specific definition */
  241. #if defined(WOLFSSL_ESPWROOM32SE)
  242. #define WOLFSSL_ATECC508A
  243. #define HAVE_PK_CALLBACKS
  244. /* when you want to use a custom slot allocation for ATECC608A */
  245. /* unless your configuration is unusual, you can use default */
  246. /* implementation. */
  247. /* #define CUSTOM_SLOT_ALLOCATION */
  248. #endif
  249. /* WC_NO_CACHE_RESISTANT: slower but more secure */
  250. /* #define WC_NO_CACHE_RESISTANT */
  251. /* TFM_TIMING_RESISTANT: slower but more secure */
  252. /* #define TFM_TIMING_RESISTANT */
  253. /* #define WOLFSSL_ATECC508A_DEBUG */
  254. /* date/time */
  255. /* if it cannot adjust time in the device, */
  256. /* enable macro below */
  257. /* #define NO_ASN_TIME */
  258. /* #define XTIME time */
  259. /* adjust wait-timeout count if you see timeout in RSA HW acceleration */
  260. #define ESP_RSA_TIMEOUT_CNT 0x349F00
  261. /* hash limit for test.c */
  262. #define HASH_SIZE_LIMIT
  263. /* USE_FAST_MATH is default */
  264. #define USE_FAST_MATH
  265. /***** Use SP_MATH *****/
  266. /* #undef USE_FAST_MATH */
  267. /* #define SP_MATH */
  268. /* #define WOLFSSL_SP_MATH_ALL */
  269. /* #define WOLFSSL_SP_RISCV32 */
  270. /***** Use Integer Heap Math *****/
  271. /* #undef USE_FAST_MATH */
  272. /* #define USE_INTEGER_HEAP_MATH */
  273. #define WOLFSSL_SMALL_STACK
  274. #define HAVE_VERSION_EXTENDED_INFO
  275. /* #define HAVE_WC_INTROSPECTION */
  276. #define HAVE_SESSION_TICKET
  277. /* #define HAVE_HASHDRBG */
  278. #define WOLFSSL_KEY_GEN
  279. #define WOLFSSL_CERT_REQ
  280. #define WOLFSSL_CERT_GEN
  281. #define WOLFSSL_CERT_EXT
  282. #define WOLFSSL_SYS_CA_CERTS
  283. #define WOLFSSL_CERT_TEXT
  284. #define WOLFSSL_ASN_TEMPLATE
  285. /*
  286. #undef WOLFSSL_KEY_GEN
  287. #undef WOLFSSL_CERT_REQ
  288. #undef WOLFSSL_CERT_GEN
  289. #undef WOLFSSL_CERT_EXT
  290. #undef WOLFSSL_SYS_CA_CERTS
  291. */
  292. /* command-line options
  293. --enable-keygen
  294. --enable-certgen
  295. --enable-certreq
  296. --enable-certext
  297. --enable-asn-template
  298. */
  299. /* Chipset detection from sdkconfig.h
  300. * Default is HW enabled unless turned off.
  301. * Uncomment lines to force SW instead of HW acceleration */
  302. #if defined(CONFIG_IDF_TARGET_ESP32)
  303. #define WOLFSSL_ESP32
  304. /* Alternatively, if there's an ECC Secure Element present: */
  305. /* #define WOLFSSL_ESPWROOM32SE */
  306. /* wolfSSL HW Acceleration supported on ESP32. Uncomment to disable: */
  307. /* #define NO_ESP32_CRYPT */
  308. /* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
  309. /* #define NO_WOLFSSL_ESP32_CRYPT_AES */
  310. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
  311. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
  312. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
  313. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
  314. /* These are defined automatically in esp32-crypt.h, here for clarity: */
  315. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA224 /* no SHA224 HW on ESP32 */
  316. #undef ESP_RSA_MULM_BITS
  317. #define ESP_RSA_MULM_BITS 16 /* TODO add compile-time warning */
  318. /***** END CONFIG_IDF_TARGET_ESP32 *****/
  319. #elif defined(CONFIG_IDF_TARGET_ESP32S2)
  320. #define WOLFSSL_ESP32
  321. /* wolfSSL HW Acceleration supported on ESP32-S2. Uncomment to disable: */
  322. /* #define NO_ESP32_CRYPT */
  323. /* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
  324. /* Note: There's no AES192 HW on the ESP32-S2; falls back to SW */
  325. /* #define NO_WOLFSSL_ESP32_CRYPT_AES */
  326. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
  327. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
  328. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
  329. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
  330. /***** END CONFIG_IDF_TARGET_ESP32S2 *****/
  331. #elif defined(CONFIG_IDF_TARGET_ESP32S3)
  332. #define WOLFSSL_ESP32
  333. /* wolfSSL HW Acceleration supported on ESP32-S3. Uncomment to disable: */
  334. /* #define NO_ESP32_CRYPT */
  335. /* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
  336. /* Note: There's no AES192 HW on the ESP32-S3; falls back to SW */
  337. /* #define NO_WOLFSSL_ESP32_CRYPT_AES */
  338. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
  339. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
  340. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
  341. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
  342. /***** END CONFIG_IDF_TARGET_ESP32S3 *****/
  343. #elif defined(CONFIG_IDF_TARGET_ESP32C2) || \
  344. defined(CONFIG_IDF_TARGET_ESP8684)
  345. #define WOLFSSL_ESP32
  346. /* ESP8684 is essentially ESP32-C2 chip + flash embedded together in a
  347. * single QFN 4x4 mm package. Out of released documentation, Technical
  348. * Reference Manual as well as ESP-IDF Programming Guide is applicable
  349. * to both ESP32-C2 and ESP8684.
  350. *
  351. * See: https://www.esp32.com/viewtopic.php?f=5&t=27926#:~:text=ESP8684%20is%20essentially%20ESP32%2DC2,both%20ESP32%2DC2%20and%20ESP8684. */
  352. /* wolfSSL HW Acceleration supported on ESP32-C2. Uncomment to disable: */
  353. /* #define NO_ESP32_CRYPT */
  354. /* #define NO_WOLFSSL_ESP32_CRYPT_HASH */ /* to disable all SHA HW */
  355. /* These are defined automatically in esp32-crypt.h, here for clarity */
  356. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA384 /* no SHA384 HW on C2 */
  357. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA512 /* no SHA512 HW on C2 */
  358. /* There's no AES or RSA/Math accelerator on the ESP32-C2
  359. * Auto defined with NO_WOLFSSL_ESP32_CRYPT_RSA_PRI, for clarity: */
  360. #define NO_WOLFSSL_ESP32_CRYPT_AES
  361. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
  362. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL
  363. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD
  364. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD
  365. /***** END CONFIG_IDF_TARGET_ESP32C2 *****/
  366. #elif defined(CONFIG_IDF_TARGET_ESP32C3)
  367. #define WOLFSSL_ESP32
  368. /* wolfSSL HW Acceleration supported on ESP32-C3. Uncomment to disable: */
  369. /* #define NO_ESP32_CRYPT */
  370. /* #define NO_WOLFSSL_ESP32_CRYPT_HASH */ /* to disable all SHA HW */
  371. /* These are defined automatically in esp32-crypt.h, here for clarity: */
  372. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA384 /* no SHA384 HW on C6 */
  373. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA512 /* no SHA512 HW on C6 */
  374. /* #define NO_WOLFSSL_ESP32_CRYPT_AES */
  375. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
  376. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
  377. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
  378. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
  379. /***** END CONFIG_IDF_TARGET_ESP32C3 *****/
  380. #elif defined(CONFIG_IDF_TARGET_ESP32C6)
  381. #define WOLFSSL_ESP32
  382. /* wolfSSL HW Acceleration supported on ESP32-C6. Uncomment to disable: */
  383. /* #define NO_ESP32_CRYPT */
  384. /* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
  385. /* These are defined automatically in esp32-crypt.h, here for clarity: */
  386. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA384 /* no SHA384 HW on C6 */
  387. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA512 /* no SHA512 HW on C6 */
  388. /* #define NO_WOLFSSL_ESP32_CRYPT_AES */
  389. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
  390. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
  391. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
  392. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
  393. /***** END CONFIG_IDF_TARGET_ESP32C6 *****/
  394. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  395. #define WOLFSSL_ESP32
  396. /* wolfSSL Hardware Acceleration not yet implemented */
  397. #define NO_ESP32_CRYPT
  398. #define NO_WOLFSSL_ESP32_CRYPT_HASH
  399. #define NO_WOLFSSL_ESP32_CRYPT_AES
  400. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
  401. /***** END CONFIG_IDF_TARGET_ESP32H2 *****/
  402. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  403. #define WOLFSSL_ESP8266
  404. /* There's no hardware encryption on the ESP8266 */
  405. /* Consider using the ESP32-C2/C3/C6
  406. * See https://www.espressif.com/en/products/socs/esp32-c2 */
  407. #define NO_ESP32_CRYPT
  408. #define NO_WOLFSSL_ESP32_CRYPT_HASH
  409. #define NO_WOLFSSL_ESP32_CRYPT_AES
  410. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
  411. /***** END CONFIG_IDF_TARGET_ESP266 *****/
  412. #elif defined(CONFIG_IDF_TARGET_ESP8684)
  413. /* There's no Hardware Acceleration available on ESP8684 */
  414. #define NO_ESP32_CRYPT
  415. #define NO_WOLFSSL_ESP32_CRYPT_HASH
  416. #define NO_WOLFSSL_ESP32_CRYPT_AES
  417. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
  418. /***** END CONFIG_IDF_TARGET_ESP8684 *****/
  419. #else
  420. /* Anything else encountered, disable HW accleration */
  421. #warning "Unexpected CONFIG_IDF_TARGET_NN value"
  422. #define NO_ESP32_CRYPT
  423. #define NO_WOLFSSL_ESP32_CRYPT_HASH
  424. #define NO_WOLFSSL_ESP32_CRYPT_AES
  425. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
  426. #endif /* CONFIG_IDF_TARGET Check */
  427. /* RSA primitive specific definition, listed AFTER the Chipset detection */
  428. #if defined(WOLFSSL_ESP32) || defined(WOLFSSL_ESPWROOM32SE)
  429. /* Consider USE_FAST_MATH and SMALL_STACK */
  430. #ifndef NO_RSA
  431. #define ESP32_USE_RSA_PRIMITIVE
  432. #if defined(CONFIG_IDF_TARGET_ESP32)
  433. #ifdef CONFIG_ESP_MAIN_TASK_STACK_SIZE
  434. #if CONFIG_ESP_MAIN_TASK_STACK_SIZE < 10500
  435. #warning "RSA may be difficult with less than 10KB Stack "/
  436. #endif
  437. #endif
  438. /* NOTE HW unreliable for small values! */
  439. /* threshold for performance adjustment for HW primitive use */
  440. /* X bits of G^X mod P greater than */
  441. #undef ESP_RSA_EXPT_XBITS
  442. #define ESP_RSA_EXPT_XBITS 32
  443. /* X and Y of X * Y mod P greater than */
  444. #undef ESP_RSA_MULM_BITS
  445. #define ESP_RSA_MULM_BITS 16
  446. #endif
  447. #endif
  448. #endif
  449. /* Debug options:
  450. See wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h for details on debug options
  451. #define ESP_VERIFY_MEMBLOCK
  452. #define DEBUG_WOLFSSL
  453. #define DEBUG_WOLFSSL_VERBOSE
  454. #define DEBUG_WOLFSSL_SHA_MUTEX
  455. #define WOLFSSL_ESP32_CRYPT_DEBUG
  456. #define WOLFSSL_ESP32_CRYPT_HASH_SHA224_DEBUG
  457. #define NO_RECOVER_SOFTWARE_CALC
  458. #define WOLFSSL_TEST_STRAY 1
  459. #define USE_ESP_DPORT_ACCESS_READ_BUFFER
  460. #define WOLFSSL_ESP32_HW_LOCK_DEBUG
  461. #define WOLFSSL_DEBUG_ESP_RSA_MULM_BITS
  462. #define ESP_DISABLE_HW_TASK_LOCK
  463. See wolfcrypt/benchmark/benchmark.c for debug and other settings:
  464. Turn on benchmark timing debugging (CPU Cycles, RTOS ticks, etc)
  465. #define DEBUG_WOLFSSL_BENCHMARK_TIMING
  466. Turn on timer debugging (used when CPU cycles not available)
  467. #define WOLFSSL_BENCHMARK_TIMER_DEBUG
  468. */
  469. /* Pause in a loop rather than exit. */
  470. #define WOLFSSL_ESPIDF_ERROR_PAUSE
  471. #define WOLFSSL_HW_METRICS
  472. /* for test.c */
  473. /* #define HASH_SIZE_LIMIT */
  474. /* Optionally turn off HW math checks */
  475. /* #define NO_HW_MATH_TEST */
  476. /* Optionally include alternate HW test library: alt_hw_test.h */
  477. /* When enabling, the ./components/wolfssl/CMakeLists.txt file
  478. * will need the name of the library in the idf_component_register
  479. * for the PRIV_REQUIRES list. */
  480. /* #define INCLUDE_ALT_HW_TEST */
  481. /* optionally turn off individual math HW acceleration features */
  482. /* Turn off Large Number ESP32 HW Multiplication:
  483. ** [Z = X * Y] in esp_mp_mul() */
  484. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
  485. /* Turn off Large Number ESP32 HW Modular Exponentiation:
  486. ** [Z = X^Y mod M] in esp_mp_exptmod() */
  487. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
  488. /* Turn off Large Number ESP32 HW Modular Multiplication
  489. ** [Z = X * Y mod M] in esp_mp_mulmod() */
  490. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
  491. /* used by benchmark: */
  492. #define WOLFSSL_PUBLIC_MP
  493. /* when turning on ECC508 / ECC608 support
  494. #define WOLFSSL_ESPWROOM32SE
  495. #define HAVE_PK_CALLBACKS
  496. #define WOLFSSL_ATECC508A
  497. #define ATCA_WOLFSSL
  498. */
  499. /***************************** Certificate Macros *****************************
  500. *
  501. * The section below defines macros used in typically all of the wolfSSL
  502. * examples such as the client and server for certs stored in header files.
  503. *
  504. * There are various certificate examples in this header file:
  505. * https://github.com/wolfSSL/wolfssl/blob/master/wolfssl/certs_test.h
  506. *
  507. * To use the sets of macros below, define *one* of these:
  508. *
  509. * USE_CERT_BUFFERS_1024 - ECC 1024 bit encoded ASN1
  510. * USE_CERT_BUFFERS_2048 - RSA 2048 bit encoded ASN1
  511. * WOLFSSL_SM[2,3,4] - SM Ciphers
  512. *
  513. * For example: define USE_CERT_BUFFERS_2048 to use CA Certs used in this
  514. * wolfSSL function for the `ca_cert_der_2048` buffer, size and types:
  515. *
  516. * ret = wolfSSL_CTX_load_verify_buffer(ctx,
  517. * CTX_CA_CERT,
  518. * CTX_CA_CERT_SIZE,
  519. * CTX_CA_CERT_TYPE);
  520. *
  521. * See https://www.wolfssl.com/documentation/manuals/wolfssl/group__CertsKeys.html#function-wolfssl_ctx_load_verify_buffer
  522. *
  523. * In this case the CTX_CA_CERT will be defined as `ca_cert_der_2048` as
  524. * defined here: https://github.com/wolfSSL/wolfssl/blob/master/wolfssl/certs_test.h
  525. *
  526. * The CTX_CA_CERT_SIZE and CTX_CA_CERT_TYPE are similarly used to reference
  527. * array size and cert type respectively.
  528. *
  529. * Similarly for loading the private client key:
  530. *
  531. * ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx,
  532. * CTX_CLIENT_KEY,
  533. * CTX_CLIENT_KEY_SIZE,
  534. * CTX_CLIENT_KEY_TYPE);
  535. *
  536. * see https://www.wolfssl.com/documentation/manuals/wolfssl/group__CertsKeys.html#function-wolfssl_ctx_use_privatekey_buffer
  537. *
  538. * Similarly, the other macros are for server certificates and keys:
  539. * `CTX_SERVER_CERT` and `CTX_SERVER_KEY` are available.
  540. *
  541. * The certificate and key names are typically `static const unsigned char`
  542. * arrays. The [NAME]_size are typically `sizeof([array name])`, and the types
  543. * are the known wolfSSL encoding type integers (e.g. WOLFSSL_FILETYPE_PEM).
  544. *
  545. * See `SSL_FILETYPE_[name]` in
  546. * https://github.com/wolfSSL/wolfssl/blob/master/wolfssl/ssl.h
  547. *
  548. * See Abstract Syntax Notation One (ASN.1) in:
  549. * https://github.com/wolfSSL/wolfssl/blob/master/wolfssl/wolfcrypt/asn.h
  550. *
  551. * Optional SM4 Ciphers:
  552. *
  553. * Although the SM ciphers are shown here, the `certs_test_sm.h` may not yet
  554. * be available. See:
  555. * https://github.com/wolfSSL/wolfssl/pull/6825
  556. * https://github.com/wolfSSL/wolfsm
  557. *
  558. * Uncomment these 3 macros to enable the SM Ciphers and use the macros below.
  559. */
  560. /*
  561. #define WOLFSSL_SM2
  562. #define WOLFSSL_SM3
  563. #define WOLFSSL_SM4
  564. */
  565. /* Conditional macros used in wolfSSL TLS client and server examples */
  566. #if defined(WOLFSSL_SM2) || defined(WOLFSSL_SM3) || defined(WOLFSSL_SM4)
  567. #include <wolfssl/certs_test_sm.h>
  568. #define CTX_CA_CERT root_sm2
  569. #define CTX_CA_CERT_SIZE sizeof_root_sm2
  570. #define CTX_CA_CERT_TYPE WOLFSSL_FILETYPE_PEM
  571. #define CTX_SERVER_CERT server_sm2
  572. #define CTX_SERVER_CERT_SIZE sizeof_server_sm2
  573. #define CTX_SERVER_CERT_TYPE WOLFSSL_FILETYPE_PEM
  574. #define CTX_SERVER_KEY server_sm2_priv
  575. #define CTX_SERVER_KEY_SIZE sizeof_server_sm2_priv
  576. #define CTX_SERVER_KEY_TYPE WOLFSSL_FILETYPE_PEM
  577. #undef WOLFSSL_BASE16
  578. #define WOLFSSL_BASE16
  579. #else
  580. #if defined(USE_CERT_BUFFERS_2048)
  581. /* Be sure to include in app when using example certs: */
  582. /* #include <wolfssl/certs_test.h> */
  583. #define CTX_CA_CERT ca_cert_der_2048
  584. #define CTX_CA_CERT_SIZE sizeof_ca_cert_der_2048
  585. #define CTX_CA_CERT_TYPE WOLFSSL_FILETYPE_ASN1
  586. #define CTX_SERVER_CERT server_cert_der_2048
  587. #define CTX_SERVER_CERT_SIZE sizeof_server_cert_der_2048
  588. #define CTX_SERVER_CERT_TYPE WOLFSSL_FILETYPE_ASN1
  589. #define CTX_SERVER_KEY server_key_der_2048
  590. #define CTX_SERVER_KEY_SIZE sizeof_server_key_der_2048
  591. #define CTX_SERVER_KEY_TYPE WOLFSSL_FILETYPE_ASN1
  592. #define CTX_CLIENT_CERT client_cert_der_2048
  593. #define CTX_CLIENT_CERT_SIZE sizeof_client_cert_der_2048
  594. #define CTX_CLIENT_CERT_TYPE WOLFSSL_FILETYPE_ASN1
  595. #define CTX_CLIENT_KEY client_key_der_2048
  596. #define CTX_CLIENT_KEY_SIZE sizeof_client_key_der_2048
  597. #define CTX_CLIENT_KEY_TYPE WOLFSSL_FILETYPE_ASN1
  598. #elif defined(USE_CERT_BUFFERS_1024)
  599. /* Be sure to include in app when using example certs: */
  600. /* #include <wolfssl/certs_test.h> */
  601. #define CTX_CA_CERT ca_cert_der_1024
  602. #define CTX_CA_CERT_SIZE sizeof_ca_cert_der_1024
  603. #define CTX_CA_CERT_TYPE WOLFSSL_FILETYPE_ASN1
  604. #define CTX_CLIENT_CERT client_cert_der_1024
  605. #define CTX_CLIENT_CERT_SIZE sizeof_client_cert_der_1024
  606. #define CTX_CLIENT_CERT_TYPE WOLFSSL_FILETYPE_ASN1
  607. #define CTX_CLIENT_KEY client_key_der_1024
  608. #define CTX_CLIENT_KEY_SIZE sizeof_client_key_der_1024
  609. #define CTX_CLIENT_KEY_TYPE WOLFSSL_FILETYPE_ASN1
  610. #define CTX_SERVER_CERT server_cert_der_1024
  611. #define CTX_SERVER_CERT_SIZE sizeof_server_cert_der_1024
  612. #define CTX_SERVER_CERT_TYPE WOLFSSL_FILETYPE_ASN1
  613. #define CTX_SERVER_KEY server_key_der_1024
  614. #define CTX_SERVER_KEY_SIZE sizeof_server_key_der_1024
  615. #define CTX_SERVER_KEY_TYPE WOLFSSL_FILETYPE_ASN1
  616. #else
  617. /* Optionally define custom cert arrays, sizes, and types here */
  618. #error "Must define USE_CERT_BUFFERS_2048 or USE_CERT_BUFFERS_1024"
  619. #endif
  620. #endif /* Conditional key and cert constant names */