user_settings.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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. /* Template based on examples/config/user_settings_template.h, but modified to
  22. * include `WOLFSSL_SILABS_SE_ACCEL` and tune for ARM Cortex M. */
  23. #ifndef WOLFSSL_USER_SETTINGS_H
  24. #define WOLFSSL_USER_SETTINGS_H
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /* Silicon Labs ERF32 Hardware Acceleration */
  29. #define WOLFSSL_SILABS_SE_ACCEL
  30. /* ------------------------------------------------------------------------- */
  31. /* Platform */
  32. /* ------------------------------------------------------------------------- */
  33. #define WOLFSSL_GENERAL_ALIGNMENT 4
  34. #define SIZEOF_LONG_LONG 8
  35. #define HAVE_STRINGS_H
  36. /* Use FreeRTOS */
  37. #if 1
  38. #define FREERTOS
  39. #else
  40. /* disable mutex locking */
  41. #define SINGLE_THREADED
  42. #endif
  43. /* reduce stack use. For variables over 100 bytes allocate from heap */
  44. #define WOLFSSL_SMALL_STACK
  45. /* Disable the built-in socket support and use the IO callbacks.
  46. * Set IO callbacks with wolfSSL_CTX_SetIORecv/wolfSSL_CTX_SetIOSend
  47. */
  48. #define WOLFSSL_USER_IO
  49. /* ------------------------------------------------------------------------- */
  50. /* Math Configuration */
  51. /* ------------------------------------------------------------------------- */
  52. /* Math Choices: SP (preferred), TFM or Normal (heap) */
  53. #if 1
  54. /* Wolf Single Precision Math */
  55. #define WOLFSSL_HAVE_SP_RSA
  56. #define WOLFSSL_HAVE_SP_DH
  57. #define WOLFSSL_HAVE_SP_ECC
  58. //#define WOLFSSL_SP_4096 /* Enable RSA/RH 4096-bit support */
  59. //#define WOLFSSL_SP_384 /* Enable ECC 384-bit SECP384R1 support */
  60. //#define WOLFSSL_SP_MATH /* only SP math - disables integer.c/tfm.c */
  61. #define WOLFSSL_SP_MATH_ALL /* use SP math for all key sizes and curves */
  62. //#define WOLFSSL_SP_NO_MALLOC
  63. //#define WOLFSSL_SP_DIV_32 /* do not use 64-bit divides */
  64. /* use smaller version of code */
  65. #define WOLFSSL_SP_SMALL
  66. /* SP Assembly Speedups - specific to chip type */
  67. #define WOLFSSL_SP_ASM
  68. #define WOLFSSL_SP_ARM_CORTEX_M_ASM
  69. #elif 1
  70. /* Fast Math (tfm.c) (stack based and timing resistant) */
  71. #define USE_FAST_MATH
  72. #define TFM_TIMING_RESISTANT
  73. #else
  74. /* Normal (integer.c) (heap based, not timing resistant) - not recommended*/
  75. #define USE_INTEGER_HEAP_MATH
  76. #endif
  77. /* ------------------------------------------------------------------------- */
  78. /* Crypto */
  79. /* ------------------------------------------------------------------------- */
  80. /* RSA */
  81. #undef NO_RSA
  82. #if 1
  83. #ifdef USE_FAST_MATH
  84. /* Maximum math bits (Max RSA key bits * 2) */
  85. #define FP_MAX_BITS 4096
  86. #endif
  87. /* half as much memory but twice as slow */
  88. //#define RSA_LOW_MEM
  89. /* Enables blinding mode, to prevent timing attacks */
  90. #define WC_RSA_BLINDING
  91. /* RSA PSS Support */
  92. #define WC_RSA_PSS
  93. #else
  94. #define NO_RSA
  95. #endif
  96. /* DH */
  97. #undef NO_DH
  98. #if 1
  99. /* Use table for DH instead of -lm (math) lib dependency */
  100. #if 1
  101. #define WOLFSSL_DH_CONST
  102. #define HAVE_FFDHE_2048
  103. //#define HAVE_FFDHE_4096
  104. //#define HAVE_FFDHE_6144
  105. //#define HAVE_FFDHE_8192
  106. #endif
  107. #else
  108. #define NO_DH
  109. #endif
  110. /* ECC */
  111. #undef HAVE_ECC
  112. #if 1
  113. #define HAVE_ECC
  114. /* Manually define enabled curves */
  115. #define ECC_USER_CURVES
  116. #ifdef ECC_USER_CURVES
  117. /* Manual Curve Selection */
  118. //#define HAVE_ECC192
  119. //#define HAVE_ECC224
  120. #undef NO_ECC256
  121. //#define HAVE_ECC384
  122. //#define HAVE_ECC521
  123. #endif
  124. /* Fixed point cache (speeds repeated operations against same private key) */
  125. //#define FP_ECC
  126. #ifdef FP_ECC
  127. /* Bits / Entries */
  128. #define FP_ENTRIES 2
  129. #define FP_LUT 4
  130. #endif
  131. /* Optional ECC calculation method */
  132. /* Note: doubles heap usage, but slightly faster */
  133. #define ECC_SHAMIR
  134. /* Reduces heap usage, but slower */
  135. #define ECC_TIMING_RESISTANT
  136. /* Compressed ECC Key Support */
  137. //#define HAVE_COMP_KEY
  138. /* Use alternate ECC size for ECC math */
  139. #ifdef USE_FAST_MATH
  140. /* MAX ECC BITS = ROUND8(MAX ECC) * 2 */
  141. #if defined(NO_RSA) && defined(NO_DH)
  142. /* Custom fastmath size if not using RSA/DH */
  143. #define FP_MAX_BITS (256 * 2)
  144. #else
  145. /* use heap allocation for ECC points */
  146. #define ALT_ECC_SIZE
  147. /* wolfSSL will compute the FP_MAX_BITS_ECC, but it can be overridden */
  148. //#define FP_MAX_BITS_ECC (256 * 2)
  149. #endif
  150. /* Speedups specific to curve */
  151. #ifndef NO_ECC256
  152. #define TFM_ECC256
  153. #endif
  154. #endif
  155. #endif
  156. /* AES */
  157. #undef NO_AES
  158. #if 1
  159. #define HAVE_AES_CBC
  160. /* GCM Method: GCM_TABLE_4BIT, GCM_SMALL, GCM_WORD32 or GCM_TABLE */
  161. #define HAVE_AESGCM
  162. #define GCM_SMALL
  163. //#define WOLFSSL_AES_DIRECT
  164. //#define HAVE_AES_ECB
  165. //#define WOLFSSL_AES_COUNTER
  166. //#define HAVE_AESCCM
  167. #else
  168. #define NO_AES
  169. #endif
  170. /* DES3 */
  171. #undef NO_DES3
  172. #if 0
  173. #else
  174. #define NO_DES3
  175. #endif
  176. /* ChaCha20 / Poly1305 */
  177. #undef HAVE_CHACHA
  178. #undef HAVE_POLY1305
  179. #if 1
  180. #define HAVE_CHACHA
  181. #define HAVE_POLY1305
  182. /* Needed for Poly1305 */
  183. #define HAVE_ONE_TIME_AUTH
  184. #endif
  185. /* Ed25519 / Curve25519 */
  186. #undef HAVE_CURVE25519
  187. #undef HAVE_ED25519
  188. #if 0
  189. #define HAVE_CURVE25519
  190. #define HAVE_ED25519 /* ED25519 Requires SHA512 */
  191. /* Optionally use small math (less flash usage, but much slower) */
  192. #if 1
  193. #define CURVED25519_SMALL
  194. #endif
  195. #endif
  196. /* ------------------------------------------------------------------------- */
  197. /* Hashing */
  198. /* ------------------------------------------------------------------------- */
  199. /* Sha */
  200. #undef NO_SHA
  201. #if 1
  202. /* 1k smaller, but 25% slower */
  203. //#define USE_SLOW_SHA
  204. #else
  205. #define NO_SHA
  206. #endif
  207. /* Sha256 */
  208. #undef NO_SHA256
  209. #if 1
  210. /* not unrolled - ~2k smaller and ~25% slower */
  211. //#define USE_SLOW_SHA256
  212. /* Sha224 */
  213. #if 0
  214. #define WOLFSSL_SHA224
  215. #endif
  216. #else
  217. #define NO_SHA256
  218. #endif
  219. /* Sha512 */
  220. #undef WOLFSSL_SHA512
  221. #if 0
  222. #define WOLFSSL_SHA512
  223. /* Sha384 */
  224. #undef WOLFSSL_SHA384
  225. #if 0
  226. #define WOLFSSL_SHA384
  227. #endif
  228. /* over twice as small, but 50% slower */
  229. //#define USE_SLOW_SHA512
  230. #endif
  231. /* Sha3 */
  232. #undef WOLFSSL_SHA3
  233. #if 0
  234. #define WOLFSSL_SHA3
  235. #endif
  236. /* MD5 */
  237. #undef NO_MD5
  238. #if 0
  239. #else
  240. #define NO_MD5
  241. #endif
  242. /* HKDF */
  243. #undef HAVE_HKDF
  244. #if 1
  245. #define HAVE_HKDF
  246. #endif
  247. /* CMAC */
  248. #undef WOLFSSL_CMAC
  249. #if 0
  250. #define WOLFSSL_CMAC
  251. #endif
  252. /* ------------------------------------------------------------------------- */
  253. /* Benchmark / Test */
  254. /* ------------------------------------------------------------------------- */
  255. /* Use reduced benchmark / test sizes */
  256. #define BENCH_EMBEDDED
  257. /* Use test buffers from array (not filesystem) */
  258. #define USE_CERT_BUFFERS_256
  259. #define USE_CERT_BUFFERS_2048
  260. /* ------------------------------------------------------------------------- */
  261. /* Debugging */
  262. /* ------------------------------------------------------------------------- */
  263. #undef DEBUG_WOLFSSL
  264. #undef NO_ERROR_STRINGS
  265. #if 0
  266. #define DEBUG_WOLFSSL
  267. #else
  268. #if 0
  269. #define NO_ERROR_STRINGS
  270. #endif
  271. #endif
  272. /* ------------------------------------------------------------------------- */
  273. /* Memory */
  274. /* ------------------------------------------------------------------------- */
  275. /* Override Memory API's */
  276. #if 0
  277. #define XMALLOC_OVERRIDE
  278. /* prototypes for user heap override functions */
  279. /* Note: Realloc only required for normal math */
  280. #include <stddef.h> /* for size_t */
  281. extern void *myMalloc(size_t n, void* heap, int type);
  282. extern void myFree(void *p, void* heap, int type);
  283. extern void *myRealloc(void *p, size_t n, void* heap, int type);
  284. #define XMALLOC(n, h, t) myMalloc(n, h, t)
  285. #define XFREE(p, h, t) myFree(p, h, t)
  286. #define XREALLOC(p, n, h, t) myRealloc(p, n, h, t)
  287. #endif
  288. #if 0
  289. /* Static memory requires fast math */
  290. #define WOLFSSL_STATIC_MEMORY
  291. /* Disable fallback malloc/free */
  292. #define WOLFSSL_NO_MALLOC
  293. #if 1
  294. #define WOLFSSL_MALLOC_CHECK /* trap malloc failure */
  295. #endif
  296. #endif
  297. /* Memory callbacks */
  298. #if 0
  299. #undef USE_WOLFSSL_MEMORY
  300. #define USE_WOLFSSL_MEMORY
  301. /* Use this to measure / print heap usage */
  302. #if 0
  303. #define WOLFSSL_TRACK_MEMORY
  304. #define WOLFSSL_DEBUG_MEMORY
  305. #endif
  306. #else
  307. #ifndef WOLFSSL_STATIC_MEMORY
  308. #define NO_WOLFSSL_MEMORY
  309. /* Otherwise we will use stdlib malloc, free and realloc */
  310. #endif
  311. #endif
  312. /* ------------------------------------------------------------------------- */
  313. /* Port */
  314. /* ------------------------------------------------------------------------- */
  315. /* Override Current Time */
  316. #if 0
  317. /* Allows custom "custom_time()" function to be used for benchmark */
  318. #define WOLFSSL_USER_CURRTIME
  319. #define WOLFSSL_GMTIME
  320. #define USER_TICKS
  321. extern unsigned long my_time(unsigned long* timer);
  322. #define XTIME my_time
  323. #endif
  324. /* ------------------------------------------------------------------------- */
  325. /* RNG */
  326. /* ------------------------------------------------------------------------- */
  327. /* Choose RNG method */
  328. #if 1
  329. /* Custom Seed Source */
  330. #if 0
  331. /* Size of returned HW RNG value */
  332. #define CUSTOM_RAND_TYPE unsigned int
  333. extern unsigned int my_rng_seed_gen(void);
  334. #undef CUSTOM_RAND_GENERATE
  335. #define CUSTOM_RAND_GENERATE my_rng_seed_gen
  336. #endif
  337. /* Use built-in P-RNG (SHA256 based) with HW RNG */
  338. /* P-RNG + HW RNG (P-RNG is ~8K) */
  339. #undef HAVE_HASHDRBG
  340. #define HAVE_HASHDRBG
  341. #else
  342. #undef WC_NO_HASHDRBG
  343. #define WC_NO_HASHDRBG
  344. /* Bypass P-RNG and use only HW RNG */
  345. extern int my_rng_gen_block(unsigned char* output, unsigned int sz);
  346. #undef CUSTOM_RAND_GENERATE_BLOCK
  347. #define CUSTOM_RAND_GENERATE_BLOCK my_rng_gen_block
  348. #endif
  349. /* ------------------------------------------------------------------------- */
  350. /* Custom Standard Lib */
  351. /* ------------------------------------------------------------------------- */
  352. /* Allows override of all standard library functions */
  353. #undef STRING_USER
  354. #if 0
  355. #define STRING_USER
  356. #include <string.h>
  357. #define USE_WOLF_STRSEP
  358. #define XSTRSEP(s1,d) wc_strsep((s1),(d))
  359. #define USE_WOLF_STRTOK
  360. #define XSTRTOK(s1,d,ptr) wc_strtok((s1),(d),(ptr))
  361. #define XSTRNSTR(s1,s2,n) mystrnstr((s1),(s2),(n))
  362. #define XMEMCPY(d,s,l) memcpy((d),(s),(l))
  363. #define XMEMSET(b,c,l) memset((b),(c),(l))
  364. #define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n))
  365. #define XMEMMOVE(d,s,l) memmove((d),(s),(l))
  366. #define XSTRLEN(s1) strlen((s1))
  367. #define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
  368. #define XSTRSTR(s1,s2) strstr((s1),(s2))
  369. #define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
  370. #define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
  371. #define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
  372. #define XSNPRINTF snprintf
  373. #endif
  374. /* ------------------------------------------------------------------------- */
  375. /* Enable Features */
  376. /* ------------------------------------------------------------------------- */
  377. #define WOLFSSL_TLS13
  378. #define WOLFSSL_OLD_PRIME_CHECK /* Use faster DH prime checking */
  379. #define HAVE_TLS_EXTENSIONS
  380. #define HAVE_SUPPORTED_CURVES
  381. #define WOLFSSL_BASE64_ENCODE
  382. #define WOLFSSL_PUB_PEM_TO_DER
  383. //#define WOLFSSL_KEY_GEN /* For RSA Key gen only */
  384. //#define KEEP_PEER_CERT
  385. //#define HAVE_COMP_KEY
  386. /* TLS Session Cache */
  387. #if 0
  388. #define SMALL_SESSION_CACHE
  389. #else
  390. #define NO_SESSION_CACHE
  391. #endif
  392. /* ------------------------------------------------------------------------- */
  393. /* Disable Features */
  394. /* ------------------------------------------------------------------------- */
  395. //#define NO_WOLFSSL_SERVER
  396. //#define NO_WOLFSSL_CLIENT
  397. //#define NO_CRYPT_TEST
  398. //#define NO_CRYPT_BENCHMARK
  399. //#define WOLFCRYPT_ONLY
  400. /* do not warm when file is included to be built and not required to be */
  401. #define WOLFSSL_IGNORE_FILE_WARN
  402. /* In-lining of misc.c functions */
  403. /* If defined, must include wolfcrypt/src/misc.c in build */
  404. /* Slower, but about 1k smaller */
  405. //#define NO_INLINE
  406. #define NO_FILESYSTEM
  407. #define NO_WRITEV
  408. #define NO_MAIN_DRIVER
  409. #define NO_DEV_RANDOM
  410. #define NO_OLD_TLS
  411. #define NO_PSK
  412. #define NO_DSA
  413. #define NO_RC4
  414. #define NO_MD4
  415. #define NO_PWDBASED
  416. //#define NO_CODING
  417. //#define NO_ASN_TIME
  418. //#define NO_CERTS
  419. //#define NO_SIG_WRAPPER
  420. #ifdef __cplusplus
  421. }
  422. #endif
  423. #endif /* WOLFSSL_USER_SETTINGS_H */