user_settings_template.h 14 KB

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