1
0

user_settings.h 13 KB

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