user_settings.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /* user_settings.h
  2. *
  3. * Copyright (C) 2020 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 Settings for CryptoCell */
  22. #ifndef WOLFSSL_USER_SETTINGS_H
  23. #define WOLFSSL_USER_SETTINGS_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /* ------------------------------------------------------------------------- */
  28. /* CryptoCell */
  29. /* ------------------------------------------------------------------------- */
  30. #if 1
  31. #define WOLFSSL_CRYPTOCELL
  32. #define WOLFSSL_nRF5x_SDK_15_2 /* for benchmark timer */
  33. #define WOLFSSL_CRYPTOCELL_AES /* only CBC mode is supported */
  34. #else
  35. /* run without CryptoCell,
  36. include IDE/GCC-ARM/Source/wolf_main.c for current_time(). */
  37. #endif
  38. #if defined(WOLFSSL_CRYPTOCELL)
  39. #define AES_MAX_KEY_SIZE 128
  40. #endif /* WOLFSSL_CRYPTOCELL*/
  41. /* ------------------------------------------------------------------------- */
  42. /* Platform */
  43. /* ------------------------------------------------------------------------- */
  44. #undef WOLFSSL_GENERAL_ALIGNMENT
  45. #define WOLFSSL_GENERAL_ALIGNMENT 4
  46. #undef SINGLE_THREADED
  47. #define SINGLE_THREADED
  48. #undef WOLFSSL_SMALL_STACK
  49. #define WOLFSSL_SMALL_STACK
  50. #undef WOLFSSL_USER_IO
  51. #define WOLFSSL_USER_IO
  52. /* ------------------------------------------------------------------------- */
  53. /* Math Configuration */
  54. /* ------------------------------------------------------------------------- */
  55. #undef SIZEOF_LONG_LONG
  56. #define SIZEOF_LONG_LONG 8
  57. #undef USE_FAST_MATH
  58. #if 1
  59. #define USE_FAST_MATH
  60. #undef TFM_TIMING_RESISTANT
  61. #define TFM_TIMING_RESISTANT
  62. /* Optimizations */
  63. //#define TFM_ARM
  64. #endif
  65. /* Wolf Single Precision Math */
  66. #undef WOLFSSL_SP
  67. #if 0
  68. #define WOLFSSL_SP
  69. #define WOLFSSL_SP_SMALL /* use smaller version of code */
  70. #define WOLFSSL_HAVE_SP_RSA
  71. #define WOLFSSL_HAVE_SP_DH
  72. #define WOLFSSL_HAVE_SP_ECC
  73. #define WOLFSSL_SP_CACHE_RESISTANT
  74. //#define WOLFSSL_SP_MATH /* only SP math - eliminates fast math code */
  75. /* Assembly */
  76. //#define WOLFSSL_SP_ASM /* required if using the ASM versions */
  77. //#define WOLFSSL_SP_ARM_CORTEX_M_ASM
  78. #endif
  79. /* ------------------------------------------------------------------------- */
  80. /* Crypto */
  81. /* ------------------------------------------------------------------------- */
  82. /* RSA */
  83. #undef NO_RSA
  84. #if 1
  85. #ifdef USE_FAST_MATH
  86. /* Maximum math bits (Max RSA key bits * 2) */
  87. #undef FP_MAX_BITS
  88. #define FP_MAX_BITS 4096
  89. #endif
  90. /* half as much memory but twice as slow */
  91. #undef RSA_LOW_MEM
  92. //#define RSA_LOW_MEM
  93. /* Enables blinding mode, to prevent timing attacks */
  94. #if 1
  95. #undef WC_RSA_BLINDING
  96. #define WC_RSA_BLINDING
  97. #else
  98. #undef WC_NO_HARDEN
  99. #define WC_NO_HARDEN
  100. #endif
  101. /* RSA PSS Support */
  102. #if 0
  103. #define WC_RSA_PSS
  104. #endif
  105. #if 0
  106. #define WC_RSA_NO_PADDING
  107. #endif
  108. #else
  109. #define NO_RSA
  110. #endif
  111. /* ECC */
  112. #undef HAVE_ECC
  113. #if 1
  114. #define HAVE_ECC
  115. /* Manually define enabled curves */
  116. #undef ECC_USER_CURVES
  117. #define ECC_USER_CURVES
  118. #ifdef ECC_USER_CURVES
  119. /* Manual Curve Selection */
  120. //#define HAVE_ECC192
  121. //#define HAVE_ECC224
  122. #undef NO_ECC256
  123. #define HAVE_ECC384
  124. //#define HAVE_ECC521
  125. #endif
  126. /* Fixed point cache (speeds repeated operations against same private key) */
  127. #undef FP_ECC
  128. //#define FP_ECC
  129. #ifdef FP_ECC
  130. /* Bits / Entries */
  131. #undef FP_ENTRIES
  132. #define FP_ENTRIES 2
  133. #undef FP_LUT
  134. #define FP_LUT 4
  135. #endif
  136. /* Optional ECC calculation method */
  137. /* Note: doubles heap usage, but slightly faster */
  138. #undef ECC_SHAMIR
  139. #define ECC_SHAMIR
  140. /* Reduces heap usage, but slower */
  141. #undef ECC_TIMING_RESISTANT
  142. #define ECC_TIMING_RESISTANT
  143. /* Enable cofactor support */
  144. #undef HAVE_ECC_CDH
  145. //#define HAVE_ECC_CDH
  146. /* Validate import */
  147. #undef WOLFSSL_VALIDATE_ECC_IMPORT
  148. //#define WOLFSSL_VALIDATE_ECC_IMPORT
  149. /* Compressed Key Support */
  150. #undef HAVE_COMP_KEY
  151. //#define HAVE_COMP_KEY
  152. /* Use alternate ECC size for ECC math */
  153. #ifdef USE_FAST_MATH
  154. #ifdef NO_RSA
  155. /* Custom fastmath size if not using RSA */
  156. /* MAX = ROUND32(ECC BITS 384) + SIZE_OF_MP_DIGIT(32) */
  157. #undef FP_MAX_BITS
  158. #define FP_MAX_BITS (384 + 32)
  159. #else
  160. #undef ALT_ECC_SIZE
  161. #define ALT_ECC_SIZE
  162. #endif
  163. /* Speedups specific to curve */
  164. #ifndef NO_ECC256
  165. #undef TFM_ECC256
  166. #define TFM_ECC256
  167. #endif
  168. #ifndef HAVE_ECC384
  169. #undef TFM_ECC384
  170. #define TFM_ECC384
  171. #endif
  172. #endif
  173. #endif
  174. /* DH */
  175. #undef NO_DH
  176. #if 0
  177. /* Use table for DH instead of -lm (math) lib dependency */
  178. #if 0
  179. #define WOLFSSL_DH_CONST
  180. #endif
  181. #define HAVE_FFDHE_2048
  182. //#define HAVE_FFDHE_4096
  183. //#define HAVE_FFDHE_6144
  184. //#define HAVE_FFDHE_8192
  185. #else
  186. #define NO_DH
  187. #endif
  188. /* AES */
  189. #undef NO_AES
  190. #if 1
  191. #undef HAVE_AES_CBC
  192. #define HAVE_AES_CBC
  193. /* If you need other than AES-CBC mode, you must undefine WOLFSSL_CRYPTOCELL_AES */
  194. #if !defined(WOLFSSL_CRYPTOCELL_AES)
  195. #undef HAVE_AESGCM
  196. #define HAVE_AESGCM
  197. /* GCM Method: GCM_SMALL, GCM_WORD32 or GCM_TABLE */
  198. #define GCM_SMALL
  199. #undef WOLFSSL_AES_DIRECT
  200. //#define WOLFSSL_AES_DIRECT
  201. #undef HAVE_AES_ECB
  202. //#define HAVE_AES_ECB
  203. #undef WOLFSSL_AES_COUNTER
  204. //#define WOLFSSL_AES_COUNTER
  205. #undef HAVE_AESCCM
  206. //#define HAVE_AESCCM
  207. #endif
  208. #else
  209. #define NO_AES
  210. #endif
  211. /* DES3 */
  212. #undef NO_DES3
  213. #if 0
  214. #else
  215. #define NO_DES3
  216. #endif
  217. /* ChaCha20 / Poly1305 */
  218. #undef HAVE_CHACHA
  219. #undef HAVE_POLY1305
  220. #if 0
  221. #define HAVE_CHACHA
  222. #define HAVE_POLY1305
  223. /* Needed for Poly1305 */
  224. #undef HAVE_ONE_TIME_AUTH
  225. #define HAVE_ONE_TIME_AUTH
  226. #endif
  227. /* Ed25519 / Curve25519 */
  228. #undef HAVE_CURVE25519
  229. #undef HAVE_ED25519
  230. #if 0
  231. #define HAVE_CURVE25519
  232. #define HAVE_ED25519 /* ED25519 Requires SHA512 */
  233. /* Optionally use small math (less flash usage, but much slower) */
  234. #if 1
  235. #define CURVED25519_SMALL
  236. #endif
  237. #endif
  238. /* ------------------------------------------------------------------------- */
  239. /* Hashing */
  240. /* ------------------------------------------------------------------------- */
  241. /* Sha */
  242. #undef NO_SHA
  243. #if 1
  244. /* 1k smaller, but 25% slower */
  245. //#define USE_SLOW_SHA
  246. #else
  247. #define NO_SHA
  248. #endif
  249. /* Sha256 */
  250. #undef NO_SHA256
  251. #if 1
  252. /* not unrolled - ~2k smaller and ~25% slower */
  253. //#define USE_SLOW_SHA256
  254. /* Sha224 */
  255. #if 0
  256. #define WOLFSSL_SHA224
  257. #endif
  258. #else
  259. #define NO_SHA256
  260. #endif
  261. /* Sha512 */
  262. #undef WOLFSSL_SHA512
  263. #if 0
  264. #define WOLFSSL_SHA512
  265. /* Sha384 */
  266. #undef WOLFSSL_SHA384
  267. #if 0
  268. #define WOLFSSL_SHA384
  269. #endif
  270. /* over twice as small, but 50% slower */
  271. //#define USE_SLOW_SHA512
  272. #endif
  273. /* Sha3 */
  274. #undef WOLFSSL_SHA3
  275. #if 0
  276. #define WOLFSSL_SHA3
  277. #endif
  278. /* MD5 */
  279. #undef NO_MD5
  280. #if 0
  281. #else
  282. #define NO_MD5
  283. #endif
  284. /* HKDF */
  285. #undef HAVE_HKDF
  286. #if 0
  287. #define HAVE_HKDF
  288. #endif
  289. /* CMAC */
  290. #undef WOLFSSL_CMAC
  291. #if 0
  292. #define WOLFSSL_CMAC
  293. #endif
  294. /* ------------------------------------------------------------------------- */
  295. /* Benchmark / Test */
  296. /* ------------------------------------------------------------------------- */
  297. /* Use reduced benchmark / test sizes */
  298. #undef BENCH_EMBEDDED
  299. #define BENCH_EMBEDDED
  300. #undef USE_CERT_BUFFERS_2048
  301. #define USE_CERT_BUFFERS_2048
  302. //#undef USE_CERT_BUFFERS_1024
  303. //#define USE_CERT_BUFFERS_1024
  304. #undef USE_CERT_BUFFERS_256
  305. #define USE_CERT_BUFFERS_256
  306. /* ------------------------------------------------------------------------- */
  307. /* Debugging */
  308. /* ------------------------------------------------------------------------- */
  309. #undef DEBUG_WOLFSSL
  310. #undef NO_ERROR_STRINGS
  311. #if 0
  312. #define DEBUG_WOLFSSL
  313. #else
  314. #if 0
  315. #define NO_ERROR_STRINGS
  316. #endif
  317. #endif
  318. /* ------------------------------------------------------------------------- */
  319. /* Memory */
  320. /* ------------------------------------------------------------------------- */
  321. /* Override Memory API's */
  322. #if 0
  323. #undef XMALLOC_OVERRIDE
  324. #define XMALLOC_OVERRIDE
  325. /* prototypes for user heap override functions */
  326. /* Note: Realloc only required for normal math */
  327. #include <stddef.h> /* for size_t */
  328. extern void *myMalloc(size_t n, void* heap, int type);
  329. extern void myFree(void *p, void* heap, int type);
  330. extern void *myRealloc(void *p, size_t n, void* heap, int type);
  331. #define XMALLOC(n, h, t) myMalloc(n, h, t)
  332. #define XFREE(p, h, t) myFree(p, h, t)
  333. #define XREALLOC(p, n, h, t) myRealloc(p, n, h, t)
  334. #endif
  335. #if 0
  336. /* Static memory requires fast math */
  337. #define WOLFSSL_STATIC_MEMORY
  338. /* Disable fallback malloc/free */
  339. #define WOLFSSL_NO_MALLOC
  340. #if 1
  341. #define WOLFSSL_MALLOC_CHECK /* trap malloc failure */
  342. #endif
  343. #endif
  344. /* Memory callbacks */
  345. #if 0
  346. #undef USE_WOLFSSL_MEMORY
  347. #define USE_WOLFSSL_MEMORY
  348. /* Use this to measure / print heap usage */
  349. #if 1
  350. #undef WOLFSSL_TRACK_MEMORY
  351. #define WOLFSSL_TRACK_MEMORY
  352. #undef WOLFSSL_DEBUG_MEMORY
  353. #define WOLFSSL_DEBUG_MEMORY
  354. #endif
  355. #else
  356. #ifndef WOLFSSL_STATIC_MEMORY
  357. #define NO_WOLFSSL_MEMORY
  358. /* Otherwise we will use stdlib malloc, free and realloc */
  359. #endif
  360. #endif
  361. /* ------------------------------------------------------------------------- */
  362. /* Port */
  363. /* ------------------------------------------------------------------------- */
  364. /* Override Current Time */
  365. /* Allows custom "custom_time()" function to be used for benchmark */
  366. #define WOLFSSL_USER_CURRTIME
  367. #define WOLFSSL_GMTIME
  368. #define USER_TICKS
  369. #if !defined(WOLFSSL_CRYPTOCELL)
  370. // extern unsigned long my_time(unsigned long* timer);
  371. // #define XTIME my_time
  372. #endif
  373. /* ------------------------------------------------------------------------- */
  374. /* RNG */
  375. /* ------------------------------------------------------------------------- */
  376. #if defined(WOLFSSL_CRYPTOCELL)
  377. // /* Override P-RNG with HW RNG */
  378. #undef CUSTOM_RAND_GENERATE_BLOCK
  379. #define CUSTOM_RAND_GENERATE_BLOCK cc310_random_generate
  380. //#define CUSTOM_RAND_GENERATE_BLOCK nrf_random_generate
  381. //#define WOLFSSL_GENSEED_FORTEST /* for software RNG*/
  382. #else
  383. #define WOLFSSL_GENSEED_FORTEST
  384. #endif
  385. /* ------------------------------------------------------------------------- */
  386. /* Enable Features */
  387. /* ------------------------------------------------------------------------- */
  388. #undef WOLFSSL_TLS13
  389. #if 0
  390. #define WOLFSSL_TLS13
  391. #endif
  392. #undef WOLFSSL_KEY_GEN
  393. #if 1
  394. #define WOLFSSL_KEY_GEN
  395. #endif
  396. /* reduce DH test time */
  397. #define WOLFSSL_OLD_PRIME_CHECK
  398. #undef KEEP_PEER_CERT
  399. //#define KEEP_PEER_CERT
  400. #undef HAVE_COMP_KEY
  401. //#define HAVE_COMP_KEY
  402. #undef HAVE_TLS_EXTENSIONS
  403. #define HAVE_TLS_EXTENSIONS
  404. #undef HAVE_SUPPORTED_CURVES
  405. #define HAVE_SUPPORTED_CURVES
  406. #undef WOLFSSL_BASE64_ENCODE
  407. #define WOLFSSL_BASE64_ENCODE
  408. /* TLS Session Cache */
  409. #if 0
  410. #define SMALL_SESSION_CACHE
  411. #else
  412. #define NO_SESSION_CACHE
  413. #endif
  414. /* ------------------------------------------------------------------------- */
  415. /* Disable Features */
  416. /* ------------------------------------------------------------------------- */
  417. #undef NO_WOLFSSL_SERVER
  418. //#define NO_WOLFSSL_SERVER
  419. #undef NO_WOLFSSL_CLIENT
  420. //#define NO_WOLFSSL_CLIENT
  421. #undef NO_CRYPT_TEST
  422. //#define NO_CRYPT_TEST
  423. #undef NO_CRYPT_BENCHMARK
  424. //#define NO_CRYPT_BENCHMARK
  425. #undef WOLFCRYPT_ONLY
  426. //#define WOLFCRYPT_ONLY
  427. /* In-lining of misc.c functions */
  428. /* If defined, must include wolfcrypt/src/misc.c in build */
  429. /* Slower, but about 1k smaller */
  430. #undef NO_INLINE
  431. //#define NO_INLINE
  432. #undef NO_FILESYSTEM
  433. #define NO_FILESYSTEM
  434. #undef NO_WRITEV
  435. #define NO_WRITEV
  436. #undef NO_MAIN_DRIVER
  437. #define NO_MAIN_DRIVER
  438. #undef NO_DEV_RANDOM
  439. #define NO_DEV_RANDOM
  440. #undef NO_DSA
  441. #define NO_DSA
  442. #undef NO_RC4
  443. #define NO_RC4
  444. #undef NO_OLD_TLS
  445. #define NO_OLD_TLS
  446. #undef NO_HC128
  447. #define NO_HC128
  448. #undef NO_RABBIT
  449. #define NO_RABBIT
  450. #undef NO_PSK
  451. #define NO_PSK
  452. #undef NO_MD4
  453. #define NO_MD4
  454. #undef NO_PWDBASED
  455. #define NO_PWDBASED
  456. #undef NO_CODING
  457. //#define NO_CODING
  458. #undef NO_ASN_TIME
  459. //#define NO_ASN_TIME
  460. #undef NO_CERTS
  461. //#define NO_CERTS
  462. #undef NO_SIG_WRAPPER
  463. //#define NO_SIG_WRAPPER
  464. #ifdef __cplusplus
  465. }
  466. #endif
  467. #endif /* WOLFSSL_USER_SETTINGS_H */