2
0

user_settings.h 13 KB

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