user_settings.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /* user_settings.h
  2. *
  3. * Copyright (C) 2006-2024 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. /* Note2: XFREE(NULL) must be properly handled */
  324. #include <stddef.h> /* for size_t */
  325. extern void *myMalloc(size_t n, void* heap, int type);
  326. extern void myFree(void *p, void* heap, int type);
  327. extern void *myRealloc(void *p, size_t n, void* heap, int type);
  328. #define XMALLOC(n, h, t) myMalloc(n, h, t)
  329. #define XFREE(p, h, t) myFree(p, h, t)
  330. #define XREALLOC(p, n, h, t) myRealloc(p, n, h, t)
  331. #endif
  332. /* Static memory */
  333. #if 0
  334. /* Static memory requires fast math */
  335. #define WOLFSSL_STATIC_MEMORY
  336. /* Disable fallback malloc/free */
  337. #define WOLFSSL_NO_MALLOC
  338. #if 1
  339. #define WOLFSSL_MALLOC_CHECK /* trap malloc failure */
  340. #endif
  341. #endif
  342. /* Memory callbacks */
  343. #if 0
  344. #undef USE_WOLFSSL_MEMORY
  345. #define USE_WOLFSSL_MEMORY
  346. /* Use this to measure / print heap usage */
  347. #if 1
  348. #undef WOLFSSL_TRACK_MEMORY
  349. #define WOLFSSL_TRACK_MEMORY
  350. #undef WOLFSSL_DEBUG_MEMORY
  351. #define WOLFSSL_DEBUG_MEMORY
  352. #endif
  353. #else
  354. #ifndef WOLFSSL_STATIC_MEMORY
  355. #define NO_WOLFSSL_MEMORY
  356. /* Otherwise we will use stdlib malloc, free and realloc */
  357. #endif
  358. #endif
  359. /* ------------------------------------------------------------------------- */
  360. /* Port */
  361. /* ------------------------------------------------------------------------- */
  362. /* Override Current Time */
  363. #if defined(WOLFSSL_SIFIVE_RISC_V)
  364. #define WOLFSSL_USER_CURRTIME /* for benchmarks, uses "custom_time()" function */
  365. #define WOLFSSL_GMTIME
  366. #define USER_TICKS
  367. #else
  368. // extern unsigned long my_time(unsigned long* timer);
  369. // #define XTIME my_time
  370. #endif
  371. /* ------------------------------------------------------------------------- */
  372. /* RNG */
  373. /* ------------------------------------------------------------------------- */
  374. #if 0
  375. /* Bypass P-RNG and use only HW RNG */
  376. #define CUSTOM_RAND_TYPE unsigned int
  377. extern int my_rng_gen_block(unsigned char* output, unsigned int sz);
  378. #undef CUSTOM_RAND_GENERATE_BLOCK
  379. #define CUSTOM_RAND_GENERATE_BLOCK my_rng_gen_block
  380. #else
  381. #define HAVE_HASHDRBG
  382. /* Seed Source */
  383. /* Size of returned HW RNG value */
  384. #define CUSTOM_RAND_TYPE unsigned int
  385. extern unsigned int my_rng_seed_gen(void);
  386. #undef CUSTOM_RAND_GENERATE
  387. #define CUSTOM_RAND_GENERATE my_rng_seed_gen
  388. #endif
  389. /* ------------------------------------------------------------------------- */
  390. /* Enable Features */
  391. /* ------------------------------------------------------------------------- */
  392. #undef WOLFSSL_TLS13
  393. #if 0
  394. #define WOLFSSL_TLS13
  395. #endif
  396. #undef WOLFSSL_KEY_GEN
  397. #if 0
  398. #define WOLFSSL_KEY_GEN
  399. #endif
  400. /* reduce DH test time */
  401. #define WOLFSSL_OLD_PRIME_CHECK
  402. #undef KEEP_PEER_CERT
  403. //#define KEEP_PEER_CERT
  404. #undef HAVE_COMP_KEY
  405. //#define HAVE_COMP_KEY
  406. #undef HAVE_TLS_EXTENSIONS
  407. #define HAVE_TLS_EXTENSIONS
  408. #undef HAVE_SUPPORTED_CURVES
  409. #define HAVE_SUPPORTED_CURVES
  410. #undef WOLFSSL_BASE64_ENCODE
  411. //#define WOLFSSL_BASE64_ENCODE
  412. /* TLS Session Cache */
  413. #if 0
  414. #define SMALL_SESSION_CACHE
  415. #else
  416. #define NO_SESSION_CACHE
  417. #endif
  418. /* ------------------------------------------------------------------------- */
  419. /* Disable Features */
  420. /* ------------------------------------------------------------------------- */
  421. #undef NO_WOLFSSL_SERVER
  422. //#define NO_WOLFSSL_SERVER
  423. #undef NO_WOLFSSL_CLIENT
  424. //#define NO_WOLFSSL_CLIENT
  425. #undef NO_CRYPT_TEST
  426. //#define NO_CRYPT_TEST
  427. #undef NO_CRYPT_BENCHMARK
  428. //#define NO_CRYPT_BENCHMARK
  429. #undef WOLFCRYPT_ONLY
  430. //#define WOLFCRYPT_ONLY
  431. /* In-lining of misc.c functions */
  432. /* If defined, must include wolfcrypt/src/misc.c in build */
  433. /* Slower, but about 1k smaller */
  434. #undef NO_INLINE
  435. //#define NO_INLINE
  436. #undef NO_FILESYSTEM
  437. #define NO_FILESYSTEM
  438. #undef NO_WRITEV
  439. #define NO_WRITEV
  440. #undef NO_MAIN_DRIVER
  441. #define NO_MAIN_DRIVER
  442. #undef NO_DEV_RANDOM
  443. #define NO_DEV_RANDOM
  444. #undef NO_DSA
  445. #define NO_DSA
  446. #undef NO_RC4
  447. #define NO_RC4
  448. #undef NO_OLD_TLS
  449. #define NO_OLD_TLS
  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 */