1
0

user_settings.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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. /* 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. /* Note2: XFREE(NULL) must be properly handled */
  281. #include <stddef.h> /* for size_t */
  282. extern void *myMalloc(size_t n, void* heap, int type);
  283. extern void myFree(void *p, void* heap, int type);
  284. extern void *myRealloc(void *p, size_t n, void* heap, int type);
  285. #define XMALLOC(n, h, t) myMalloc(n, h, t)
  286. #define XFREE(p, h, t) myFree(p, h, t)
  287. #define XREALLOC(p, n, h, t) myRealloc(p, n, h, t)
  288. #endif
  289. #if 0
  290. /* Static memory requires fast math */
  291. #define WOLFSSL_STATIC_MEMORY
  292. /* Disable fallback malloc/free */
  293. #define WOLFSSL_NO_MALLOC
  294. #if 1
  295. #define WOLFSSL_MALLOC_CHECK /* trap malloc failure */
  296. #endif
  297. #endif
  298. /* Memory callbacks */
  299. #if 0
  300. #undef USE_WOLFSSL_MEMORY
  301. #define USE_WOLFSSL_MEMORY
  302. /* Use this to measure / print heap usage */
  303. #if 0
  304. #define WOLFSSL_TRACK_MEMORY
  305. #define WOLFSSL_DEBUG_MEMORY
  306. #endif
  307. #else
  308. #ifndef WOLFSSL_STATIC_MEMORY
  309. #define NO_WOLFSSL_MEMORY
  310. /* Otherwise we will use stdlib malloc, free and realloc */
  311. #endif
  312. #endif
  313. /* ------------------------------------------------------------------------- */
  314. /* Port */
  315. /* ------------------------------------------------------------------------- */
  316. /* Override Current Time */
  317. #if 0
  318. /* Allows custom "custom_time()" function to be used for benchmark */
  319. #define WOLFSSL_USER_CURRTIME
  320. #define WOLFSSL_GMTIME
  321. #define USER_TICKS
  322. extern unsigned long my_time(unsigned long* timer);
  323. #define XTIME my_time
  324. #endif
  325. /* ------------------------------------------------------------------------- */
  326. /* RNG */
  327. /* ------------------------------------------------------------------------- */
  328. /* Choose RNG method */
  329. #if 1
  330. /* Custom Seed Source */
  331. #if 0
  332. /* Size of returned HW RNG value */
  333. #define CUSTOM_RAND_TYPE unsigned int
  334. extern unsigned int my_rng_seed_gen(void);
  335. #undef CUSTOM_RAND_GENERATE
  336. #define CUSTOM_RAND_GENERATE my_rng_seed_gen
  337. #endif
  338. /* Use built-in P-RNG (SHA256 based) with HW RNG */
  339. /* P-RNG + HW RNG (P-RNG is ~8K) */
  340. #undef HAVE_HASHDRBG
  341. #define HAVE_HASHDRBG
  342. #else
  343. #undef WC_NO_HASHDRBG
  344. #define WC_NO_HASHDRBG
  345. /* Bypass P-RNG and use only HW RNG */
  346. extern int my_rng_gen_block(unsigned char* output, unsigned int sz);
  347. #undef CUSTOM_RAND_GENERATE_BLOCK
  348. #define CUSTOM_RAND_GENERATE_BLOCK my_rng_gen_block
  349. #endif
  350. /* ------------------------------------------------------------------------- */
  351. /* Custom Standard Lib */
  352. /* ------------------------------------------------------------------------- */
  353. /* Allows override of all standard library functions */
  354. #undef STRING_USER
  355. #if 0
  356. #define STRING_USER
  357. #include <string.h>
  358. #define USE_WOLF_STRSEP
  359. #define XSTRSEP(s1,d) wc_strsep((s1),(d))
  360. #define USE_WOLF_STRTOK
  361. #define XSTRTOK(s1,d,ptr) wc_strtok((s1),(d),(ptr))
  362. #define XSTRNSTR(s1,s2,n) mystrnstr((s1),(s2),(n))
  363. #define XMEMCPY(d,s,l) memcpy((d),(s),(l))
  364. #define XMEMSET(b,c,l) memset((b),(c),(l))
  365. #define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n))
  366. #define XMEMMOVE(d,s,l) memmove((d),(s),(l))
  367. #define XSTRLEN(s1) strlen((s1))
  368. #define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
  369. #define XSTRSTR(s1,s2) strstr((s1),(s2))
  370. #define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
  371. #define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
  372. #define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
  373. #define XSNPRINTF snprintf
  374. #endif
  375. /* ------------------------------------------------------------------------- */
  376. /* Enable Features */
  377. /* ------------------------------------------------------------------------- */
  378. #define WOLFSSL_TLS13
  379. #define WOLFSSL_OLD_PRIME_CHECK /* Use faster DH prime checking */
  380. #define HAVE_TLS_EXTENSIONS
  381. #define HAVE_SUPPORTED_CURVES
  382. #define WOLFSSL_BASE64_ENCODE
  383. #define WOLFSSL_PUB_PEM_TO_DER
  384. //#define WOLFSSL_KEY_GEN /* For RSA Key gen only */
  385. //#define KEEP_PEER_CERT
  386. //#define HAVE_COMP_KEY
  387. /* TLS Session Cache */
  388. #if 0
  389. #define SMALL_SESSION_CACHE
  390. #else
  391. #define NO_SESSION_CACHE
  392. #endif
  393. /* ------------------------------------------------------------------------- */
  394. /* Disable Features */
  395. /* ------------------------------------------------------------------------- */
  396. //#define NO_WOLFSSL_SERVER
  397. //#define NO_WOLFSSL_CLIENT
  398. //#define NO_CRYPT_TEST
  399. //#define NO_CRYPT_BENCHMARK
  400. //#define WOLFCRYPT_ONLY
  401. /* do not warm when file is included to be built and not required to be */
  402. #define WOLFSSL_IGNORE_FILE_WARN
  403. /* In-lining of misc.c functions */
  404. /* If defined, must include wolfcrypt/src/misc.c in build */
  405. /* Slower, but about 1k smaller */
  406. //#define NO_INLINE
  407. #define NO_FILESYSTEM
  408. #define NO_WRITEV
  409. #define NO_MAIN_DRIVER
  410. #define NO_DEV_RANDOM
  411. #define NO_OLD_TLS
  412. #define NO_PSK
  413. #define NO_DSA
  414. #define NO_RC4
  415. #define NO_MD4
  416. #define NO_PWDBASED
  417. //#define NO_CODING
  418. //#define NO_ASN_TIME
  419. //#define NO_CERTS
  420. //#define NO_SIG_WRAPPER
  421. #ifdef __cplusplus
  422. }
  423. #endif
  424. #endif /* WOLFSSL_USER_SETTINGS_H */