user_settings.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /* user_settings.h
  2. *
  3. * Copyright (C) 2006-2021 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 SiFive HiFive1 */
  22. #ifndef WOLFSSL_USER_SETTINGS_H
  23. #define WOLFSSL_USER_SETTINGS_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /* ------------------------------------------------------------------------- */
  28. /* SiFive HiFive */
  29. /* ------------------------------------------------------------------------- */
  30. #undef WOLFSSL_SIFIVE_RISC_V
  31. #define WOLFSSL_SIFIVE_RISC_V
  32. /* ------------------------------------------------------------------------- */
  33. /* Platform */
  34. /* ------------------------------------------------------------------------- */
  35. #undef WOLFSSL_GENERAL_ALIGNMENT
  36. #define WOLFSSL_GENERAL_ALIGNMENT 4
  37. #undef SINGLE_THREADED
  38. #define SINGLE_THREADED
  39. #undef WOLFSSL_SMALL_STACK
  40. #define WOLFSSL_SMALL_STACK
  41. #undef WOLFSSL_USER_IO
  42. #define WOLFSSL_USER_IO
  43. /* ------------------------------------------------------------------------- */
  44. /* Math Configuration */
  45. /* ------------------------------------------------------------------------- */
  46. #undef SIZEOF_LONG_LONG
  47. #define SIZEOF_LONG_LONG 8
  48. #undef USE_FAST_MATH
  49. #if 1
  50. #define USE_FAST_MATH
  51. #undef TFM_TIMING_RESISTANT
  52. #define TFM_TIMING_RESISTANT
  53. /* Optimizations */
  54. //#define TFM_ARM
  55. #endif
  56. /* ------------------------------------------------------------------------- */
  57. /* Asymmetric */
  58. /* ------------------------------------------------------------------------- */
  59. /* RSA */
  60. /* Not enabled due to memory constraints on HiFive1 */
  61. #undef NO_RSA
  62. #if 0
  63. #ifdef USE_FAST_MATH
  64. /* Maximum math bits (Max RSA key bits * 2) */
  65. #undef FP_MAX_BITS
  66. #define FP_MAX_BITS 4096
  67. #endif
  68. /* half as much memory but twice as slow */
  69. #undef RSA_LOW_MEM
  70. #define RSA_LOW_MEM
  71. /* Enables blinding mode, to prevent timing attacks */
  72. #if 1
  73. #undef WC_RSA_BLINDING
  74. #define WC_RSA_BLINDING
  75. #else
  76. #undef WC_NO_HARDEN
  77. #define WC_NO_HARDEN
  78. #endif
  79. /* RSA PSS Support */
  80. #if 0
  81. #define WC_RSA_PSS
  82. #endif
  83. #if 0
  84. #define WC_RSA_NO_PADDING
  85. #endif
  86. #else
  87. #define NO_RSA
  88. #endif
  89. /* ECC */
  90. #undef HAVE_ECC
  91. #if 1
  92. #define HAVE_ECC
  93. /* Manually define enabled curves */
  94. #undef ECC_USER_CURVES
  95. #define ECC_USER_CURVES
  96. #ifdef ECC_USER_CURVES
  97. /* Manual Curve Selection, FP_MAX_BITS must be adjusted accordingly */
  98. // #define HAVE_ECC192
  99. // #define HAVE_ECC224
  100. #undef NO_ECC256
  101. // #define HAVE_ECC384
  102. // #define HAVE_ECC521
  103. #endif
  104. /* Fixed point cache (speeds repeated operations against same private key) */
  105. #undef FP_ECC
  106. //#define FP_ECC
  107. #ifdef FP_ECC
  108. /* Bits / Entries */
  109. #undef FP_ENTRIES
  110. #define FP_ENTRIES 2
  111. #undef FP_LUT
  112. #define FP_LUT 4
  113. #endif
  114. /* Optional ECC calculation method */
  115. /* Note: doubles heap usage, but slightly faster */
  116. #undef ECC_SHAMIR
  117. //#define ECC_SHAMIR
  118. /* Reduces heap usage, but slower */
  119. #undef ECC_TIMING_RESISTANT
  120. #define ECC_TIMING_RESISTANT
  121. /* Enable cofactor support */
  122. #undef HAVE_ECC_CDH
  123. //#define HAVE_ECC_CDH
  124. /* Validate import */
  125. #undef WOLFSSL_VALIDATE_ECC_IMPORT
  126. //#define WOLFSSL_VALIDATE_ECC_IMPORT
  127. /* Compressed Key Support */
  128. #undef HAVE_COMP_KEY
  129. //#define HAVE_COMP_KEY
  130. /* Use alternate ECC size for ECC math */
  131. #ifdef USE_FAST_MATH
  132. #ifdef NO_RSA
  133. /* Custom fastmath size if not using RSA */
  134. /* MAX = ROUND32(ECC BITS 256) + SIZE_OF_MP_DIGIT(32) */
  135. #undef FP_MAX_BITS
  136. #define FP_MAX_BITS (256 + 32)
  137. #else
  138. #undef ALT_ECC_SIZE
  139. /* Disable alternate ECC size, since it uses HEAP allocations.
  140. Heap is limited resource on HiFive1 */
  141. //#define ALT_ECC_SIZE
  142. #endif
  143. #endif
  144. #endif
  145. /* DH */
  146. #undef NO_DH
  147. #if 0
  148. /* Use table for DH instead of -lm (math) lib dependency */
  149. #if 0
  150. #define WOLFSSL_DH_CONST
  151. #endif
  152. #define HAVE_FFDHE_2048
  153. //#define HAVE_FFDHE_4096
  154. //#define HAVE_FFDHE_6144
  155. //#define HAVE_FFDHE_8192
  156. #else
  157. #define NO_DH
  158. #endif
  159. /* Wolf Single Precision Math */
  160. /* Optional ECC SECP256R1 acceleration using optimized C code */
  161. #undef WOLFSSL_SP
  162. #if 1
  163. #define WOLFSSL_SP
  164. #define WOLFSSL_SP_SMALL /* use smaller version of code (requires heap) */
  165. #define SP_WORD_SIZE 32 /* force 32-bit type */
  166. #define WOLFSSL_SP_MATH /* only SP math - eliminates fast math code */
  167. //#define WOLFSSL_SP_DIV_32 /* do not use 64-bit divides */
  168. #ifdef HAVE_ECC
  169. #define WOLFSSL_HAVE_SP_ECC
  170. #endif
  171. #ifndef NO_RSA
  172. #define WOLFSSL_HAVE_SP_RSA
  173. #endif
  174. #endif
  175. /* Ed25519 / Curve25519 */
  176. #undef HAVE_CURVE25519
  177. #undef HAVE_ED25519
  178. #if 1
  179. #define HAVE_CURVE25519
  180. #define HAVE_ED25519 /* ED25519 Requires SHA512 */
  181. /* Optionally use small math (less flash usage, but much slower) */
  182. #if 1
  183. /* Curve and Ed 25519 small */
  184. #define CURVED25519_SMALL
  185. #endif
  186. #endif
  187. /* ------------------------------------------------------------------------- */
  188. /* Symmetric Ciphers */
  189. /* ------------------------------------------------------------------------- */
  190. /* AES */
  191. #undef NO_AES
  192. #if 1
  193. #undef HAVE_AES_CBC
  194. #define HAVE_AES_CBC
  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. /* DES3 */
  209. #undef NO_DES3
  210. #if 0
  211. #else
  212. #define NO_DES3
  213. #endif
  214. /* ChaCha20 / Poly1305 */
  215. #undef HAVE_CHACHA
  216. #undef HAVE_POLY1305
  217. #if 1
  218. #define HAVE_CHACHA
  219. #define HAVE_POLY1305
  220. /* Needed for Poly1305 */
  221. #undef HAVE_ONE_TIME_AUTH
  222. #define HAVE_ONE_TIME_AUTH
  223. #endif
  224. /* ------------------------------------------------------------------------- */
  225. /* Symmetric Hashing */
  226. /* ------------------------------------------------------------------------- */
  227. /* Sha */
  228. #undef NO_SHA
  229. #if 1
  230. /* 1k smaller, but 25% slower */
  231. //#define USE_SLOW_SHA
  232. #else
  233. #define NO_SHA
  234. #endif
  235. /* Sha256 */
  236. #undef NO_SHA256
  237. #if 1
  238. /* not unrolled - ~2k smaller and ~25% slower */
  239. //#define USE_SLOW_SHA256
  240. /* Sha224 */
  241. #if 0
  242. #define WOLFSSL_SHA224
  243. #endif
  244. #else
  245. #define NO_SHA256
  246. #endif
  247. /* Sha512 */
  248. #undef WOLFSSL_SHA512
  249. #if 1
  250. #define WOLFSSL_SHA512
  251. /* Sha384 */
  252. #undef WOLFSSL_SHA384
  253. #if 0
  254. #define WOLFSSL_SHA384
  255. #endif
  256. /* over twice as small, but 50% slower */
  257. #define USE_SLOW_SHA512
  258. #endif
  259. /* Sha3 */
  260. #undef WOLFSSL_SHA3
  261. #if 0
  262. #define WOLFSSL_SHA3
  263. #endif
  264. /* MD5 */
  265. #undef NO_MD5
  266. #if 0
  267. #else
  268. #define NO_MD5
  269. #endif
  270. /* Blake2B */
  271. #undef HAVE_BLAKE2
  272. #if 0
  273. #define HAVE_BLAKE2
  274. #endif
  275. /* Blake2S */
  276. #undef HAVE_BLAKE2S
  277. #if 0
  278. #define HAVE_BLAKE2S
  279. #endif
  280. /* HKDF */
  281. #undef HAVE_HKDF
  282. #if 0
  283. #define HAVE_HKDF
  284. #endif
  285. /* CMAC */
  286. #undef WOLFSSL_CMAC
  287. #if 0
  288. #define WOLFSSL_CMAC
  289. #endif
  290. /* ------------------------------------------------------------------------- */
  291. /* Benchmark / Test */
  292. /* ------------------------------------------------------------------------- */
  293. /* Use reduced benchmark / test sizes */
  294. #undef BENCH_EMBEDDED
  295. #define BENCH_EMBEDDED
  296. #undef USE_CERT_BUFFERS_2048
  297. #define USE_CERT_BUFFERS_2048
  298. #undef USE_CERT_BUFFERS_1024
  299. //#define USE_CERT_BUFFERS_1024
  300. #undef USE_CERT_BUFFERS_256
  301. #define USE_CERT_BUFFERS_256
  302. /* ------------------------------------------------------------------------- */
  303. /* Debugging */
  304. /* ------------------------------------------------------------------------- */
  305. #undef DEBUG_WOLFSSL
  306. #undef NO_ERROR_STRINGS
  307. #if 0
  308. #define DEBUG_WOLFSSL
  309. #else
  310. #if 0
  311. #define NO_ERROR_STRINGS
  312. #endif
  313. #endif
  314. /* ------------------------------------------------------------------------- */
  315. /* Memory */
  316. /* ------------------------------------------------------------------------- */
  317. /* Override Memory API's */
  318. #if 0
  319. #undef XMALLOC_OVERRIDE
  320. #define XMALLOC_OVERRIDE
  321. /* prototypes for user heap override functions */
  322. /* Note: Realloc only required for normal math */
  323. #include <stddef.h> /* for size_t */
  324. extern void *myMalloc(size_t n, void* heap, int type);
  325. extern void myFree(void *p, void* heap, int type);
  326. extern void *myRealloc(void *p, size_t n, void* heap, int type);
  327. #define XMALLOC(n, h, t) myMalloc(n, h, t)
  328. #define XFREE(p, h, t) myFree(p, h, t)
  329. #define XREALLOC(p, n, h, t) myRealloc(p, n, h, t)
  330. #endif
  331. /* Static memory */
  332. #if 0
  333. /* Static memory requires fast math */
  334. #define WOLFSSL_STATIC_MEMORY
  335. /* Disable fallback malloc/free */
  336. #define WOLFSSL_NO_MALLOC
  337. #if 1
  338. #define WOLFSSL_MALLOC_CHECK /* trap malloc failure */
  339. #endif
  340. #endif
  341. /* Memory callbacks */
  342. #if 0
  343. #undef USE_WOLFSSL_MEMORY
  344. #define USE_WOLFSSL_MEMORY
  345. /* Use this to measure / print heap usage */
  346. #if 1
  347. #undef WOLFSSL_TRACK_MEMORY
  348. #define WOLFSSL_TRACK_MEMORY
  349. #undef WOLFSSL_DEBUG_MEMORY
  350. #define WOLFSSL_DEBUG_MEMORY
  351. #endif
  352. #else
  353. #ifndef WOLFSSL_STATIC_MEMORY
  354. #define NO_WOLFSSL_MEMORY
  355. /* Otherwise we will use stdlib malloc, free and realloc */
  356. #endif
  357. #endif
  358. /* ------------------------------------------------------------------------- */
  359. /* Port */
  360. /* ------------------------------------------------------------------------- */
  361. /* Override Current Time */
  362. #if defined(WOLFSSL_SIFIVE_RISC_V)
  363. #define WOLFSSL_USER_CURRTIME /* for benchmarks, uses "custom_time()" function */
  364. #define WOLFSSL_GMTIME
  365. #define USER_TICKS
  366. #else
  367. // extern unsigned long my_time(unsigned long* timer);
  368. // #define XTIME my_time
  369. #endif
  370. /* ------------------------------------------------------------------------- */
  371. /* RNG */
  372. /* ------------------------------------------------------------------------- */
  373. #if 0
  374. /* Bypass P-RNG and use only HW RNG */
  375. #define CUSTOM_RAND_TYPE unsigned int
  376. extern int my_rng_gen_block(unsigned char* output, unsigned int sz);
  377. #undef CUSTOM_RAND_GENERATE_BLOCK
  378. #define CUSTOM_RAND_GENERATE_BLOCK my_rng_gen_block
  379. #else
  380. #define HAVE_HASHDRBG
  381. /* Seed Source */
  382. /* Size of returned HW RNG value */
  383. #define CUSTOM_RAND_TYPE unsigned int
  384. extern unsigned int my_rng_seed_gen(void);
  385. #undef CUSTOM_RAND_GENERATE
  386. #define CUSTOM_RAND_GENERATE my_rng_seed_gen
  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 0
  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_HC128
  450. #define NO_HC128
  451. #undef NO_RABBIT
  452. #define NO_RABBIT
  453. #undef NO_PSK
  454. #define NO_PSK
  455. #undef NO_MD4
  456. #define NO_MD4
  457. #undef NO_PWDBASED
  458. #define NO_PWDBASED
  459. #undef NO_CODING
  460. //#define NO_CODING
  461. #undef NO_ASN_TIME
  462. //#define NO_ASN_TIME
  463. #undef NO_CERTS
  464. //#define NO_CERTS
  465. #undef NO_SIG_WRAPPER
  466. //#define NO_SIG_WRAPPER
  467. #ifdef __cplusplus
  468. }
  469. #endif
  470. #endif /* WOLFSSL_USER_SETTINGS_H */