user_settings_template.h 14 KB

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