user_settings.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /* user_settings.h
  2. *
  3. * Copyright (C) 2006-2023 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. #include <sdkconfig.h>
  23. /* The Espressif sdkconfig will have chipset info.
  24. **
  25. ** Possible values:
  26. **
  27. ** CONFIG_IDF_TARGET_ESP32
  28. ** CONFIG_IDF_TARGET_ESP32S2
  29. ** CONFIG_IDF_TARGET_ESP32S3
  30. ** CONFIG_IDF_TARGET_ESP32C3
  31. ** CONFIG_IDF_TARGET_ESP32C6
  32. */
  33. #undef WOLFSSL_ESPIDF
  34. #define WOLFSSL_ESPIDF
  35. /*
  36. * choose ONE of these Espressif chips to define:
  37. *
  38. * WOLFSSL_ESP32
  39. * WOLFSSL_ESPWROOM32SE
  40. * WOLFSSL_ESP8266
  41. */
  42. #undef WOLFSSL_ESPWROOM32SE
  43. #undef WOLFSSL_ESP8266
  44. #undef WOLFSSL_ESP32
  45. #define WOLFSSL_ESP32
  46. /* optionally turn off SHA512/224 SHA512/256 */
  47. /* #define WOLFSSL_NOSHA512_224 */
  48. /* #define WOLFSSL_NOSHA512_256 */
  49. /* when you want to use SINGLE THREAD. Note Default ESP-IDF is FreeRTOS */
  50. /* #define SINGLE_THREADED */
  51. /* When you don't want to use the old SHA */
  52. /* #define NO_SHA */
  53. /* #define NO_OLD_TLS */
  54. #define BENCH_EMBEDDED
  55. #define USE_CERT_BUFFERS_2048
  56. /* TLS 1.3 */
  57. #define WOLFSSL_TLS13
  58. #define HAVE_TLS_EXTENSIONS
  59. #define WC_RSA_PSS
  60. #define HAVE_HKDF
  61. #define HAVE_AEAD
  62. #define HAVE_SUPPORTED_CURVES
  63. #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  64. #define NO_FILESYSTEM
  65. #define NO_OLD_TLS
  66. #define HAVE_AESGCM
  67. #define WOLFSSL_RIPEMD
  68. /* when you want to use SHA224 */
  69. #define WOLFSSL_SHA224
  70. /* when you want to use SHA384 */
  71. #define WOLFSSL_SHA384
  72. /* when you want to use SHA512 */
  73. #define WOLFSSL_SHA512
  74. /* when you want to use SHA3 */
  75. #define WOLFSSL_SHA3
  76. #define HAVE_ED25519 /* ED25519 requires SHA512 */
  77. #define HAVE_ECC
  78. #define HAVE_CURVE25519
  79. #define CURVE25519_SMALL
  80. #define HAVE_ED25519
  81. /* Optional OPENSSL compatibility */
  82. #define OPENSSL_EXTRA
  83. /* when you want to use pkcs7 */
  84. /* #define HAVE_PKCS7 */
  85. #define HAVE_PKCS7
  86. #if defined(HAVE_PKCS7)
  87. #define HAVE_AES_KEYWRAP
  88. #define HAVE_X963_KDF
  89. #define WOLFSSL_AES_DIRECT
  90. #endif
  91. /* when you want to use AES counter mode */
  92. /* #define WOLFSSL_AES_DIRECT */
  93. /* #define WOLFSSL_AES_COUNTER */
  94. /* esp32-wroom-32se specific definition */
  95. #if defined(WOLFSSL_ESPWROOM32SE)
  96. #define WOLFSSL_ATECC508A
  97. #define HAVE_PK_CALLBACKS
  98. /* when you want to use a custom slot allocation for ATECC608A */
  99. /* unless your configuration is unusual, you can use default */
  100. /* implementation. */
  101. /* #define CUSTOM_SLOT_ALLOCATION */
  102. #endif
  103. /* RSA primitive specific definition */
  104. #if defined(WOLFSSL_ESP32) || defined(WOLFSSL_ESPWROOM32SE)
  105. /* Define USE_FAST_MATH and SMALL_STACK */
  106. #define ESP32_USE_RSA_PRIMITIVE
  107. #if defined(CONFIG_IDF_TARGET_ESP32)
  108. /* NOTE HW unreliable for small values! */
  109. /* threshold for performance adjustment for HW primitive use */
  110. /* X bits of G^X mod P greater than */
  111. #undef ESP_RSA_EXPT_XBITS
  112. #define ESP_RSA_EXPT_XBITS 32
  113. /* X and Y of X * Y mod P greater than */
  114. #undef ESP_RSA_MULM_BITS
  115. #define ESP_RSA_MULM_BITS 16
  116. #endif
  117. #endif
  118. #define RSA_LOW_MEM
  119. /* #define WOLFSSL_ATECC508A_DEBUG */
  120. /* date/time */
  121. /* if it cannot adjust time in the device, */
  122. /* enable macro below */
  123. /* #define NO_ASN_TIME */
  124. /* #define XTIME time */
  125. /* adjust wait-timeout count if you see timeout in RSA HW acceleration */
  126. #define ESP_RSA_TIMEOUT_CNT 0x249F00
  127. #define HASH_SIZE_LIMIT /* for test.c */
  128. /* USE_FAST_MATH is default */
  129. #define USE_FAST_MATH
  130. /***** Use SP_MATH *****/
  131. /* #undef USE_FAST_MATH */
  132. /* #define SP_MATH */
  133. /* #define WOLFSSL_SP_MATH_ALL */
  134. /***** Use Integer Heap Math *****/
  135. /* #undef USE_FAST_MATH */
  136. /* #define USE_INTEGER_HEAP_MATH */
  137. #define WOLFSSL_SMALL_STACK
  138. #define HAVE_VERSION_EXTENDED_INFO
  139. /* #define HAVE_WC_INTROSPECTION */
  140. #define HAVE_SESSION_TICKET
  141. /* #define HAVE_HASHDRBG */
  142. #define WOLFSSL_KEY_GEN
  143. #define WOLFSSL_CERT_REQ
  144. #define WOLFSSL_CERT_GEN
  145. #define WOLFSSL_CERT_EXT
  146. #define WOLFSSL_SYS_CA_CERTS
  147. #define WOLFSSL_CERT_TEXT
  148. #define WOLFSSL_ASN_TEMPLATE
  149. /*
  150. #undef WOLFSSL_KEY_GEN
  151. #undef WOLFSSL_CERT_REQ
  152. #undef WOLFSSL_CERT_GEN
  153. #undef WOLFSSL_CERT_EXT
  154. #undef WOLFSSL_SYS_CA_CERTS
  155. */
  156. /*
  157. --enable-keygen
  158. --enable-certgen
  159. --enable-certreq
  160. --enable-certext
  161. --enable-asn-template
  162. */
  163. /* Default is HW enabled unless turned off.
  164. ** Uncomment these lines to force SW instead of HW acceleration */
  165. #if defined(CONFIG_IDF_TARGET_ESP32)
  166. /* wolfSSL HW Acceleration supported on ESP32. Uncomment to disable: */
  167. /* #define NO_ESP32_CRYPT */
  168. /* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
  169. /* #define NO_WOLFSSL_ESP32_CRYPT_AES */
  170. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
  171. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
  172. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
  173. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
  174. /* These are defined automatically in esp32-crypt.h, here for clarity: */
  175. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA224 /* no SHA224 HW on ESP32 */
  176. #undef ESP_RSA_MULM_BITS
  177. #define ESP_RSA_MULM_BITS 16 /* TODO add compile-time warning */
  178. /***** END CONFIG_IDF_TARGET_ESP32 *****/
  179. #elif defined(CONFIG_IDF_TARGET_ESP32S2)
  180. /* wolfSSL HW Acceleration supported on ESP32-S2. Uncomment to disable: */
  181. /* #define NO_ESP32_CRYPT */
  182. /* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
  183. /* Note: There's no AES192 HW on the ESP32-S2; falls back to SW */
  184. /* #define NO_WOLFSSL_ESP32_CRYPT_AES */
  185. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
  186. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
  187. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
  188. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
  189. /***** END CONFIG_IDF_TARGET_ESP32S2 *****/
  190. #elif defined(CONFIG_IDF_TARGET_ESP32S3)
  191. /* wolfSSL HW Acceleration supported on ESP32-S3. Uncomment to disable: */
  192. /* #define NO_ESP32_CRYPT */
  193. /* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
  194. /* Note: There's no AES192 HW on the ESP32-S3; falls back to SW */
  195. /* #define NO_WOLFSSL_ESP32_CRYPT_AES */
  196. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
  197. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
  198. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
  199. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
  200. /***** END CONFIG_IDF_TARGET_ESP32S3 *****/
  201. #elif defined(CONFIG_IDF_TARGET_ESP32C2) || \
  202. defined(CONFIG_IDF_TARGET_ESP8684)
  203. /* ESP8684 is essentially ESP32-C2 chip + flash embedded together in a
  204. * single QFN 4x4 mm package. Out of released documentation, Technical
  205. * Reference Manual as well as ESP-IDF Programming Guide is applicable
  206. * to both ESP32-C2 and ESP8684.
  207. *
  208. * See: https://www.esp32.com/viewtopic.php?f=5&t=27926#:~:text=ESP8684%20is%20essentially%20ESP32%2DC2,both%20ESP32%2DC2%20and%20ESP8684. */
  209. /* wolfSSL HW Acceleration supported on ESP32-C2. Uncomment to disable: */
  210. /* #define NO_ESP32_CRYPT */
  211. /* #define NO_WOLFSSL_ESP32_CRYPT_HASH */ /* to disable all SHA HW */
  212. /* These are defined automatically in esp32-crypt.h, here for clarity */
  213. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA384 /* no SHA384 HW on C2 */
  214. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA512 /* no SHA512 HW on C2 */
  215. /* There's no AES or RSA/Math accelerator on the ESP32-C2
  216. * Auto defined with NO_WOLFSSL_ESP32_CRYPT_RSA_PRI, for clarity: */
  217. #define NO_WOLFSSL_ESP32_CRYPT_AES
  218. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
  219. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL
  220. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD
  221. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD
  222. /***** END CONFIG_IDF_TARGET_ESP32C2 *****/
  223. #elif defined(CONFIG_IDF_TARGET_ESP32C3)
  224. /* wolfSSL HW Acceleration supported on ESP32-C3. Uncomment to disable: */
  225. /* #define NO_ESP32_CRYPT */
  226. /* #define NO_WOLFSSL_ESP32_CRYPT_HASH */ /* to disable all SHA HW */
  227. /* These are defined automatically in esp32-crypt.h, here for clarity: */
  228. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA384 /* no SHA384 HW on C6 */
  229. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA512 /* no SHA512 HW on C6 */
  230. /* #define NO_WOLFSSL_ESP32_CRYPT_AES */
  231. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
  232. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
  233. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
  234. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
  235. /***** END CONFIG_IDF_TARGET_ESP32C3 *****/
  236. #elif defined(CONFIG_IDF_TARGET_ESP32C6)
  237. /* wolfSSL HW Acceleration supported on ESP32-C6. Uncomment to disable: */
  238. /* #define NO_ESP32_CRYPT */
  239. /* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
  240. /* These are defined automatically in esp32-crypt.h, here for clarity: */
  241. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA384 /* no SHA384 HW on C6 */
  242. #define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA512 /* no SHA512 HW on C6 */
  243. /* #define NO_WOLFSSL_ESP32_CRYPT_AES */
  244. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
  245. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
  246. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
  247. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
  248. /***** END CONFIG_IDF_TARGET_ESP32C6 *****/
  249. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  250. /* wolfSSL Hardware Acceleration not yet implemented */
  251. #define NO_ESP32_CRYPT
  252. #define NO_WOLFSSL_ESP32_CRYPT_HASH
  253. #define NO_WOLFSSL_ESP32_CRYPT_AES
  254. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
  255. /***** END CONFIG_IDF_TARGET_ESP32H2 *****/
  256. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  257. /* TODO: Revisit ESP8266 */
  258. #define NO_ESP32_CRYPT
  259. #define NO_WOLFSSL_ESP32_CRYPT_HASH
  260. #define NO_WOLFSSL_ESP32_CRYPT_AES
  261. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
  262. /***** END CONFIG_IDF_TARGET_ESP266 *****/
  263. #else
  264. /* Anything else encountered, disable HW accleration */
  265. #define NO_ESP32_CRYPT
  266. #define NO_WOLFSSL_ESP32_CRYPT_HASH
  267. #define NO_WOLFSSL_ESP32_CRYPT_AES
  268. #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
  269. #endif /* CONFIG_IDF_TARGET Check */
  270. /* Debug options:
  271. #define ESP_VERIFY_MEMBLOCK
  272. #define DEBUG_WOLFSSL
  273. #define DEBUG_WOLFSSL_VERBOSE
  274. #define DEBUG_WOLFSSL_SHA_MUTEX
  275. #define WOLFSSL_ESP32_CRYPT_DEBUG
  276. #define WOLFSSL_ESP32_CRYPT_HASH_SHA224_DEBUG
  277. #define NO_RECOVER_SOFTWARE_CALC
  278. #define WOLFSSL_TEST_STRAY 1
  279. #define USE_ESP_DPORT_ACCESS_READ_BUFFER
  280. #define WOLFSSL_ESP32_HW_LOCK_DEBUG
  281. #define WOLFSSL_DEBUG_ESP_RSA_MULM_BITS
  282. #define ESP_DISABLE_HW_TASK_LOCK
  283. */
  284. #define WOLFSSL_ESPIDF_ERROR_PAUSE /* Pause in a loop rather than exit. */
  285. #define WOLFSSL_HW_METRICS
  286. /* #define HASH_SIZE_LIMIT */ /* for test.c */
  287. /* #define NO_HW_MATH_TEST */ /* Optionall turn off HW math checks */
  288. /* Optionally include alternate HW test library: alt_hw_test.h */
  289. /* When enabling, the ./components/wolfssl/CMakeLists.txt file
  290. * will need the name of the library in the idf_component_register
  291. * for the PRIV_REQUIRES list. */
  292. /* #define INCLUDE_ALT_HW_TEST */
  293. /* optionally turn off individual math HW acceleration features */
  294. /* Turn off Large Number ESP32 HW Multiplication:
  295. ** [Z = X * Y] in esp_mp_mul() */
  296. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
  297. /* Turn off Large Number ESP32 HW Modular Exponentiation:
  298. ** [Z = X^Y mod M] in esp_mp_exptmod() */
  299. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
  300. /* Turn off Large Number ESP32 HW Modular Multiplication
  301. ** [Z = X * Y mod M] in esp_mp_mulmod() */
  302. /* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
  303. #define WOLFSSL_PUBLIC_MP /* used by benchmark */
  304. #define USE_CERT_BUFFERS_2048
  305. /* when turning on ECC508 / ECC608 support
  306. #define WOLFSSL_ESPWROOM32SE
  307. #define HAVE_PK_CALLBACKS
  308. #define WOLFSSL_ATECC508A
  309. #define ATCA_WOLFSSL
  310. */
  311. /* optional SM4 Ciphers. See https://github.com/wolfSSL/wolfsm
  312. #define WOLFSSL_SM2
  313. #define WOLFSSL_SM3
  314. #define WOLFSSL_SM4
  315. */
  316. #if defined(WOLFSSL_SM2) || defined(WOLFSSL_SM3) || defined(WOLFSSL_SM4)
  317. #include <wolfssl/certs_test_sm.h>
  318. #define CTX_CA_CERT root_sm2
  319. #define CTX_CA_CERT_SIZE sizeof_root_sm2
  320. #define CTX_CA_CERT_TYPE WOLFSSL_FILETYPE_PEM
  321. #define CTX_SERVER_CERT server_sm2
  322. #define CTX_SERVER_CERT_SIZE sizeof_server_sm2
  323. #define CTX_SERVER_CERT_TYPE WOLFSSL_FILETYPE_PEM
  324. #define CTX_SERVER_KEY server_sm2_priv
  325. #define CTX_SERVER_KEY_SIZE sizeof_server_sm2_priv
  326. #define CTX_SERVER_KEY_TYPE WOLFSSL_FILETYPE_PEM
  327. #undef WOLFSSL_BASE16
  328. #define WOLFSSL_BASE16
  329. #else
  330. #define USE_CERT_BUFFERS_2048
  331. #define USE_CERT_BUFFERS_256
  332. #define CTX_CA_CERT ca_cert_der_2048
  333. #define CTX_CA_CERT_SIZE sizeof_ca_cert_der_2048
  334. #define CTX_CA_CERT_TYPE WOLFSSL_FILETYPE_ASN1
  335. #define CTX_SERVER_CERT server_cert_der_2048
  336. #define CTX_SERVER_CERT_SIZE sizeof_server_cert_der_2048
  337. #define CTX_SERVER_CERT_TYPE WOLFSSL_FILETYPE_ASN1
  338. #define CTX_SERVER_KEY server_key_der_2048
  339. #define CTX_SERVER_KEY_SIZE sizeof_server_key_der_2048
  340. #define CTX_SERVER_KEY_TYPE WOLFSSL_FILETYPE_ASN1
  341. #endif