CMakeLists.txt 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788
  1. # CMakeLists.txt
  2. #
  3. # Copyright (C) 2006-2024 wolfSSL Inc.
  4. #
  5. # This file is part of wolfSSL. (formerly known as CyaSSL)
  6. #
  7. # Usage:
  8. # $ mkdir build
  9. # $ cd build
  10. # $ cmake ..
  11. # $ cmake --build .
  12. #
  13. # To build with debugging use:
  14. # $ cmake .. -DCMAKE_BUILD_TYPE=Debug
  15. #
  16. # See "Building with CMake" in INSTALL for more.
  17. ####################################################
  18. # Project
  19. ####################################################
  20. cmake_minimum_required(VERSION 3.16)
  21. if(${CMAKE_VERSION} VERSION_LESS "3.22")
  22. message(STATUS "This project recommends using CMake version 3.22 or higher. You are using ${CMAKE_VERSION}.")
  23. else()
  24. cmake_policy(SET CMP0128 NEW)
  25. endif()
  26. if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
  27. message(FATAL_ERROR "In-source builds are not allowed.\
  28. Run cmake from a separate directory from where CMakeLists.txt lives.\
  29. NOTE: cmake will now create CMakeCache.txt and CMakeFiles/*.\
  30. You must delete them, or cmake will refuse to work.")
  31. endif()
  32. project(wolfssl VERSION 5.7.2 LANGUAGES C ASM)
  33. # Set WOLFSSL_ROOT if not already defined
  34. if ("${WOLFSSL_ROOT}" STREQUAL "")
  35. # we'll assume this CMakeLists.txt is in the root of wolfSSL
  36. if (EXISTS "${CMAKE_SOURCE_DIR}/wolfcrypt/src/")
  37. get_filename_component(WOLFSSL_ROOT "${CMAKE_SOURCE_DIR}" ABSOLUTE)
  38. message(STATUS "Found WOLFSSL_ROOT = ${WOLFSSL_ROOT}")
  39. endif()
  40. else()
  41. message(STATUS "Using predefined WOLFSSL_ROOT = ${WOLFSSL_ROOT}")
  42. endif()
  43. # shared library versioning
  44. # increment if interfaces have been removed or changed
  45. set(WOLFSSL_LIBRARY_VERSION_FIRST 42)
  46. # increment if interfaces have been added
  47. # set to zero if WOLFSSL_LIBRARY_VERSION_FIRST is incremented
  48. set(WOLFSSL_LIBRARY_VERSION_SECOND 2)
  49. # increment if source code has changed
  50. # set to zero if WOLFSSL_LIBRARY_VERSION_FIRST is incremented or
  51. # WOLFSSL_LIBRARY_VERSION_SECOND is incremented
  52. set(WOLFSSL_LIBRARY_VERSION_THIRD 0)
  53. set(LIBTOOL_FULL_VERSION ${WOLFSSL_LIBRARY_VERSION_FIRST}.${WOLFSSL_LIBRARY_VERSION_SECOND}.${WOLFSSL_LIBRARY_VERSION_THIRD})
  54. set(WOLFSSL_DEFINITIONS)
  55. set(WOLFSSL_LINK_LIBS)
  56. set(WOLFSSL_INCLUDE_DIRS)
  57. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
  58. include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/functions.cmake)
  59. ####################################################
  60. # Compiler
  61. ####################################################
  62. # Let CMake choose default compiler
  63. # TODO: See gl_VISIBILITY in visibility.m4. Need to perform
  64. # the same checks.
  65. # TODO: Turn on warnings.
  66. if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
  67. # Silence ranlib warning "has no symbols"
  68. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  69. set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  70. set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  71. set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  72. endif()
  73. include(CheckIncludeFile)
  74. check_include_file("arpa/inet.h" HAVE_ARPA_INET_H)
  75. check_include_file("fcntl.h" HAVE_FCNTL_H)
  76. check_include_file("limits.h" HAVE_LIMITS_H)
  77. check_include_file("netdb.h" HAVE_NETDB_H)
  78. check_include_file("netinet/in.h" HAVE_NETINET_IN_H)
  79. check_include_file("stddef.h" HAVE_STDDEF_H)
  80. check_include_file("time.h" HAVE_TIME_H)
  81. check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H)
  82. check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H)
  83. check_include_file("sys/time.h" HAVE_SYS_TIME_H)
  84. check_include_file("errno.h" HAVE_ERRNO_H)
  85. check_include_file("dlfcn.h" HAVE_DLFCN_H)
  86. check_include_file("inttypes.h" HAVE_INTTYPES_H)
  87. check_include_file("memory.h" HAVE_MEMORY_H)
  88. check_include_file("stdint.h" HAVE_STDINT_H)
  89. check_include_file("stdlib.h" HAVE_STDLIB_H)
  90. check_include_file("string.h" HAVE_STRING_H)
  91. check_include_file("strings.h" HAVE_STRINGS_H)
  92. check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
  93. check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
  94. check_include_file("unistd.h" HAVE_UNISTD_H)
  95. include(CheckFunctionExists)
  96. # TODO: Also check if these functions are declared by the
  97. # expected headers. See comments around
  98. # AC_CHECK_FUNCS/AC_CHECK_DECLS in configure.ac.
  99. check_function_exists("gethostbyname" HAVE_GETHOSTBYNAME)
  100. check_function_exists("getaddrinfo" HAVE_GETADDRINFO)
  101. check_function_exists("gettimeofday" HAVE_GETTIMEOFDAY)
  102. check_function_exists("gmtime_r" HAVE_GMTIME_R)
  103. check_function_exists("inet_ntoa" HAVE_INET_NTOA)
  104. check_function_exists("memset" HAVE_MEMSET)
  105. check_function_exists("socket" HAVE_SOCKET)
  106. check_function_exists("strftime" HAVE_STRFTIME)
  107. check_function_exists("__atomic_fetch_add" HAVE_C___ATOMIC)
  108. include(CheckTypeSize)
  109. check_type_size("__uint128_t" __UINT128_T)
  110. check_type_size("long long" SIZEOF_LONG_LONG)
  111. check_type_size("long" SIZEOF_LONG)
  112. check_type_size("time_t" SIZEOF_TIME_T)
  113. check_type_size("uintptr_t" HAVE_UINTPTR_T)
  114. # By default, HAVE___UINT128_T gets defined as TRUE,
  115. # but we want it as 1.
  116. if(HAVE___UINT128_T)
  117. set(HAVE___UINT128_T "1" CACHE INTERNAL "Result of TRY_COMPILE" FORCE)
  118. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE___UINT128_T")
  119. endif()
  120. if(CMAKE_VERSION VERSION_LESS "3.20")
  121. # TestBigEndian was deprecated in 3.20
  122. include(TestBigEndian)
  123. test_big_endian(IS_BIG_ENDIAN)
  124. set(CMAKE_C_BYTE_ORDER "LITTLE_ENDIAN")
  125. if(IS_BIG_ENDIAN)
  126. set(CMAKE_C_BYTE_ORDER "BIG_ENDIAN")
  127. endif()
  128. endif()
  129. # Thread local storage
  130. include(CheckCSourceCompiles)
  131. set(TLS_KEYWORDS "__thread" "__declspec(thread)")
  132. foreach(TLS_KEYWORD IN LISTS TLS_KEYWORDS)
  133. set(TLS_CODE "#include <stdlib.h>
  134. static void foo(void) {
  135. static ${TLS_KEYWORD} int bar\;
  136. exit(1)\;
  137. }
  138. int main() {
  139. return 0\;
  140. }"
  141. )
  142. check_c_source_compiles(${TLS_CODE} THREAD_LS_ON)
  143. if(THREAD_LS_ON)
  144. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_THREAD_LS")
  145. break()
  146. else()
  147. # THREAD_LS_ON is cached after each call to
  148. # check_c_source_compiles, and the function
  149. # won't run subsequent times if the variable
  150. # is in the cache. To make it run again, we
  151. # need to remove the variable from the cache.
  152. unset(THREAD_LS_ON CACHE)
  153. endif()
  154. endforeach()
  155. # TODO: AX_PTHREAD does a lot. Need to implement the
  156. # rest of its logic.
  157. find_package(Threads)
  158. ####################################################
  159. # Cross Compile Example
  160. ####################################################
  161. #set(CMAKE_SYSTEM_NAME Linux)
  162. #set(CMAKE_SYSTEM_PROCESSOR arm)
  163. #set(CMAKE_C_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-gcc")
  164. #set(CMAKE_CXX_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-g++")
  165. #set(CMAKE_SYSROOT "/opt/arm-linux-musleabihf-cross/arm-linux-musleabihf/")
  166. # Example for setting CFLAGS
  167. #set(CMAKE_C_FLAGS "-std=gnu89 ${CMAKE_C_FLAGS}")
  168. # Example for map file and custom linker script
  169. #set(CMAKE_EXE_LINKER_FLAGS " -Xlinker -Map=output.map -T\"${CMAKE_CURRENT_SOURCE_DIR}/linker.ld\"")
  170. if(DEFINED WARNING_C_FLAGS)
  171. set(CMAKE_C_FLAGS "${WARNING_C_FLAGS} ${CMAKE_C_FLAGS}")
  172. elseif(WIN32)
  173. # Windows cl.exe does not support the -Wextra, -Wno-unused and -Werror flags.
  174. set(CMAKE_C_FLAGS "-Wall ${CMAKE_C_FLAGS}")
  175. else()
  176. set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused -Werror ${CMAKE_C_FLAGS}")
  177. endif()
  178. ####################################################
  179. # Build Options
  180. ####################################################
  181. # TODO: - FIPS
  182. # - Distro
  183. # - Linux Kernel Module
  184. # - Single precision math
  185. # - Enable all
  186. # - Enable all crypto
  187. # For reproducible build, gate out from the build anything that might
  188. # introduce semantically frivolous jitter, maximizing chance of
  189. # identical object files.
  190. add_option("WOLFSSL_REPRODUCIBLE_BUILD"
  191. "Enable maximally reproducible build (default: disabled)"
  192. "no" "yes;no")
  193. if(WOLFSSL_REPRODUCIBLE_BUILD)
  194. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_REPRODUCIBLE_BUILD")
  195. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>")
  196. set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>")
  197. set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>")
  198. endif()
  199. add_option("WOLFSSL_INSTALL" "Create install target for WolfSSL project" "yes" "yes;no")
  200. # Support for forcing 32-bit mode
  201. # TODO: detect platform from other options
  202. add_option("WOLFSSL_32BIT"
  203. "Enables 32-bit support (default: disabled)"
  204. "no" "yes;no")
  205. # 16-bit compiler support
  206. add_option("WOLFSSL_16BIT"
  207. "Enables 16-bit support (default: disabled)"
  208. "no" "yes;no")
  209. if(WOLFSSL_16BIT)
  210. list(APPEND WOLFSSL_DEFINITIONS "-DWC_16BIT_CPU")
  211. endif()
  212. # Support for disabling all ASM
  213. add_option("WOLFSSL_ASM"
  214. "Enables option for assembly (default: enabled)"
  215. "yes" "yes;no")
  216. if(NOT WOLFSSL_ASM)
  217. list(APPEND WOLFSSL_DEFINITIONS
  218. "-DTFM_NO_ASM"
  219. "-DWOLFSSL_NO_ASM")
  220. endif()
  221. # Enable Debugging
  222. add_option("WOLFSSL_DEBUG"
  223. "Enables option for debug (default: disabled)"
  224. "no" "yes;no")
  225. if(WOLFSSL_DEBUG)
  226. set(CMAKE_C_FLAGS "-g ${CMAKE_C_FLAGS}")
  227. list(APPEND WOLFSSL_DEFINITIONS
  228. "-DDEBUG_WOLFSSL"
  229. "-DDEBUG")
  230. endif()
  231. # Single threaded
  232. add_option("WOLFSSL_SINGLE_THREADED"
  233. "Enable wolfSSL single threaded (default: disabled)"
  234. "no" "yes;no")
  235. # TODO: Logic here isn't complete, yet (see AX_PTHREAD)
  236. if(NOT WOLFSSL_SINGLE_THREADED)
  237. if(CMAKE_USE_PTHREADS_INIT)
  238. list(APPEND WOLFSSL_LINK_LIBS Threads::Threads)
  239. set(HAVE_PTHREAD 1)
  240. list(APPEND WOLFSSL_DEFINITIONS
  241. "-DHAVE_PTHREAD"
  242. "-D_POSIX_THREADS")
  243. endif()
  244. else()
  245. list(APPEND WOLFSSL_DEFINITIONS "-DSINGLE_THREADED")
  246. endif()
  247. # DTLS-SRTP
  248. add_option("WOLFSSL_SRTP"
  249. "Enables wolfSSL DTLS-SRTP (default: disabled)"
  250. "no" "yes;no")
  251. if(WOLFSSL_SRTP)
  252. list(APPEND WOLFSSL_DEFINITIONS
  253. "-DWOLFSSL_SRTP")
  254. set(WOLFSSL_DTLS "yes")
  255. set(WOLFSSL_KEYING_MATERIAL "yes")
  256. endif()
  257. # DTLS
  258. add_option("WOLFSSL_DTLS"
  259. "Enables wolfSSL DTLS (default: disabled)"
  260. "no" "yes;no")
  261. if(WOLFSSL_DTLS)
  262. list(APPEND WOLFSSL_DEFINITIONS
  263. "-DWOLFSSL_DTLS")
  264. endif()
  265. # TLS v1.3
  266. add_option("WOLFSSL_TLS13"
  267. "Enable wolfSSL TLS v1.3 (default: enabled)"
  268. "yes" "yes;no")
  269. if("${FIPS_VERSION}" STREQUAL "v1")
  270. override_cache(WOLFSSL_TLS13 "no")
  271. endif()
  272. # Post-handshake authentication
  273. add_option("WOLFSSL_POSTAUTH"
  274. "Enable wolfSSL Post-handshake Authentication (default: disabled)"
  275. "no" "yes;no")
  276. if(WOLFSSL_POSTAUTH)
  277. if(NOT WOLFSSL_TLS13)
  278. message(WARNING "TLS 1.3 is disabled - disabling Post-handshake Authentication")
  279. override_cache(WOLFSSL_POSTAUTH "no")
  280. else()
  281. list(APPEND WOLFSSL_DEFINITIONS
  282. "-DWOLFSSL_POST_HANDSHAKE_AUTH")
  283. endif()
  284. endif()
  285. # Hello Retry Request Cookie
  286. add_option("WOLFSSL_HRR_COOKIE"
  287. "Enable the server to send Cookie Extension in HRR with state (default: disabled)"
  288. "undefined" "yes;no;undefined")
  289. if("${WOLFSSL_HRR_COOKIE}" STREQUAL "yes")
  290. if(NOT WOLFSSL_TLS13)
  291. message(WARNING "TLS 1.3 is disabled - disabling HRR Cookie")
  292. override_cache(WOLFSSL_HRR_COOKIE "no")
  293. else()
  294. list(APPEND WOLFSSL_DEFINITIONS
  295. "-DWOLFSSL_SEND_HRR_COOKIE")
  296. endif()
  297. endif()
  298. # DTLS v1.3
  299. add_option("WOLFSSL_DTLS13"
  300. "Enable wolfSSL DTLS v1.3 (default: disabled)"
  301. "no" "yes;no")
  302. if(WOLFSSL_DTLS13)
  303. if (NOT WOLFSSL_DTLS)
  304. message(FATAL_ERROR "DTLS13 requires DTLS")
  305. endif()
  306. if (NOT WOLFSSL_TLS13)
  307. message(FATAL_ERROR "DTLS13 requires TLS13")
  308. endif()
  309. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_DTLS13")
  310. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_W64_WRAPPER")
  311. if ("${WOLFSSL_HRR_COOKIE}" STREQUAL "undefined")
  312. message(WARNING "DTLS1.3 is enabled - enabling HRR Cookie")
  313. override_cache(WOLFSSL_HRR_COOKIE "yes")
  314. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SEND_HRR_COOKIE")
  315. endif()
  316. if (WOLFSSL_AES)
  317. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_AES_DIRECT")
  318. endif()
  319. endif()
  320. # DTLS ConnectionID support
  321. add_option("WOLFSSL_DTLS_CID"
  322. "Enables wolfSSL DTLS CID (default: disabled)"
  323. "no" "yes;no")
  324. if(WOLFSSL_DTLS_CID)
  325. if(NOT WOLFSSL_DTLS13)
  326. message(FATAL_ERROR "CID are supported only for DTLSv1.3")
  327. endif()
  328. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_DTLS_CID")
  329. endif()
  330. # RNG
  331. add_option("WOLFSSL_RNG"
  332. "Enable compiling and using RNG (default: enabled)"
  333. "yes" "yes;no")
  334. if(NOT WOLFSSL_RNG)
  335. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_RNG")
  336. endif()
  337. # QUIC
  338. add_option(WOLFSSL_QUIC
  339. "Enable QUIC support (default: disabled)"
  340. "no" "yes;no")
  341. if(WOLFSSL_QUIC)
  342. set(WOLFSSL_ALPN "yes")
  343. set(WOLFSSL_OPENSSLEXTRA "yes")
  344. set(WOLFSSL_AESCTR "yes")
  345. set(WOLFSSL_CURVE25519 "yes")
  346. set(WOLFSSL_SNI "yes")
  347. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_QUIC" "-DHAVE_EX_DATA")
  348. endif()
  349. # Curl
  350. add_option(WOLFSSL_CURL
  351. "Enable CURL support (default: disabled)"
  352. "no" "yes;no")
  353. if(WOLFSSL_CURL)
  354. set(WOLFSSL_MD4 "yes")
  355. set(WOLFSSL_DES3 "yes")
  356. set(WOLFSSL_ALPN "yes")
  357. set(WOLFSSL_WOLFSSH "yes")
  358. set(WOLFSSL_OPENSSLEXTRA "yes")
  359. set(WOLFSSL_CRL "yes")
  360. set(WOLFSSL_OCSP "yes")
  361. set(WOLFSSL_OCSPSTAPLING "yes")
  362. set(WOLFSSL_OCSPSTAPLING_V2 "yes")
  363. # Note: OCSP sets requisite HAVE_TLS_EXTENSIONS and HAVE_CERTIFICATE_STATUS_REQUEST(_V2)
  364. set(WOLFSSL_SNI "yes")
  365. set(WOLFSSL_ALT_CERT_CHAINS "yes")
  366. set(WOLFSSL_IP_ALT_NAME "yes")
  367. set(WOLFSSL_SESSION_TICKET "yes")
  368. list(APPEND WOLFSSL_DEFINITIONS
  369. "-DNO_SESSION_CACHE_REF" "-DWOLFSSL_DES_ECB")
  370. endif()
  371. # ALPN
  372. add_option(WOLFSSL_ALPN
  373. "Enable ALPN support (default: disabled)"
  374. "no" "yes;no")
  375. if(WOLFSSL_ALPN)
  376. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ALPN" "-DHAVE_TLS_EXTENSIONS")
  377. endif()
  378. # altcertchains
  379. add_option(WOLFSSL_ALT_CERT_CHAINS
  380. "Enable support for Alternate certification chains (default: disabled)"
  381. "no" "yes;no")
  382. if(WOLFSSL_ALT_CERT_CHAINS)
  383. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_ALT_CERT_CHAINS")
  384. endif()
  385. # ip-alt-name
  386. add_option(WOLFSSL_IP_ALT_NAME
  387. "Enable support for IP alternative name (default: disabled)"
  388. "no" "yes;no")
  389. if(WOLFSSL_IP_ALT_NAME)
  390. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_IP_ALT_NAME")
  391. endif()
  392. # wolfSSH
  393. add_option(WOLFSSL_WOLFSSH
  394. "Enable support for wolfSSH (default: disabled)"
  395. "no" "yes;no")
  396. if(WOLFSSL_WOLFSSH)
  397. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_WOLFSSH")
  398. endif()
  399. if(WOLFSSL_WOLFSSH OR WOLFSSL_WPAS)
  400. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_PUBLIC_MP")
  401. endif()
  402. # TODO: - DTLS-SCTP
  403. # - DTLS multicast
  404. # - OpenSSH
  405. # - OpenVPN
  406. # - Nginx
  407. # - HAProxy
  408. # - wpa_supplicant
  409. # - Fortress
  410. # - libwebsockets
  411. # - Qt
  412. # - SSL bump
  413. # - sniffer
  414. # - Signal
  415. # - OpenSSL coexist
  416. # - Max strength
  417. # Harden, enable Timing Resistance and Blinding by default
  418. add_option("WOLFSSL_HARDEN"
  419. "Enable Hardened build, Enables Timing Resistance and Blinding (default: enabled)"
  420. "yes" "yes;no")
  421. if(WOLFSSL_HARDEN)
  422. list(APPEND WOLFSSL_DEFINITIONS "-DTFM_TIMING_RESISTANT" "-DECC_TIMING_RESISTANT")
  423. if(WOLFSSL_RNG)
  424. list(APPEND WOLFSSL_DEFINITIONS "-DWC_RSA_BLINDING")
  425. endif()
  426. else()
  427. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_HARDEN")
  428. endif()
  429. add_option(WOLFSSL_OPENSSLEXTRA
  430. "Enable extra OpenSSL API, size+ (default: disabled)"
  431. "no" "yes;no")
  432. add_option(WOLFSSL_OPENSSLALL
  433. "Enable all OpenSSL API, size++ (default: disabled)"
  434. "no" "yes;no")
  435. add_option(WOLFSSL_ASIO
  436. "Enable asio support (default: disabled)"
  437. "no" "yes;no")
  438. if (WOLFSSL_ASIO)
  439. list(APPEND WOLFSSL_DEFINITIONS
  440. "-DWOLFSSL_ASIO" "-DASIO_USE_WOLFSSL"
  441. "-DBOOST_ASIO_USE_WOLFSSL" "-DHAVE_EX_DATA"
  442. "-DSSL_TXT_TLSV1_2" "-DOPENSSL_NO_SSL2" "-DOPENSSL_NO_SSL3"
  443. "-DHAVE_OCSP" "-DWOLFSSL_KEY_GEN")
  444. override_cache(WOLFSSL_OPENSSLALL "yes")
  445. override_cache(WOLFSSL_OPENSSLEXTRA "yes")
  446. endif()
  447. if (WOLFSSL_OPENSSLEXTRA AND NOT WOLFSSL_OPENSSLCOEXIST)
  448. list(APPEND WOLFSSL_DEFINITIONS
  449. "-DOPENSSL_EXTRA")
  450. endif()
  451. if (WOLFSSL_OPENSSLALL)
  452. list(APPEND WOLFSSL_DEFINITIONS
  453. "-DOPENSSL_ALL" "-DWOLFSSL_EITHER_SIDE" "-DWC_RSA_NO_PADDING"
  454. "-DWC_RSA_PSS" "-DWOLFSSL_PSS_LONG_SALT" "-DWOLFSSL_TICKET_HAVE_ID"
  455. "-DWOLFSSL_ERROR_CODE_OPENSSL" "-DWOLFSSL_CERT_NAME_ALL")
  456. endif()
  457. add_option(WOLFSSL_NO_STUB
  458. "Removes OpenSSL compatibility stub functions (default: disabled)"
  459. "no" "yes;no")
  460. if (WOLFSSL_NO_STUB)
  461. list(APPEND WOLFSSL_DEFINITIONS
  462. "-DNO_WOLFSSL_STUB")
  463. endif()
  464. # TODO: - IPv6 test apps
  465. set(WOLFSSL_SLOW_MATH "yes")
  466. # liboqs
  467. add_option(WOLFSSL_OQS
  468. "Enable integration with the OQS (Open Quantum Safe) liboqs library (default: disabled)"
  469. "no" "yes;no")
  470. # Kyber
  471. add_option(WOLFSSL_KYBER
  472. "Enable the wolfSSL PQ Kyber library (default: disabled)"
  473. "no" "yes;no")
  474. # Experimental features
  475. add_option(WOLFSSL_EXPERIMENTAL
  476. "Enable experimental features (default: disabled)"
  477. "no" "yes;no")
  478. message(STATUS "Looking for WOLFSSL_EXPERIMENTAL")
  479. if (WOLFSSL_EXPERIMENTAL)
  480. message(STATUS "Looking for WOLFSSL_EXPERIMENTAL - found")
  481. # We've enabled the experimental environment, but let's
  482. # check if any experimental features are also enabled:
  483. set(WOLFSSL_FOUND_EXPERIMENTAL_FEATURE 0)
  484. set_wolfssl_definitions("WOLFSSL_EXPERIMENTAL_SETTINGS" RESUlT)
  485. # Checking for experimental feature: OQS
  486. message(STATUS "Looking for WOLFSSL_OQS")
  487. if (WOLFSSL_OQS)
  488. set(WOLFSSL_FOUND_EXPERIMENTAL_FEATURE 1)
  489. message(STATUS "Looking for WOLFSSL_OQS - found")
  490. message(STATUS "Checking OQS")
  491. find_package(OQS)
  492. if (OQS_FOUND)
  493. message(STATUS "Checking OQS - found")
  494. list(APPEND WOLFSSL_LINK_LIBS ${OQS_LIBRARY})
  495. list(APPEND WOLFSSL_INCLUDE_DIRS ${OQS_INCLUDE_DIR})
  496. set_wolfssl_definitions("HAVE_LIBOQS" RESUlT)
  497. set_wolfssl_definitions("HAVE_TLS_EXTENSIONS" RESUlT)
  498. set_wolfssl_definitions("OPENSSL_EXTRA" RESUlT)
  499. else()
  500. message(STATUS "Checking OQS - not found")
  501. message(STATUS "WARNING: WOLFSSL_OQS enabled but not found: OQS_LIBRARY=${OQS_LIBRARY}, OQS_INCLUDE_DIR=${OQS_INCLUDE_DIR} ")
  502. endif()
  503. else()
  504. message(STATUS "Looking for WOLFSSL_OQS - not found")
  505. endif()
  506. # Checking for experimental feature: Kyber
  507. message(STATUS "Looking for WOLFSSL_KYBER")
  508. if (WOLFSSL_KYBER)
  509. set(WOLFSSL_FOUND_EXPERIMENTAL_FEATURE 1)
  510. message(STATUS "Automatically set related requirements for Kyber:")
  511. set_wolfssl_definitions("WOLFSSL_HAVE_KYBER" RESUlT)
  512. set_wolfssl_definitions("WOLFSSL_WC_KYBER" RESUlT)
  513. set_wolfssl_definitions("WOLFSSL_SHA3" RESUlT)
  514. set_wolfssl_definitions("WOLFSSL_SHAKE128" RESUlT)
  515. set_wolfssl_definitions("WOLFSSL_SHAKE256" RESUlT)
  516. message(STATUS "Looking for WOLFSSL_KYBER - found")
  517. else()
  518. message(STATUS "Looking for WOLFSSL_KYBER - not found")
  519. endif()
  520. # Other experimental feature detection can be added here...
  521. # Were any experimental features found? Display a message.
  522. if(WOLFSSL_FOUND_EXPERIMENTAL_FEATURE)
  523. message(STATUS "WOLFSSL_EXPERIMENTAL enabled, experimental features enabled.")
  524. else()
  525. message(STATUS "Warning: WOLFSSL_EXPERIMENTAL enabled, but no experimental features enabled.")
  526. endif()
  527. # Sanity checks
  528. if(WOLFSSL_OQS AND WOLFSSL_KYBER)
  529. message(FATAL_ERROR "Error: cannot enable both WOLFSSL_OQS and WOLFSSL_KYBER at the same time.")
  530. endif()
  531. else()
  532. # Experimental mode not enabled, but were any experimental features enabled? Error out if so:
  533. message(STATUS "Looking for WOLFSSL_EXPERIMENTAL - not found")
  534. if (WOLFSSL_OQS)
  535. message(FATAL_ERROR "Error: WOLFSSL_OQS requires WOLFSSL_EXPERIMENTAL at this time.")
  536. endif()
  537. if(WOLFSSL_KYBER)
  538. message(FATAL_ERROR "Error: WOLFSSL_KYBER requires WOLFSSL_EXPERIMENTAL at this time.")
  539. endif()
  540. endif()
  541. # TODO: - Lean PSK
  542. # - Lean TLS
  543. # - Low resource
  544. # - Titan cache
  545. # - Huge cache
  546. # - Big cache
  547. # - Small cache
  548. # - Persistent session cache
  549. # - Persistent cert cache
  550. # - Write duplicate
  551. # - Atomic user record layer
  552. # - Public key callbacks
  553. # - Microchip/Atmel CryptoAuthLib
  554. # - XMSS
  555. # - LMS
  556. # - dual-certs
  557. # AES-CBC
  558. add_option("WOLFSSL_AESCBC"
  559. "Enable wolfSSL AES-CBC support (default: enabled)"
  560. "yes" "yes;no")
  561. if(NOT WOLFSSL_AESCBC)
  562. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES_CBC")
  563. endif()
  564. # AES-GCM
  565. add_option("WOLFSSL_AESGCM"
  566. "Enable wolfSSL AES-GCM support (default: enabled)"
  567. "yes" "yes;no;table;small;word32;4bit")
  568. # leanpsk and leantls don't need gcm
  569. if(WOLFSSL_LEAN_PSK OR (WOLFSSL_LEAN_TLS AND NOT WOLFSSL_TLS13))
  570. override_cache(WOLFSSL_AESGCM "no")
  571. endif()
  572. if(WOLFSSL_AESGCM AND CMAKE_C_BYTE_ORDER STREQUAL "LITTLE_ENDIAN")
  573. override_cache(WOLFSSL_AESGCM "4bit")
  574. endif()
  575. if(WOLFSSL_AESGCM)
  576. if("${WOLFSSL_AESGCM}" STREQUAL "word32")
  577. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_WORD32")
  578. override_cache(WOLFSSL_AESGCM "yes")
  579. endif()
  580. if(("${WOLFSSL_AESGCM}" STREQUAL "small") OR WOLFSSL_LOW_RESOURCE)
  581. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_SMALL")
  582. override_cache(WOLFSSL_AESGCM "yes")
  583. endif()
  584. if("${WOLFSSL_AESGCM}" STREQUAL "table")
  585. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_TABLE")
  586. override_cache(WOLFSSL_AESGCM "yes")
  587. endif()
  588. if("${WOLFSSL_AESGCM}" STREQUAL "4bit")
  589. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_TABLE_4BIT")
  590. override_cache(WOLFSSL_AESGCM "yes")
  591. endif()
  592. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_AESGCM")
  593. endif()
  594. if(WOLFSSL_QUIC)
  595. if(NOT WOLFSSL_TLS13)
  596. message(FATAL_ERROR "TLS 1.3 is disabled - necessary for QUIC")
  597. endif()
  598. if(NOT WOLFSSL_AESGCM)
  599. message(FATAL_ERROR "AES-GCM is disabled - necessary for QUIC")
  600. endif()
  601. endif()
  602. # AES-SIV
  603. add_option("WOLFSSL_AESSIV"
  604. "Enable wolfSSL AES-SIV support (default: disabled)"
  605. "no" "yes;no")
  606. if(WOLFSSL_AESSIV)
  607. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_AES_SIV")
  608. endif()
  609. # AES-CTR
  610. add_option("WOLFSSL_AESCTR"
  611. "Enable wolfSSL AES-CTR support (default: disabled)"
  612. "no" "yes;no")
  613. if(WOLFSSL_OPENVPN OR
  614. WOLFSSL_LIBSSH2 OR
  615. WOLFSSL_AESSIV)
  616. override_cache(WOLFSSL_AESCTR "yes")
  617. endif()
  618. if(WOLFSSL_AESCTR AND NOT WOLFSSL_FORTRESS)
  619. list(APPEND WOLFSSL_DEFINITIONS
  620. "-DWOLFSSL_AES_COUNTER"
  621. "-DWOLFSSL_AES_DIRECT")
  622. endif()
  623. # ARIA
  624. add_option("WOLFSSL_ARIA"
  625. "Enable wolfSSL ARIA support (default: disabled)"
  626. "no" "yes;no")
  627. # AES-CCM
  628. add_option("WOLFSSL_AESCCM"
  629. "Enable wolfSSL AES-CCM support (default: disabled)"
  630. "no" "yes;no")
  631. # AES-OFB
  632. add_option("WOLFSSL_AESOFB"
  633. "Enable wolfSSL AES-OFB support (default: disabled)"
  634. "no" "yes;no")
  635. # TODO: - AES-GCM stream
  636. # - AES-ARM
  637. # - Xilinx hardened crypto
  638. # - Intel AES-NI
  639. # - Intel ASM
  640. # - Intel RDRAND
  641. # - Linux af_alg
  642. # - Linux dev crpyto calls
  643. # - Camellia
  644. # - MD2
  645. # - NULL cipher
  646. # - RIPEMD
  647. # - BLAKE2
  648. add_option("WOLFSSL_AESCFB"
  649. "Enable wolfSSL AES-CFB support (default: disabled)"
  650. "no" "yes;no")
  651. # Align data
  652. add_option("WOLFSSL_ALIGN_DATA"
  653. "Align data for ciphers (default: enabled)"
  654. "yes" "yes;no")
  655. if(WOLFSSL_ALIGN_DATA)
  656. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_USE_ALIGN")
  657. endif()
  658. # SHA224
  659. set(SHA224_DEFAULT "no")
  660. if(("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64|AMD64|arm64") OR
  661. ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
  662. if(NOT WOLFSSL_AFALG AND NOT WOLFSSL_DEVCRYPTO AND
  663. (NOT WOLFSSL_FIPS OR ("${FIPS_VERSION}" STREQUAL "v2")))
  664. set(SHA224_DEFAULT "yes")
  665. endif()
  666. endif()
  667. add_option("WOLFSSL_SHA224"
  668. "Enable wolfSSL SHA-224 support (default: enabled on x86_64/aarch64)"
  669. ${SHA224_DEFAULT} "yes;no")
  670. # SHA3
  671. set(SHA3_DEFAULT "no")
  672. if(("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64|AMD64|arm64") OR
  673. ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
  674. if(NOT WOLFSSL_FIPS OR ("${FIPS_VERSION}" STREQUAL "v2"))
  675. set(SHA3_DEFAULT "yes")
  676. endif()
  677. endif()
  678. add_option("WOLFSSL_SHA3"
  679. "Enable wolfSSL SHA-3 support (default: enabled on x86_64/aarch64)"
  680. ${SHA3_DEFAULT} "yes;no;small")
  681. # SHAKE256
  682. add_option("WOLFSSL_SHAKE256"
  683. "Enable wolfSSL SHAKE256 support (default: enabled on x86_64/aarch64)"
  684. "no" "yes;no;small")
  685. # SHAKE128
  686. add_option("WOLFSSL_SHAKE128"
  687. "Enable wolfSSL SHAKE128 support (default: enabled on x86_64/aarch64)"
  688. "no" "yes;no;small")
  689. # SHA512
  690. add_option("WOLFSSL_SHA512"
  691. "Enable wolfSSL SHA-512 support (default: enabled)"
  692. "yes" "yes;no")
  693. # options that don't require sha512
  694. if(WOLFSSL_LEAN_PSK OR
  695. WOLFSSL_LEAN_TLS OR
  696. WOLFSSL_32BIT OR
  697. WOLFSSL_16BIT)
  698. override_cache(WOLFSSL_SHA512 "no")
  699. endif()
  700. # options that require sha512
  701. if(WOLFSSL_OPENSSH OR
  702. WOLFSSL_WPAS OR
  703. WOLFSSL_FORTRESS)
  704. override_cache(WOLFSSL_SHA512 "yes")
  705. endif()
  706. if(WOLFSSL_SHA512)
  707. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA512")
  708. endif()
  709. # SHA384
  710. add_option("WOLFSSL_SHA384"
  711. "Enable wolfSSL SHA-384 support (default: enabled)"
  712. "yes" "yes;no")
  713. # options that don't require sha384
  714. if(WOLFSSL_LEAN_PSK OR
  715. WOLFSSL_LEAN_TLS OR
  716. WOLFSSL_32BIT OR
  717. WOLFSSL_16BIT)
  718. override_cache(WOLFSSL_SHA384 "no")
  719. endif()
  720. # options that require sha384
  721. if(WOLFSSL_OPENSSH OR
  722. WOLFSSL_WPAS OR
  723. WOLFSSL_FORTRESS)
  724. override_cache(WOLFSSL_SHA384 "yes")
  725. endif()
  726. if(WOLFSSL_SHA384)
  727. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA384")
  728. endif()
  729. # TODO: - Session certs
  730. # - SEP
  731. add_option("WOLFSSL_KEYGEN"
  732. "Enable key generation (default: disabled)])"
  733. "no" "yes;no")
  734. add_option("WOLFSSL_CERTGEN"
  735. "Enable cert generation (default: disabled)"
  736. "no" "yes;no")
  737. add_option("WOLFSSL_CERTREQ"
  738. "Enable cert request generation (default: disabled)"
  739. "no" "yes;no")
  740. add_option("WOLFSSL_CERTEXT"
  741. "Enable cert request extensions (default: disabled)"
  742. "no" "yes;no")
  743. add_option("WOLFSSL_CERTGENCACHE"
  744. "Enable decoded cert caching (default: disabled)"
  745. "no" "yes;no")
  746. # HKDF
  747. add_option("WOLFSSL_HKDF"
  748. "Enable HKDF (HMAC-KDF) support (default: disabled)"
  749. "no" "yes;no")
  750. if(WOLFSSL_TLS13)
  751. override_cache(WOLFSSL_HKDF "yes")
  752. endif()
  753. if(WOLFSSL_HKDF)
  754. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HKDF")
  755. endif()
  756. # DSA
  757. add_option("WOLFSSL_DSA"
  758. "Enable DSA (default: disabled)"
  759. "no" "yes;no")
  760. if(NOT WOLFSSL_DSA AND NOT WOLFSSL_OPENSSH)
  761. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DSA")
  762. endif()
  763. # ECC Shamir
  764. add_option("WOLFSSL_ECCSHAMIR"
  765. "Enable ECC Shamir (default: enabled)"
  766. "yes" "yes;no")
  767. # ECC
  768. add_option("WOLFSSL_ECC"
  769. "Enable ECC (default: enabled)"
  770. "yes" "yes;no;nonblock")
  771. # lean psk doesn't need ecc
  772. if(WOLFSSL_LEAN_PSK)
  773. override_cache(WOLFSSL_ECC "no")
  774. endif()
  775. if(WOLFSSL_OPENSSH OR
  776. WOLFSSL_NGINX OR
  777. WOLFSSL_SIGNAL)
  778. override_cache(WOLFSSL_ECC "yes")
  779. endif()
  780. if(WOLFSSL_ECC)
  781. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ECC" "-DTFM_ECC256")
  782. if(WOLFSSL_ECCSHAMIR AND NOT WOLFSSL_LOW_RESOURCE)
  783. list(APPEND WOLFSSL_DEFINITIONS "-DECC_SHAMIR")
  784. endif()
  785. if("${WOLFSSL_ECC}" STREQUAL "nonblock")
  786. list(APPEND WOLFSSL_DEFINITIONS "-DWC_ECC_NONBLOCK")
  787. endif()
  788. endif()
  789. # TODO: - Compressed key
  790. # - FP ECC, fixed point cache ECC
  791. # - ECC encrypt
  792. # - PSK
  793. # - Single PSK identity
  794. # ECC custom curves
  795. add_option("WOLFSSL_ECCCUSTCURVES"
  796. "Enable ECC Custom Curves (default: disabled)"
  797. "no" "yes;no;all")
  798. if(WOLFSSL_ECCCUSTCURVES)
  799. if("${WOLFSSL_ECCCUSTCURVES}" STREQUAL "all")
  800. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ECC_SECPR2")
  801. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ECC_SECPR3")
  802. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ECC_BRAINPOOL")
  803. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ECC_KOBLITZ")
  804. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ECC_CDH")
  805. endif()
  806. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CUSTOM_CURVES")
  807. endif()
  808. # CURVE25519
  809. set(WOLFSSL_CURVE25519_SMALL "no")
  810. add_option("WOLFSSL_CURVE25519"
  811. "Enable Curve25519 (default: disabled)"
  812. "no" "yes;no;small;no128bit")
  813. if(WOLFSSL_OPENSSH)
  814. override_cache(WOLFSSL_CURVE25519 "yes")
  815. endif()
  816. if(WOLFSSL_CURVE25519)
  817. if("${WOLFSSL_CURVE25519}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  818. list(APPEND WOLFSSL_DEFINITIONS "-DCURVE25519_SMALL")
  819. set(WOLFSSL_CURVE25519_SMALL "yes")
  820. endif()
  821. if("${WOLFSSL_CURVE25519}" STREQUAL "no128bit" OR WOLFSSL_32BIT)
  822. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CURVED25519_128BIT")
  823. endif()
  824. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CURVE25519")
  825. set(WOLFSSL_FEMATH "yes")
  826. endif()
  827. # ED25519
  828. set(WOLFSSL_ED25519_SMALL "no")
  829. add_option("WOLFSSL_ED25519"
  830. "Enable ED25519 (default: disabled)"
  831. "no" "yes;no")
  832. if(WOLFSSL_OPENSSH)
  833. override_cache(WOLFSSL_ED25519 "yes")
  834. endif()
  835. if(WOLFSSL_ED25519 AND NOT WOLFSSL_32BIT)
  836. if("${WOLFSSL_ED25519}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  837. list(APPEND WOLFSSL_DEFINITIONS "-DED25519_SMALL")
  838. set(WOLFSSL_ED25519_SMALL "yes")
  839. set(WOLFSSL_CURVE25519_SMALL "yes")
  840. endif()
  841. if(NOT WOLFSSL_SHA512)
  842. message(FATAL_ERROR "cannot enable ed25519 without enabling sha512.")
  843. endif()
  844. set(WOLFSSL_FEMATH "yes")
  845. set(WOLFSSL_GEMATH "yes")
  846. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ED25519")
  847. endif()
  848. # CURVE448
  849. set(WOLFSSL_CURVE448_SMALL "no")
  850. add_option("WOLFSSL_CURVE448"
  851. "Enable Curve448 (default: disabled)"
  852. "no" "yes;no;small")
  853. if(WOLFSSL_CURVE448)
  854. if("${WOLFSSL_CURVE448}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  855. list(APPEND WOLFSSL_DEFINITIONS "-DCURVE448_SMALL")
  856. set(WOLFSSL_CURVE448_SMALL "yes")
  857. endif()
  858. if("${WOLFSSL_CURVE448}" STREQUAL "no128bit" OR WOLFSSL_32BIT)
  859. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CURVED448_128BIT")
  860. endif()
  861. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CURVE448")
  862. set(WOLFSSL_FE448 "yes")
  863. endif()
  864. # ED448
  865. set(WOLFSSL_ED448_SMALL "no")
  866. add_option("WOLFSSL_ED448"
  867. "Enable ED448 (default: disabled)"
  868. "no" "yes;no;small")
  869. if(WOLFSSL_ED448 AND NOT WOLFSSL_32BIT)
  870. if("${WOLFSSL_ED448}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  871. list(APPEND WOLFSSL_DEFINITIONS "-DED448_SMALL")
  872. set(WOLFSSL_ED448_SMALL "yes")
  873. set(WOLFSSL_CURVE448_SMALL "yes")
  874. endif()
  875. if(NOT WOLFSSL_SHA512)
  876. message(FATAL_ERROR "cannot enable ed448 without enabling sha512.")
  877. endif()
  878. set(WOLFSSL_FE448 "yes")
  879. set(WOLFSSL_GE448 "yes")
  880. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ED448")
  881. # EdDSA448 requires SHAKE256 which requires SHA-3
  882. override_cache(WOLFSSL_SHAKE256 "yes")
  883. endif()
  884. # Error strings
  885. add_option("WOLFSSL_ERROR_STRINGS"
  886. "Enable error strings table (default: enabled)"
  887. "yes" "yes;no")
  888. if(NOT WOLFSSL_ERROR_STRINGS)
  889. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ERROR_STRINGS")
  890. else()
  891. # turn off error strings if leanpsk or leantls on
  892. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  893. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ERROR_STRINGS")
  894. override_cache(WOLFSSL_ERROR_STRINGS "no")
  895. endif()
  896. endif()
  897. # Error queue
  898. add_option("WOLFSSL_ERROR_QUEUE"
  899. "Enables adding nodes to error queue when compiled with OPENSSL_EXTRA (default: enabled)"
  900. "yes" "yes;no")
  901. if(NOT WOLFSSL_ERROR_QUEUE)
  902. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ERROR_QUEUE")
  903. endif()
  904. # Old TLS
  905. add_option("WOLFSSL_OLD_TLS"
  906. "Enable old TLS versions < 1.2 (default: enabled)"
  907. "yes" "yes;no")
  908. if(NOT WOLFSSL_OLD_TLS)
  909. list(APPEND WOLFSSL_DEFINITIONS "-DNO_OLD_TLS")
  910. else()
  911. # turn off old if leanpsk or leantls on
  912. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  913. list(APPEND WOLFSSL_DEFINITIONS "-DNO_OLD_TLS")
  914. override_cache(WOLFSSL_OLD_TLS "no")
  915. endif()
  916. endif()
  917. # TLSv1.2
  918. add_option("WOLFSSL_TLSV12"
  919. "Enable TLS versions 1.2 (default: enabled)"
  920. "yes" "yes;no")
  921. if(NOT WOLFSSL_TLSV12)
  922. list(APPEND WOLFSSL_DEFINITIONS
  923. "-DWOLFSSL_NO_TLS12"
  924. "-DNO_OLD_TLS")
  925. endif()
  926. # TODO: - TLSv1.0
  927. # - SSLv3
  928. # - Stack size
  929. # - Stack size verbose
  930. # Memory
  931. add_option("WOLFSSL_MEMORY"
  932. "Enable memory callbacks (default: enabled)"
  933. "yes" "yes;no")
  934. if(NOT WOLFSSL_MEMORY)
  935. list(APPEND WOLFSSL_DEFINITIONS "-DNO_WOLFSSL_MEMORY")
  936. else()
  937. # turn off memory cb if leanpsk or leantls on
  938. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  939. # but don't turn on NO_WOLFSSL_MEMORY because using own
  940. override_cache(WOLFSSL_MEMORY "no")
  941. endif()
  942. endif()
  943. # TODO: - Track memory
  944. # - Memory log
  945. # - Stack log
  946. # RSA
  947. add_option("WOLFSSL_RSA"
  948. "Enable RSA (default: enabled)"
  949. "yes" "yes;no")
  950. if(NOT WOLFSSL_RSA)
  951. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RSA")
  952. else()
  953. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  954. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RSA")
  955. override_cache(WOLFSSL_RSA "no")
  956. endif()
  957. endif()
  958. # OAEP
  959. add_option("WOLFSSL_OAEP"
  960. "Enable RSA OAEP (default: enabled)"
  961. "yes" "yes;no")
  962. if(NOT WOLFSSL_OAEP)
  963. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_RSA_OAEP")
  964. endif()
  965. # TODO: - RSA public only
  966. # - RSA verify inline only
  967. # RSA-PSS
  968. add_option("WOLFSSL_RSA_PSS"
  969. "Enable RSA-PSS (default: disabled)"
  970. "no" "yes;no")
  971. if(NOT WOLFSSL_RSA)
  972. override_cache(WOLFSSL_RSA_PSS "no")
  973. else()
  974. if(WOLFSSL_TLS13)
  975. override_cache(WOLFSSL_RSA_PSS "yes")
  976. endif()
  977. endif()
  978. if(WOLFSSL_RSA_PSS)
  979. list(APPEND WOLFSSL_DEFINITIONS "-DWC_RSA_PSS")
  980. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_PSS_LONG_SALT")
  981. endif()
  982. # DH
  983. add_option("WOLFSSL_DH"
  984. "Enable DH (default: enabled)"
  985. "yes" "yes;no;const")
  986. if(WOLFSSL_OPENSSH)
  987. override_cache(WOLFSSL_DH "yes")
  988. endif()
  989. if(NOT WOLFSSL_DH)
  990. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DH")
  991. else()
  992. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  993. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DH")
  994. override_cache(WOLFSSL_DH "no")
  995. endif()
  996. endif()
  997. if("${WOLFSSL_DH}" STREQUAL "const")
  998. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_DH_CONST")
  999. set(WOLFSSL_DH_CONST "yes")
  1000. endif()
  1001. # TODO: - Anonymous
  1002. # ASN
  1003. # turn off asn, which means no certs, no rsa, no dsa, no ecc,
  1004. # and no big int (unless dh is on)
  1005. add_option("WOLFSSL_ASN"
  1006. "Enable ASN (default: enabled)"
  1007. "yes" "yes;no")
  1008. if(NOT WOLFSSL_ASN)
  1009. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ASN" "-DNO_CERTS")
  1010. if(NOT WOLFSSL_DH AND NOT WOLFSSL_ECC)
  1011. # DH and ECC need bigint
  1012. list(APPEND WOLFSSL_DEFINITIONS "-DNO_BIG_INT")
  1013. endif()
  1014. else()
  1015. # turn off ASN if leanpsk on
  1016. if(WOLFSSL_LEAN_PSK)
  1017. list(APPEND WOLFSSL_DEFINITIONS
  1018. "-DNO_ASN"
  1019. "-DNO_CERTS"
  1020. "-DNO_BIG_INT")
  1021. override_cache(WOLFSSL_ASN "no")
  1022. else()
  1023. if("${WOLFSSL_ASN}" STREQUAL "nocrypt")
  1024. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ASN_CRYPT")
  1025. # TODO: verify that this is correct
  1026. override_cache(WOLFSSL_PWDBASED "no")
  1027. endif()
  1028. endif()
  1029. endif()
  1030. if(WOLFSSL_RSA AND NOT WOLFSSL_RSA_VFY AND NOT WOLFSSL_ASN)
  1031. message(FATAL_ERROR "please disable rsa if disabling asn.")
  1032. endif()
  1033. if(WOLFSSL_DSA AND NOT WOLFSSL_ASN)
  1034. message(FATAL_ERROR "please disable dsa if disabling asn.")
  1035. endif()
  1036. # DH and ECC need bigint
  1037. if(NOT WOLFSSL_ASN AND
  1038. NOT WOLFSSL_DH AND
  1039. NOT WOLFSSL_ECC AND
  1040. NOT WOLFSSL_RSA)
  1041. override_cache(WOLFSSL_FAST_MATH "no")
  1042. set(WOLFSSL_SLOWMATH "no")
  1043. endif()
  1044. # AES
  1045. add_option("WOLFSSL_AES"
  1046. "Enable AES (default: enabled)"
  1047. "yes" "yes;no")
  1048. if(NOT WOLFSSL_AES)
  1049. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES")
  1050. if(WOLFSSL_FORTRESS)
  1051. message(FATAL_ERROR "fortress requires aes")
  1052. endif()
  1053. if(WOLFSSL_ECC_ENCRYPT)
  1054. message(FATAL_ERROR "cannot enable eccencrypt and hkdf without aes.")
  1055. endif()
  1056. if(WOLFSSL_AESGCM)
  1057. message(FATAL_ERROR "AESGCM requires AES.")
  1058. endif()
  1059. if(WOLFSSL_AESCCM)
  1060. message(FATAL_ERROR "AESCCM requires AES.")
  1061. endif()
  1062. if(WOLFSSL_AESCTR)
  1063. message(FATAL_ERROR "AESCTR requires AES.")
  1064. endif()
  1065. else()
  1066. if(WOLFSSL_LEAN_PSK)
  1067. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES")
  1068. override_cache(WOLFSSL_AES "no")
  1069. endif()
  1070. endif()
  1071. # Coding
  1072. add_option("WOLFSSL_CODING"
  1073. "Enable coding base 16/64 (default: enabled)"
  1074. "yes" "yes;no")
  1075. if(NOT WOLFSSL_CODING)
  1076. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CODING")
  1077. else()
  1078. # turn off CODING if leanpsk on
  1079. if(WOLFSSL_LEAN_PSK)
  1080. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CODING")
  1081. override_cache(WOLFSSL_CODING "no")
  1082. endif()
  1083. endif()
  1084. # Base64
  1085. set(BASE64_ENCODE_DEFAULT "no")
  1086. if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64|AMD64|arm64")
  1087. set(BASE64_ENCODE_DEFAULT "yes")
  1088. endif()
  1089. set(WOLFSSL_BASE64_ENCODE_HELP_STRING "Enable Base64 encoding (default: enabled on x86_64)")
  1090. add_option("WOLFSSL_BASE64_ENCODE" ${WOLFSSL_BASE64_ENCODE_HELP_STRING} ${BASE64_ENCODE_DEFAULT} "yes;no")
  1091. if(WOLFSSL_BASE64_ENCODE)
  1092. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_BASE64_ENCODE")
  1093. endif()
  1094. # TODO: - Base16
  1095. # DES3
  1096. set(WOLFSSL_DES3_HELP_STRING "Enable DES3 (default: disabled)")
  1097. add_option("WOLFSSL_DES3" ${WOLFSSL_DES3_HELP_STRING} "no" "yes;no")
  1098. if(WOLFSSL_OPENSSH OR
  1099. WOLFSSL_QT OR
  1100. WOLFSSL_OPENVPN OR
  1101. WOLFSSL_WPAS OR
  1102. WOLFSSL_ASIO)
  1103. override_cache(WOLFSSL_DES3 "yes")
  1104. endif()
  1105. # DES3 TLS Suites
  1106. set(WOLFSSL_DES3_TLS_SUITES_STRING "Enable DES3 TLS cipher suites (default: disabled)")
  1107. add_option("WOLFSSL_DES3_TLS_SUITES" ${WOLFSSL_DES3_TLS_SUITES_STRING} "no" "yes;no")
  1108. if(NOT WOLFSSL_DES3_TLS_SUITES)
  1109. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DES3_TLS_SUITES")
  1110. endif()
  1111. # ARC4
  1112. set(WOLFSSL_ARC4_HELP_STRING "Enable ARC4 (default: disabled)")
  1113. add_option("WOLFSSL_ARC4" ${WOLFSSL_ARC4_HELP_STRING} "no" "yes;no")
  1114. if(WOLFSSL_OPENSSH OR WOLFSSL_WPAS)
  1115. override_cache(WOLFSSL_ARC4 "yes")
  1116. endif()
  1117. # MD5
  1118. set(WOLFSSL_MD5_HELP_STRING "Enable MD5 (default: enabled)")
  1119. add_option("WOLFSSL_MD5" ${WOLFSSL_MD5_HELP_STRING} "yes" "yes;no")
  1120. if(NOT WOLFSSL_MD5)
  1121. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD5" "-DNO_OLD_TLS")
  1122. else()
  1123. # turn off MD5 if leanpsk or leantls on
  1124. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1125. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD5" "-DNO_OLD_TLS")
  1126. override_cache(WOLFSSL_MD5 "no")
  1127. endif()
  1128. endif()
  1129. # SHA
  1130. add_option("WOLFSSL_SHA"
  1131. "Enable SHA (default: enabled)"
  1132. "yes" "yes;no")
  1133. if(NOT WOLFSSL_SHA)
  1134. list(APPEND WOLFSSL_DEFINITIONS "-DNO_SHA" "-DNO_OLD_TLS")
  1135. else()
  1136. # turn off SHA if leanpsk or leantls on
  1137. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1138. list(APPEND WOLFSSL_DEFINITIONS "-DNO_SHA" "-DNO_OLD_TLS")
  1139. override_cache(WOLFSSL_SHA "no")
  1140. endif()
  1141. endif()
  1142. # TODO: - AES-XTS
  1143. # - Web server
  1144. # - Web client
  1145. add_option("WOLFSSL_CMAC"
  1146. "Enable CMAC (default: disabled)"
  1147. "no" "yes;no")
  1148. if(WOLFSSL_WPAS OR
  1149. WOLFSSL_NTP OR
  1150. WOLFSSL_AESSIV)
  1151. override_cache(WOLFSSL_CMAC "yes")
  1152. endif()
  1153. if(WOLFSSL_CMAC)
  1154. if (NOT WOLFSSL_AES)
  1155. message(FATAL_ERROR "Cannot use CMAC without AES.")
  1156. else()
  1157. list(APPEND WOLFSSL_DEFINITIONS
  1158. "-DWOLFSSL_CMAC"
  1159. "-DWOLFSSL_AES_DIRECT")
  1160. endif()
  1161. endif()
  1162. # TODO: - RC2
  1163. # - FIPS, again (there's more logic for FIPS in configure.ac)
  1164. # - Selftest
  1165. # SHA224
  1166. if(WOLFSSL_SHA224)
  1167. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA224")
  1168. endif()
  1169. # SHA3
  1170. if("${WOLFSSL_SHA3}" STREQUAL "small")
  1171. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA3_SMALL")
  1172. override_cache(WOLFSSL_SHA3 "yes")
  1173. endif()
  1174. if(WOLFSSL_SHA3 AND NOT WOLFSSL_32BIT)
  1175. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA3")
  1176. endif()
  1177. # SHAKE256
  1178. if(WOLFSSL_SHAKE256)
  1179. if(NOT WOLFSSL_32BIT)
  1180. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHAKE256")
  1181. if(NOT WOLFSSL_SHA3)
  1182. message(FATAL_ERROR "Must have SHA-3 enabled: --enable-sha3")
  1183. endif()
  1184. endif()
  1185. else()
  1186. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_NO_SHAKE256")
  1187. endif()
  1188. # SHAKE128
  1189. if(WOLFSSL_SHAKE128)
  1190. if(NOT WOLFSSL_32BIT)
  1191. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHAKE128")
  1192. if(NOT WOLFSSL_SHA3)
  1193. message(FATAL_ERROR "Must have SHA-3 enabled: --enable-sha3")
  1194. endif()
  1195. endif()
  1196. else()
  1197. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_NO_SHAKE128")
  1198. endif()
  1199. # POLY1305
  1200. set(POLY1305_DEFAULT "yes")
  1201. if(WOLFSSL_FIPS)
  1202. set(POLY1305_DEFAULT "no")
  1203. endif()
  1204. set(WOLFSSL_POLY1305_HELP_STRING "Enable wolfSSL POLY1305 support (default: enabled)")
  1205. add_option("WOLFSSL_POLY1305" ${WOLFSSL_POLY1305_HELP_STRING} ${POLY1305_DEFAULT} "yes;no")
  1206. # leanpsk and leantls don't need poly1305
  1207. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1208. override_cache(WOLFSSL_POLY1305 "no")
  1209. endif()
  1210. if(WOLFSSL_POLY1305)
  1211. list(APPEND WOLFSSL_DEFINITIONS
  1212. "-DHAVE_POLY1305"
  1213. "-DHAVE_ONE_TIME_AUTH")
  1214. endif()
  1215. # CHACHA
  1216. set(CHACHA_DEFAULT "yes")
  1217. if(WOLFSSL_FIPS)
  1218. set(CHACHA_DEFAULT "no")
  1219. endif()
  1220. add_option("WOLFSSL_CHACHA"
  1221. "Enable CHACHA (default: enabled). Use `=noasm` to disable ASM AVX/AVX2 speedups"
  1222. ${CHACHA_DEFAULT} "yes;no;noasm")
  1223. # leanpsk and leantls don't need chacha
  1224. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1225. override_cache(WOLFSSL_CHACHA "no")
  1226. endif()
  1227. if(("${WOLFSSL_CHACHA}" STREQUAL "noasm") OR NOT WOLFSSL_ASM)
  1228. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CHACHA_ASM")
  1229. endif()
  1230. if(NOT ("${WOLFSSL_CHACHA}" STREQUAL "noasm") AND WOLFSSL_CHACHA)
  1231. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CHACHA")
  1232. endif()
  1233. # TODO: - XCHACHA
  1234. # Hash DRBG
  1235. add_option("WOLFSSL_HASH_DRBG"
  1236. "Enable Hash DRBG support (default: enabled)"
  1237. "yes" "yes;no")
  1238. if(WOLFSSL_HASH_DRBG)
  1239. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HASHDRBG")
  1240. else()
  1241. # turn on Hash DRBG if FIPS is on
  1242. if(WOLFSSL_FIPS)
  1243. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HASHDRBG")
  1244. override_cache(WOLFSSL_HASH_DRBG "yes")
  1245. else()
  1246. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_HASHDRBG")
  1247. endif()
  1248. endif()
  1249. # Filesystem
  1250. if(WOLFSSL_LINUX_KM)
  1251. set(FILESYSTEM_DEFAULT "no")
  1252. else()
  1253. set(FILESYSTEM_DEFAULT "yes")
  1254. endif()
  1255. add_option("WOLFSSL_FILESYSTEM"
  1256. "Enable Filesystem support (default: enabled)"
  1257. ${FILESYSTEM_DEFAULT} "yes;no")
  1258. if(NOT WOLFSSL_FILESYSTEM)
  1259. list(APPEND WOLFSSL_DEFINITIONS "-DNO_FILESYSTEM")
  1260. else()
  1261. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1262. list(APPEND WOLFSSL_DEFINITIONS "-DNO_FILESYSTEM")
  1263. override_cache(WOLFSSL_FILESYSTEM "no")
  1264. endif()
  1265. endif()
  1266. # Inline function support
  1267. add_option("WOLFSSL_INLINE"
  1268. "Enable inline functions (default: enabled)"
  1269. "yes" "yes;no")
  1270. if(NOT WOLFSSL_INLINE)
  1271. list(APPEND WOLFSSL_DEFINITIONS "-DNO_INLINE")
  1272. endif()
  1273. # TODO:
  1274. # - CRL monitor
  1275. # - User crypto
  1276. # - Whitewood netRandom client library
  1277. # - Max fragment length
  1278. # - ALPN
  1279. # - Trusted CA indication
  1280. # - Truncated HMAC
  1281. # - Renegotiation indication
  1282. # - Secure renegotiation
  1283. # - Fallback SCSV
  1284. add_option(WOLFSSL_OCSP "Enable OCSP (default: disabled)" "no" "yes;no")
  1285. add_option(WOLFSSL_OCSPSTAPLING "Enable OCSP Stapling (default: disabled)" "no" "yes;no")
  1286. add_option(WOLFSSL_OCSPSTAPLING_V2 "Enable OCSP Stapling v2 (default: disabled)" "no" "yes;no")
  1287. add_option(WOLFSSL_CRL
  1288. "Enable CRL (Use =io for inline CRL HTTP GET) (default: disabled)"
  1289. "no" "yes;no;io")
  1290. set(SNI_DEFAULT "no")
  1291. if(("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64|x86|AMD64|arm64") OR
  1292. ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
  1293. set(SNI_DEFAULT "yes")
  1294. endif()
  1295. set(WOLFSSL_SNI_HELP_STRING "Enable SNI (default: disabled)")
  1296. add_option(WOLFSSL_SNI ${WOLFSSL_SNI_HELP_STRING} ${SNI_DEFAULT} "yes;no")
  1297. set(WOLFSSL_TLSX_HELP_STRING "Enable all TLS Extensions (default: disabled)")
  1298. add_option(WOLFSSL_TLSX ${WOLFSSL_TLSX_HELP_STRING} "no" "yes;no")
  1299. add_option(WOLFSSL_EX_DATA
  1300. "Enable app data (default: disabled)"
  1301. "no" "yes;no")
  1302. if (WOLFSSL_EX_DATA)
  1303. list(APPEND WOLFSSL_DEFINITIONS
  1304. "-DHAVE_EX_DATA")
  1305. endif()
  1306. # Supported elliptic curves extensions
  1307. add_option("WOLFSSL_SUPPORTED_CURVES"
  1308. "Enable Supported Elliptic Curves (default: enabled)"
  1309. "yes" "yes;no")
  1310. if(WOLFSSL_SUPPORTED_CURVES)
  1311. if(NOT WOLFSSL_ECC AND NOT WOLFSSL_CURVE25519 AND NOT WOLFSSL_CURVE448)
  1312. override_cache(WOLFSSL_SUPPORTED_CURVES "no")
  1313. else()
  1314. list(APPEND WOLFSSL_DEFINITIONS
  1315. "-DHAVE_TLS_EXTENSIONS"
  1316. "-DHAVE_SUPPORTED_CURVES")
  1317. endif()
  1318. endif()
  1319. # Diffie-Hellman
  1320. if(WOLFSSL_DH)
  1321. if(WOLFSSL_TLS13 OR WOLFSSL_SUPPORTED_CURVES)
  1322. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_FFDHE_2048")
  1323. endif()
  1324. endif()
  1325. # TODO: - FFDHE params only
  1326. # TLS 1.3 Requires either ECC or (RSA/DH), or CURVE25519/ED25519 or CURVE448/ED448
  1327. if (NOT WOLFSSL_ECC AND
  1328. (NOT WOLFSSL_RSA OR NOT WOLFSSL_DH) AND
  1329. (NOT WOLFSSL_CURVE25519 OR NOT WOLFSSL_ED25519) AND
  1330. (NOT WOLFSSL_CURVE448 AND NOT WOLFSSL_ED448))
  1331. override_cache(WOLFSSL_TLS13 "no")
  1332. endif()
  1333. if (WOLFSSL_TLS13)
  1334. list(APPEND WOLFSSL_DEFINITIONS
  1335. "-DHAVE_SUPPORTED_CURVES"
  1336. "-DWOLFSSL_TLS13"
  1337. "-DHAVE_TLS_EXTENSIONS"
  1338. )
  1339. endif()
  1340. # Session Ticket Extension
  1341. add_option("WOLFSSL_SESSION_TICKET"
  1342. "Enable Session Ticket (default: disabled)"
  1343. "no" "yes;no")
  1344. if(WOLFSSL_NGINX OR WOLFSSL_WPAS OR WOLFSSL_HAPROXY OR WOLFSSL_LIGHTY)
  1345. override_cache(WOLFSSL_SESSION_TICKET "yes")
  1346. endif()
  1347. if(WOLFSSL_SESSION_TICKET)
  1348. list(APPEND WOLFSSL_DEFINITIONS
  1349. "-DHAVE_TLS_EXTENSIONS"
  1350. "-DHAVE_SESSION_TICKET")
  1351. endif()
  1352. add_option("WOLFSSL_TICKET_NONCE_MALLOC"
  1353. "Enable dynamic allocation of ticket nonces (default: disabled)"
  1354. "no" "yes;no")
  1355. if(WOLFSSL_TICKET_NONCE_MALLOC)
  1356. list(APPEND WOLFSSL_DEFINITIONS
  1357. "-DWOLFSSL_TICKET_NONCE_MALLOC")
  1358. endif()
  1359. # Extended master secret extension
  1360. add_option("WOLFSSL_EXTENDED_MASTER"
  1361. "Enable Extended Master Secret (default: enabled)"
  1362. "yes" "yes;no")
  1363. if(WOLFSSL_EXTENDED_MASTER)
  1364. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_EXTENDED_MASTER")
  1365. endif()
  1366. if(NOT WOLFSSL_ARC4)
  1367. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RC4")
  1368. else()
  1369. # turn off ARC4 if leanpsk or leantls on
  1370. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1371. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RC4")
  1372. override_cache(WOLFSSL_ARC4 "no")
  1373. endif()
  1374. endif()
  1375. # TODO: - TLS extensions
  1376. # - Early data handshake
  1377. # - SCEP
  1378. # - Secure remote password
  1379. # - Indefinite length encoded messages
  1380. # - Small stack cache
  1381. # - Small stack
  1382. # - Valgrind
  1383. # - Test certs
  1384. # - I/O pool example
  1385. # - Certificate service
  1386. # - wolfSSL JNI
  1387. # - lighttpd/lighty
  1388. # - Asio
  1389. # - Apache HTTPD
  1390. set(WOLFSSL_PKCS7_HELP_STRING "Enable PKCS7 (default: disabled)")
  1391. add_option(WOLFSSL_PKCS7 ${WOLFSSL_PKCS7_HELP_STRING} "no" "yes;no")
  1392. set(WOLFSSL_TPM_HELP_STRING "Enable wolfTPM options (default: disabled)")
  1393. add_option(WOLFSSL_TPM ${WOLFSSL_TPM_HELP_STRING} "no" "yes;no")
  1394. set(WOLFSSL_AESKEYWRAP_HELP_STRING "Enable AES key wrap support (default: disabled)")
  1395. add_option(WOLFSSL_AESKEYWRAP ${WOLFSSL_AESKEYWRAP_HELP_STRING} "no" "yes;no")
  1396. set(WOLFSSL_X963KDF_HELP_STRING "Enable X9.63 KDF support (default: disabled)")
  1397. add_option(WOLFSSL_X963KDF ${WOLFSSL_X963KDF_HELP_STRING} "no" "yes;no")
  1398. # Encrypt-then-mac
  1399. add_option("WOLFSSL_ENC_THEN_MAC"
  1400. "Enable Encryptr-Then-Mac extension (default: enabled)"
  1401. "yes" "yes;no")
  1402. if(WOLFSSL_APACHE_HTTPD)
  1403. override_cache(WOLFSSL_ENC_THEN_MAC "no")
  1404. endif()
  1405. if(WOLFSSL_TLSX)
  1406. override_cache(WOLFSSL_ENC_THEN_MAC "yes")
  1407. endif()
  1408. if(WOLFSSL_SNIFFER)
  1409. override_cache(WOLFSSL_ENC_THEN_MAC "no")
  1410. endif()
  1411. # stunnel Support
  1412. # TODO: rest of stunnel support
  1413. add_option("WOLFSSL_STUNNEL"
  1414. "Enable stunnel (default: disabled)"
  1415. "no" "yes;no")
  1416. if(WOLFSSL_ENC_THEN_MAC)
  1417. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ENCRYPT_THEN_MAC")
  1418. endif()
  1419. if(NOT WOLFSSL_PSK AND
  1420. NOT WOLFSSL_LEAN_PSK AND
  1421. NOT WOLFSSL_STUNNEL)
  1422. list(APPEND WOLFSSL_DEFINITIONS "-DNO_PSK")
  1423. endif()
  1424. # MD4
  1425. set(WOLFSSL_MD4_HELP_STRING "Enable MD4 (default: disabled)")
  1426. add_option("WOLFSSL_MD4" ${WOLFSSL_MD4_HELP_STRING} "no" "yes;no")
  1427. if(NOT WOLFSSL_MD4)
  1428. # turn on MD4 if using stunnel
  1429. if(WOLFSSL_STUNNEL OR WOLFSSL_WPAS)
  1430. override_cache(WOLFSSL_MD4 "yes")
  1431. else()
  1432. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD4")
  1433. endif()
  1434. endif()
  1435. # Encrypted keys
  1436. add_option("WOLFSSL_ENCKEYS"
  1437. "Enable PEM encrypted key support (default: disabled)"
  1438. "no" "yes;no")
  1439. if(NOT WOLFSSL_ENCKEYS)
  1440. if(WOLFSSL_OPENSSLEXTRA OR
  1441. WOLFSSL_WEBSERVER OR
  1442. WOLFSSL_WPAS)
  1443. # opensslextra, webserver, and WPAS needs enckeys
  1444. override_cache(WOLFSSL_ENCKEYS "yes")
  1445. endif()
  1446. endif()
  1447. if(WOLFSSL_ENCKEYS)
  1448. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_ENCRYPTED_KEYS")
  1449. endif()
  1450. # PKCS#12
  1451. set(WOLFSSL_PKCS12_HELP_STRING "Enable pkcs12 (default: enabled)")
  1452. add_option("WOLFSSL_PKCS12" ${WOLFSSL_PKCS12_HELP_STRING} "yes" "yes;no")
  1453. if(NOT WOLFSSL_ASN)
  1454. override_cache(WOLFSSL_PKCS12 "no")
  1455. endif()
  1456. if(NOT WOLFSSL_PKCS12)
  1457. list(APPEND WOLFSSL_DEFINITIONS "-DNO_PKCS12")
  1458. endif()
  1459. # PWDBASED has to come after certservice since we want it on w/o explicit on
  1460. # PWDBASED
  1461. add_option("WOLFSSL_PWDBASED"
  1462. "Enable PWDBASED (default: disabled)"
  1463. "no" "yes;no")
  1464. if(NOT WOLFSSL_PWDBASED)
  1465. if(WOLFSSL_OPENSSLEXTRA OR
  1466. WOLFSSL_OPENSSLALL OR
  1467. WOLFSSL_WEBSERVER OR
  1468. WOLFSSL_ENC_KEYS OR
  1469. WOLFSSL_PKCS12)
  1470. # opensslextra, opensslall, webserver, and enckeys needs pwdbased
  1471. override_cache(WOLFSSL_PWDBASED "yes")
  1472. else()
  1473. list(APPEND WOLFSSL_DEFINITIONS "-DNO_PWDBASED")
  1474. endif()
  1475. endif()
  1476. # TODO: - SCRYPT
  1477. # - wolfCrypt only
  1478. # fastmath
  1479. add_option("WOLFSSL_FAST_MATH"
  1480. "Enable fast math ops (default: disabled)"
  1481. "no" "yes;no")
  1482. if(WOLFSSL_FAST_MATH)
  1483. # turn off fastmath if leanpsk on or asn off (w/o DH and ECC)
  1484. if(WOLFSSL_LEAN_PSK OR NOT WOLFSSL_ASN)
  1485. if(NOT WOLFSSL_DH AND
  1486. NOT WOLFSSL_ECC AND
  1487. NOT WOLFSSL_RSA)
  1488. override_cache(WOLFSSL_FAST_MATH "no")
  1489. else()
  1490. list(APPEND WOLFSSL_DEFINITIONS "-DUSE_FAST_MATH")
  1491. set(WOLFSSL_SLOWMATH "no")
  1492. endif()
  1493. else()
  1494. list(APPEND WOLFSSL_DEFINITIONS "-DUSE_FAST_MATH")
  1495. set(WOLFSSL_SLOWMATH "no")
  1496. endif()
  1497. endif()
  1498. # TODO: - Fast huge math
  1499. # Set processor-specific build macros
  1500. if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64|AMD64")
  1501. set(WOLFSSL_X86_64_BUILD ON)
  1502. add_option("WOLFSSL_X86_64_BUILD_ASM" "Build ASM files" "yes" "yes;no")
  1503. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_X86_64_BUILD")
  1504. elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "aarch64|arm64")
  1505. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_AARCH64_BUILD")
  1506. endif()
  1507. # SP math all
  1508. add_option("WOLFSSL_SP_MATH_ALL"
  1509. "Enable Single Precision math implementation for full algorithm suite (default: enabled)"
  1510. "yes" "yes;no")
  1511. # Enable examples, used to disable examples
  1512. if(WOLFSSL_LINUX_KM)
  1513. set(EXAMPLES_DEFAULT "no")
  1514. else()
  1515. set(EXAMPLES_DEFAULT "yes")
  1516. endif()
  1517. add_option("WOLFSSL_EXAMPLES"
  1518. "Enable examples (default: enabled)"
  1519. ${EXAMPLES_DEFAULT} "yes;no")
  1520. if(NOT WOLFSSL_FILESYSTEM OR
  1521. NOT WOLFSSL_INLINE OR
  1522. WOLFSSL_CRYPT_ONLY)
  1523. override_cache(WOLFSSL_EXAMPLES "no")
  1524. endif()
  1525. # Enable wolfCrypt test and benchmark
  1526. if(WOLFSSL_LINUX_KM)
  1527. set(CRYPT_TESTS_DEFAULT "no")
  1528. else()
  1529. set(CRYPT_TESTS_DEFAULT "yes")
  1530. endif()
  1531. add_option("WOLFSSL_CRYPT_TESTS"
  1532. "Enable Crypt Bench/Test (default: enabled)"
  1533. ${CRYPT_TESTS_DEFAULT} "yes;no")
  1534. add_option("WOLFSSL_CRYPT_TESTS_LIBS"
  1535. "Build static libraries from the wolfCrypt test and benchmark sources (default: disabled)"
  1536. "no" "yes;no")
  1537. add_option("WOLFSSL_CRYPT_TESTS_HELP"
  1538. "Add help text to wolfCrypt test (default: disabled)"
  1539. "no" "yes;no")
  1540. # TODO: - LIBZ
  1541. # - PKCS#11
  1542. # - Cavium
  1543. # - Cavium V
  1544. # - Cavium Octeon
  1545. # - Intel QuickAssist
  1546. # - SP ASM (and other SP logic)
  1547. # - Fast RSA
  1548. # - Static memory use
  1549. # - Microchip API
  1550. # - Asynchronous crypto
  1551. # Asynchronous threading
  1552. add_option("WOLFSSL_ASYNC_THREADS"
  1553. "Enable Asynchronous Threading (default: enabled)"
  1554. "yes" "yes;no")
  1555. if(WOLFSSL_ASYNC_CRYPT AND WOLFSSL_ASYNC_THREADS)
  1556. if(CMAKE_USE_PTHREADS_INIT)
  1557. override_cache(WOLFSSL_ASYNC_THREADS "yes")
  1558. else()
  1559. override_cache(WOLFSSL_ASYNC_THREADS "no")
  1560. endif()
  1561. else()
  1562. override_cache(WOLFSSL_ASYNC_THREADS "no")
  1563. endif()
  1564. if(WOLFSSL_ASYNC_THREADS)
  1565. list(APPEND WOLFSSL_LINK_LIBS Threads::Threads)
  1566. list(APPEND WOLFSSL_DEFINITIONS "-D_GNU_SOURCE")
  1567. else()
  1568. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_ASYNC_THREADING")
  1569. endif()
  1570. # TODO: - Session export
  1571. add_option("WOLFSSL_CRYPTOCB"
  1572. "Enable crypto callbacks (default: disabled)"
  1573. "no" "yes;no")
  1574. add_option("WOLFSSL_CRYPTOCB_NO_SW_TEST"
  1575. "Disable crypto callback SW testing (default: disabled)"
  1576. "no" "yes;no")
  1577. add_option("WOLFSSL_PKCALLBACKS"
  1578. "Enable public key callbacks (default: disabled)"
  1579. "no" "yes;no")
  1580. add_option("WOLFSSL_OLD_NAMES"
  1581. "Keep backwards compat with old names (default: enabled)"
  1582. "yes" "yes;no")
  1583. if(NOT WOLFSSL_OLD_NAMES AND NOT WOLFSSL_OPENSSL_COEXIST)
  1584. list(APPEND WOLFSSL_DEFINITIONS
  1585. "-DNO_OLD_RNGNAME"
  1586. "-DNO_OLD_WC_NAMES"
  1587. "-DNO_OLD_SSL_NAMES"
  1588. "-DNO_OLD_SHA_NAMES")
  1589. endif()
  1590. # TODO: - Memory tests
  1591. # - Hash flags
  1592. # Support for enabling setting default DH parameters
  1593. add_option("WOLFSSL_DH_DEFAULT_PARAMS"
  1594. "Enables option for default dh parameters (default: disabled)"
  1595. "no" "yes;no")
  1596. if(WOLFSSL_DH_DEFAULT_PARAMS OR NOT WOLFSSL_QT)
  1597. override_cache(WOLFSSL_DH_DEFAULT_PARAMS "yes")
  1598. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_DH_DEFAULT_PARAMS")
  1599. endif()
  1600. if(NOT WOLFSSL_DES3)
  1601. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DES3")
  1602. else()
  1603. # turn off DES3 if leanpsk or leantls on
  1604. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1605. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DES3")
  1606. override_cache(WOLFSSL_DES3 "no")
  1607. endif()
  1608. endif()
  1609. add_option("WOLFSSL_USER_SETTINGS"
  1610. "Use your own user_settings.h and do not add Makefile CFLAGS (default: disabled)"
  1611. "no" "yes;no")
  1612. add_option("WOLFSSL_USER_SETTINGS_ASM"
  1613. "Enable use of user_settings_asm.h in assembly files (default: disabled)"
  1614. "no" "yes;no")
  1615. add_option("WOLFSSL_OPTFLAGS"
  1616. "Enable default optimization CFLAGS for the compiler (default: enabled)"
  1617. "yes" "yes;no")
  1618. add_option("WOLFSSL_SYS_CA_CERTS"
  1619. "Enable ability to load CA certs from OS (default: enabled)"
  1620. "yes" "yes;no")
  1621. if(WOLFSSL_SYS_CA_CERTS)
  1622. if(NOT WOLFSSL_FILESYSTEM)
  1623. message("Can't enable system CA certs without a filesystem.")
  1624. override_cache(WOLFSSL_SYS_CA_CERTS "no")
  1625. elseif(APPLE)
  1626. # Headers used for MacOS default system CA certs behavior. Only MacOS SDK will have this header
  1627. check_include_file("Security/SecTrustSettings.h" HAVE_SECURITY_SECTRUSTSETTINGS_H)
  1628. # Headers used for Apple native cert validation. All device SDKs should have these headers
  1629. check_include_file("Security/SecCertificate.h" HAVE_SECURITY_SECCERTIFICATE_H)
  1630. check_include_file("Security/SecTrust.h" HAVE_SECURITY_SECTRUST_H)
  1631. check_include_file("Security/SecPolicy.h" HAVE_SECURITY_SECPOLICY_H)
  1632. # Either Security/SecTrustSettings (for MacOS cert loading), or the
  1633. # trio of Security/SecCertificate.h, Security/SecTrust.h, and
  1634. # Security/SecPolicy.h (for native trust APIs on other apple devices)
  1635. # must be present. Default to SecTrustSettings method on MacOS.
  1636. if(HAVE_SECURITY_SECTRUSTSETTINGS_H OR (HAVE_SECURITY_SECCERTIFICATE_H
  1637. AND HAVE_SECURITY_SECTRUST_H
  1638. AND HAVE_SECURITY_SECPOLICY_H))
  1639. find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation)
  1640. if(NOT CORE_FOUNDATION_FRAMEWORK)
  1641. message(FATAL_ERROR "Can't enable system CA certs without CoreFoundation framework.")
  1642. else()
  1643. find_library(SECURITY_FRAMEWORK Security)
  1644. if(NOT SECURITY_FRAMEWORK)
  1645. message(FATAL_ERROR "Can't enable system CA certs without Security framework.")
  1646. endif()
  1647. endif()
  1648. # MacOS should not use native cert validation by default, but other apple devices should.
  1649. if(NOT HAVE_SECURITY_SECTRUSTSETTINGS_H AND HAVE_SECURITY_SECCERTIFICATE_H
  1650. AND HAVE_SECURITY_SECTRUST_H
  1651. AND HAVE_SECURITY_SECPOLICY_H)
  1652. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_APPLE_NATIVE_CERT_VALIDATION")
  1653. endif()
  1654. else()
  1655. message(FATAL_ERROR "Can't enable system CA certs without Apple Security.framework headers.")
  1656. endif()
  1657. endif()
  1658. if(WOLFSSL_SYS_CA_CERTS)
  1659. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SYS_CA_CERTS")
  1660. endif()
  1661. endif()
  1662. # FLAGS operations
  1663. if(WOLFSSL_AESCCM)
  1664. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_AESCCM")
  1665. endif()
  1666. if(WOLFSSL_AESOFB)
  1667. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_AES_OFB" "-DWOLFSSL_AES_DIRECT")
  1668. endif()
  1669. if(WOLFSSL_TPM)
  1670. override_cache(WOLFSSL_KEYGEN "yes")
  1671. override_cache(WOLFSSL_CERTGEN "yes")
  1672. override_cache(WOLFSSL_CRYPTOCB "yes")
  1673. override_cache(WOLFSSL_CERTREQ "yes")
  1674. override_cache(WOLFSSL_CERTEXT "yes")
  1675. override_cache(WOLFSSL_PKCS7 "yes")
  1676. override_cache(WOLFSSL_AESCFB "yes")
  1677. endif()
  1678. if(WOLFSSL_AESCFB)
  1679. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_AES_CFB")
  1680. endif()
  1681. if(WOLFSSL_PKCS7)
  1682. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_PKCS7")
  1683. override_cache(WOLFSSL_AESKEYWRAP "yes")
  1684. # Enable prereqs if not already enabled
  1685. if(WOLFSSL_ECC)
  1686. override_cache(WOLFSSL_X963KDF "yes")
  1687. endif()
  1688. endif()
  1689. if(WOLFSSL_X963KDF)
  1690. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_X963_KDF")
  1691. endif()
  1692. if(WOLFSSL_AESKEYWRAP)
  1693. list(APPEND WOLFSSL_DEFINITIONS
  1694. "-DHAVE_AES_KEYWRAP"
  1695. "-DWOLFSSL_AES_DIRECT"
  1696. )
  1697. endif()
  1698. # Hybrid Public Key Encryption (RFC9180)
  1699. add_option("WOLFSSL_HPKE"
  1700. "Enable wolfSSL hybrid public key encryption (default: disabled)"
  1701. "no" "yes;no")
  1702. # Encrypted Client Hello (ECH)
  1703. add_option("WOLFSSL_ECH"
  1704. "Enable wolfSSL encrypted client hello (default: disabled)"
  1705. "no" "yes;no")
  1706. # Keying Material Exporter / TLS Exporter
  1707. add_option("WOLFSSL_KEYING_MATERIAL"
  1708. "Enable wolfSSL keying material export (default: disabled)"
  1709. "no" "yes;no")
  1710. if(WOLFSSL_HPKE)
  1711. if(NOT WOLFSSL_ECC)
  1712. message(FATAL_ERROR "HPKE supported only with ECC (WOLFSSL_ECC)")
  1713. endif()
  1714. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HPKE")
  1715. override_cache(WOLFSSL_HKDF "yes")
  1716. endif()
  1717. if(WOLFSSL_ECH)
  1718. if(NOT WOLFSSL_HPKE)
  1719. message(FATAL_ERROR "ECH supported only with HPKE (WOLFSSL_HPKE)")
  1720. endif()
  1721. if(NOT WOLFSSL_SNI)
  1722. message(FATAL_ERROR "ECH supported only with SNI (WOLFSSL_SNI)")
  1723. endif()
  1724. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ECH")
  1725. endif()
  1726. if(WOLFSSL_KEYING_MATERIAL)
  1727. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_KEYING_MATERIAL")
  1728. endif()
  1729. if(WOLFSSL_KEYGEN)
  1730. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_KEY_GEN")
  1731. endif()
  1732. if(WOLFSSL_CERTGEN)
  1733. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CERT_GEN")
  1734. endif()
  1735. if(WOLFSSL_CERTREQ)
  1736. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CERT_REQ")
  1737. endif()
  1738. if(WOLFSSL_CERTEXT)
  1739. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CERT_EXT")
  1740. endif()
  1741. if(WOLFSSL_CERTGENCACHE)
  1742. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CERT_GEN_CACHE")
  1743. endif()
  1744. if(WOLFSSL_CRYPTOCB)
  1745. list(APPEND WOLFSSL_DEFINITIONS "-DWOLF_CRYPTO_CB")
  1746. endif()
  1747. if(WOLFSSL_CRYPTOCB_NO_SW_TEST)
  1748. list(APPEND WOLFSSL_DEFINITIONS "-DWC_TEST_NO_CRYPTOCB_SW_TEST")
  1749. endif()
  1750. # Public Key Callbacks
  1751. if(WOLFSSL_PKCALLBACKS)
  1752. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_PK_CALLBACKS")
  1753. endif()
  1754. if(WOLFSSL_OCSPSTAPLING)
  1755. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CERTIFICATE_STATUS_REQUEST" "-DHAVE_TLS_EXTENSIONS")
  1756. override_cache(WOLFSSL_OCSP "yes")
  1757. endif()
  1758. if(WOLFSSL_OCSPSTAPLING_V2)
  1759. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CERTIFICATE_STATUS_REQUEST_V2" "-DHAVE_TLS_EXTENSIONS")
  1760. override_cache(WOLFSSL_OCSP "yes")
  1761. endif()
  1762. # must be below OCSP stapling options to allow override
  1763. if (WOLFSSL_OCSP)
  1764. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_OCSP")
  1765. endif()
  1766. if (WOLFSSL_CRL STREQUAL "yes")
  1767. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CRL")
  1768. elseif(WOLFSSL_CRL STREQUAL "io")
  1769. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CRL" "-DHAVE_CRL_IO")
  1770. endif()
  1771. if (WOLFSSL_SNI)
  1772. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_TLS_EXTENSIONS" "-DHAVE_SNI")
  1773. endif()
  1774. if (WOLFSSL_TLSX)
  1775. list(APPEND WOLFSSL_DEFINITIONS
  1776. "-DHAVE_TLS_EXTENSIONS"
  1777. "-DHAVE_SNI"
  1778. "-DHAVE_MAX_FRAGMENT"
  1779. "-DHAVE_TRUNCATED_HMAC"
  1780. "-DHAVE_ALPN"
  1781. "-DHAVE_TRUSTED_CA")
  1782. if (WOLFSSL_ECC OR WOLFSSL_CURVE25519 OR WOLFSSL_CURVE448 OR WOLFSSL_TLS13)
  1783. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_SUPPORTED_CURVES")
  1784. endif()
  1785. endif()
  1786. add_option("WOLFSSL_CAAM"
  1787. "Enable use of CAAM with NXP (default: disabled)"
  1788. "no" "yes;no")
  1789. if (WOLFSSL_CAAM)
  1790. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CAAM")
  1791. endif()
  1792. if (WOLFSSL_ARIA)
  1793. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ARIA")
  1794. endif()
  1795. # Generates the BUILD_* flags. These control what source files are included in
  1796. # the library. A series of AM_CONDITIONALs handle this in configure.ac.
  1797. generate_build_flags()
  1798. # TODO: - Bit of logic after optimization flags option (above)
  1799. # - Check for build-type conflicts section
  1800. # USER SETTINGS
  1801. if(WOLFSSL_USER_SETTINGS)
  1802. # Replace all options and just use WOLFSSL_USER_SETTINGS
  1803. set(WOLFSSL_DEFINITIONS "-DWOLFSSL_USER_SETTINGS")
  1804. endif()
  1805. if(WOLFSSL_USER_SETTINGS_ASM)
  1806. if(WOLFSSL_USER_SETTINGS)
  1807. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_USER_SETTINGS_ASM")
  1808. # Create user_settings_asm.h for use in assembly files (e.g. .S files).
  1809. if(WIN32)
  1810. execute_process(COMMAND
  1811. $ENV{SHELL} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/user_settings_asm.sh
  1812. "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}"
  1813. RESULT_VARIABLE USER_SETTINGS_ASM_RET)
  1814. else()
  1815. execute_process(COMMAND
  1816. ${CMAKE_CURRENT_SOURCE_DIR}/scripts/user_settings_asm.sh
  1817. "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}"
  1818. RESULT_VARIABLE USER_SETTINGS_ASM_RET)
  1819. endif()
  1820. if (NOT USER_SETTINGS_ASM_RET EQUAL 0)
  1821. message(FATAL_ERROR
  1822. "${CMAKE_CURRENT_SOURCE_DIR}/scripts/user_settings_asm.sh failed.")
  1823. endif()
  1824. else()
  1825. message(FATAL_ERROR
  1826. "Must have WOLFSSL_USER_SETTINGS to enable WOLFSSL_USER_SETTINGS_ASM.")
  1827. endif()
  1828. endif()
  1829. add_option("WOLFSSL_CONFIG_H"
  1830. "Enable generation of config.h and define HAVE_CONFIG_H (default: enabled)"
  1831. "yes" "yes;no")
  1832. if(WOLFSSL_CONFIG_H)
  1833. add_definitions("-DHAVE_CONFIG_H")
  1834. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.in"
  1835. "${CMAKE_CURRENT_BINARY_DIR}/config.h" )
  1836. set(abs_top_srcdir ${CMAKE_CURRENT_SOURCE_DIR})
  1837. set(abs_top_builddir ${CMAKE_CURRENT_BINARY_DIR})
  1838. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test_paths.h.in"
  1839. "${CMAKE_CURRENT_BINARY_DIR}/wolfcrypt/test/test_paths.h" )
  1840. endif()
  1841. # If config.h or wolfssl/options.h exists, delete it to avoid
  1842. # a mixup with build/wolfssl/options.h.
  1843. if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h")
  1844. file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h")
  1845. endif()
  1846. if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/config.h")
  1847. file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/config.h")
  1848. endif()
  1849. # Suppress some warnings about separate compilation, inlining
  1850. add_definitions("-DWOLFSSL_IGNORE_FILE_WARN")
  1851. # Generate user options header
  1852. message(STATUS "Generating user options header...")
  1853. if (${CMAKE_DISABLE_SOURCE_CHANGES})
  1854. set(WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT "${CMAKE_DISABLE_SOURCE_CHANGES}")
  1855. else()
  1856. set(WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT "yes")
  1857. endif()
  1858. add_option("WOLFSSL_BUILD_OUT_OF_TREE"
  1859. "Don't generate files in the source tree (default: ${WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT})"
  1860. "${WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT}" "yes;no")
  1861. if (${WOLFSSL_BUILD_OUT_OF_TREE})
  1862. set(WOLFSSL_OUTPUT_BASE ${CMAKE_CURRENT_BINARY_DIR})
  1863. else()
  1864. set(WOLFSSL_OUTPUT_BASE ${CMAKE_CURRENT_SOURCE_DIR})
  1865. endif()
  1866. set(OPTION_FILE "${WOLFSSL_OUTPUT_BASE}/wolfssl/options.h")
  1867. # sccache
  1868. add_option("ENABLE_SCCACHE"
  1869. "Enable sccache (default: disabled)"
  1870. "no" "yes;no")
  1871. if (ENABLE_SCCACHE AND (NOT WOLFSSL_SCCACHE_ALREADY_SET_FLAG))
  1872. find_program(SCCACHE sccache REQUIRED)
  1873. if(SCCACHE)
  1874. message(STATUS "Enable sccache")
  1875. if(CMAKE_C_COMPILER_LAUNCHER)
  1876. set(CMAKE_C_COMPILER_LAUNCHER "${CMAKE_C_COMPILER_LAUNCHER}" "${SCCACHE}")
  1877. else()
  1878. set(CMAKE_C_COMPILER_LAUNCHER "${SCCACHE}")
  1879. endif()
  1880. if(CMAKE_CXX_COMPILER_LAUNCHER)
  1881. set(CMAKE_CXX_COMPILER_LAUNCHER "${CMAKE_CXX_COMPILER_LAUNCHER}" "${SCCACHE}")
  1882. else()
  1883. set(CMAKE_CXX_COMPILER_LAUNCHER "${SCCACHE}")
  1884. endif()
  1885. if (MSVC)
  1886. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  1887. string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
  1888. string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
  1889. elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
  1890. string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
  1891. string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
  1892. elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
  1893. string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
  1894. string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
  1895. endif()
  1896. endif()
  1897. set(WOLFSSL_SCCACHE_ALREADY_SET_FLAG ON)
  1898. endif()
  1899. endif()
  1900. file(REMOVE ${OPTION_FILE})
  1901. ####################################################
  1902. # Library Target
  1903. ####################################################
  1904. # TODO: - Build shared/static libs based on enables. Check CMake
  1905. # global flag BUILD_SHARED_LIBS.
  1906. option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" ON)
  1907. set(LIB_SOURCES "")
  1908. # Generates a list of sources to include in the library.
  1909. # Corresponds to the instances of "src_libwolfssl_la_SOURCES += ..."
  1910. # in the *.am files.
  1911. generate_lib_src_list("${LIB_SOURCES}")
  1912. if(BUILD_SHARED_LIBS)
  1913. message(STATUS "BUILD_SHARED_LIBS enabled: ${LIB_SOURCES}")
  1914. add_library(wolfssl SHARED ${LIB_SOURCES})
  1915. else()
  1916. message(STATUS "Static Libs: ${LIB_SOURCES}")
  1917. add_library(wolfssl STATIC ${LIB_SOURCES})
  1918. endif()
  1919. add_library(wolfssl::wolfssl ALIAS wolfssl)
  1920. if (NOT "$ENV{ARIA_DIR}" STREQUAL "")
  1921. message(STATUS "Found Environment variable ARIA_DIR=$ENV{ARIA_DIR}")
  1922. if(WOLFSSL_ARIA)
  1923. message(STATUS "wolfSSL WOLFSSL_ARIA is enabled")
  1924. else()
  1925. message(STATUS "wolfSSL WOLFSSL_ARIA is not enabled. To enable, specify a user_settings.h file or run: cmake .. -DWOLFSSL_ARIA=yes")
  1926. message(STATUS "Clear the ARIA_DIR environment variable to otherwise suppress this message when not using ARIA ciphers.")
  1927. endif()
  1928. endif()
  1929. # ARIA Check
  1930. if(WOLFSSL_ARIA)
  1931. message(STATUS "WOLFSSL_ARIA is enabled")
  1932. find_package(ARIA)
  1933. if(ARIA_FOUND)
  1934. message(STATUS "ARIA find_package() success.")
  1935. else()
  1936. message(FATAL_ERROR "WOLFSSL_ARIA is enabled, but find_package() did not find ARIA MagicCrypto.\n"
  1937. "Check ARIA_DIR environment variable and/or copy MagicCrypto directory locally.")
  1938. endif()
  1939. list(APPEND WOLFSSL_LINK_LIBS "${ARIA_LIB_FILE}")
  1940. # The cmake target_include_directories() will complain about local directories,
  1941. # so we'll handle MagicCrypto differently when found in wolfssl.
  1942. # see below to use include_directories() instead.
  1943. if(ARIA_IS_LOCAL)
  1944. # there's also a wolfssl port API to include, plus local ARIA include
  1945. include_directories("wolfssl/wolfcrypt/port/aria" "MagicCrypto/include")
  1946. else()
  1947. # see below for target_include_directories() instead
  1948. include_directories("wolfssl/wolfcrypt/port/aria")
  1949. message(STATUS "ARIA_IS_LOCAL is false, appending ${ARIA_INCLUDE_DIR} to WOLFSSL_INCLUDE_DIRS")
  1950. list(APPEND WOLFSSL_INCLUDE_DIRS "${ARIA_INCLUDE_DIR}")
  1951. endif()
  1952. add_library(MagicCrypto_lib
  1953. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/src/port/aria/aria-crypt.c
  1954. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/src/port/aria/aria-cryptocb.c
  1955. )
  1956. set_target_properties(MagicCrypto_lib PROPERTIES OUTPUT_NAME "MagicCrypto")
  1957. target_link_libraries(MagicCrypto_lib wolfssl)
  1958. target_compile_options(MagicCrypto_lib PRIVATE "-DHAVE_ARIA")
  1959. # ARIA was enabled and we successfully found it.
  1960. set(HAVE_ARIA 1)
  1961. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ARIA")
  1962. message(STATUS "ARIA Check: WOLFSSL_LINK_LIBS = ${WOLFSSL_LINK_LIBS}")
  1963. endif()
  1964. foreach(DEF IN LISTS WOLFSSL_DEFINITIONS)
  1965. string(REGEX MATCH "^(-D)?([^=]+)(=(.*))?$" DEF_MATCH ${DEF})
  1966. if (NOT "${CMAKE_MATCH_4}" STREQUAL "")
  1967. set(${CMAKE_MATCH_2} ${CMAKE_MATCH_4})
  1968. # message("set(${CMAKE_MATCH_2} ${CMAKE_MATCH_4})")
  1969. else()
  1970. set(${CMAKE_MATCH_2} 1)
  1971. # message("set(${CMAKE_MATCH_2} 1)")
  1972. endif()
  1973. endforeach()
  1974. # If new build options are added please update the cmake/options.h.in
  1975. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/options.h.in ${OPTION_FILE})
  1976. set_target_properties(wolfssl
  1977. PROPERTIES
  1978. SOVERSION ${WOLFSSL_LIBRARY_VERSION_FIRST}
  1979. VERSION ${LIBTOOL_FULL_VERSION}
  1980. )
  1981. target_compile_definitions(wolfssl PRIVATE "BUILDING_WOLFSSL")
  1982. if(${BUILD_SHARED_LIBS})
  1983. target_compile_definitions(wolfssl PUBLIC "WOLFSSL_DLL")
  1984. endif()
  1985. target_compile_definitions(wolfssl PUBLIC ${WOLFSSL_DEFINITIONS})
  1986. ####################################################
  1987. # Include Directories
  1988. ####################################################
  1989. if("${WOLFSSL_INCLUDE_DIRS}" STREQUAL "")
  1990. message(STATUS "WOLFSSL_INCLUDE_DIRS is blank. No additional directories will be added.")
  1991. else()
  1992. message(STATUS "WOLFSSL_INCLUDE_DIRS = ${WOLFSSL_INCLUDE_DIRS}")
  1993. endif()
  1994. target_include_directories(wolfssl
  1995. PUBLIC
  1996. $<INSTALL_INTERFACE:include>
  1997. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  1998. $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
  1999. ${WOLFSSL_INCLUDE_DIRS}
  2000. )
  2001. ####################################################
  2002. # Link Libraries
  2003. ####################################################
  2004. target_link_libraries(wolfssl PUBLIC ${WOLFSSL_LINK_LIBS})
  2005. if(WIN32)
  2006. # For Windows link ws2_32
  2007. target_link_libraries(wolfssl PUBLIC
  2008. $<$<PLATFORM_ID:Windows>:ws2_32 crypt32>)
  2009. elseif(APPLE)
  2010. if(WOLFSSL_SYS_CA_CERTS)
  2011. target_link_libraries(wolfssl PUBLIC
  2012. ${CORE_FOUNDATION_FRAMEWORK}
  2013. ${SECURITY_FRAMEWORK})
  2014. endif()
  2015. else()
  2016. if(WOLFSSL_DH AND NOT WOLFSSL_DH_CONST)
  2017. # DH requires math (m) library
  2018. target_link_libraries(wolfssl
  2019. PUBLIC
  2020. m)
  2021. endif()
  2022. endif()
  2023. ####################################################
  2024. # Tests and Examples
  2025. ####################################################
  2026. enable_testing()
  2027. if(WOLFSSL_EXAMPLES)
  2028. # Build wolfSSL client example
  2029. add_executable(client
  2030. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
  2031. target_link_libraries(client wolfssl)
  2032. set_property(TARGET client
  2033. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  2034. ${WOLFSSL_OUTPUT_BASE}/examples/client)
  2035. # Build wolfSSL server example
  2036. add_executable(server
  2037. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c)
  2038. target_link_libraries(server wolfssl)
  2039. set_property(TARGET server
  2040. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  2041. ${WOLFSSL_OUTPUT_BASE}/examples/server)
  2042. # Build echo client example
  2043. add_executable(echoclient
  2044. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient/echoclient.c)
  2045. target_include_directories(echoclient PRIVATE
  2046. ${CMAKE_CURRENT_BINARY_DIR})
  2047. target_link_libraries(echoclient wolfssl)
  2048. set_property(TARGET echoclient
  2049. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  2050. ${WOLFSSL_OUTPUT_BASE}/examples/echoclient)
  2051. # Build echo server example
  2052. add_executable(echoserver
  2053. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver/echoserver.c)
  2054. target_include_directories(echoserver PRIVATE
  2055. ${CMAKE_CURRENT_BINARY_DIR})
  2056. target_link_libraries(echoserver wolfssl)
  2057. set_property(TARGET echoserver
  2058. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  2059. ${WOLFSSL_OUTPUT_BASE}/examples/echoserver)
  2060. if(NOT WIN32 AND NOT WOLFSSL_SINGLE_THREADED)
  2061. # Build TLS benchmark example
  2062. add_executable(tls_bench
  2063. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c)
  2064. target_link_libraries(tls_bench wolfssl)
  2065. target_link_libraries(tls_bench Threads::Threads)
  2066. set_property(TARGET tls_bench
  2067. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  2068. ${WOLFSSL_OUTPUT_BASE}/examples/benchmark)
  2069. endif()
  2070. # Build unit tests
  2071. add_executable(unit_test
  2072. tests/api.c
  2073. tests/hash.c
  2074. tests/srp.c
  2075. tests/suites.c
  2076. tests/w64wrapper.c
  2077. tests/unit.c
  2078. tests/quic.c
  2079. examples/server/server.c
  2080. examples/client/client.c)
  2081. target_include_directories(unit_test PRIVATE
  2082. ${CMAKE_CURRENT_BINARY_DIR})
  2083. target_compile_options(unit_test PUBLIC "-DNO_MAIN_DRIVER")
  2084. target_link_libraries(unit_test wolfssl)
  2085. target_link_libraries(unit_test Threads::Threads)
  2086. set_property(TARGET unit_test
  2087. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  2088. ${WOLFSSL_OUTPUT_BASE}/tests/)
  2089. set_property(TARGET unit_test
  2090. PROPERTY RUNTIME_OUTPUT_NAME
  2091. unit.test)
  2092. add_test(NAME unit_test
  2093. COMMAND $<TARGET_FILE:unit_test>
  2094. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  2095. endif()
  2096. if(WOLFSSL_CRYPT_TESTS)
  2097. if(WOLFSSL_CRYPT_TESTS_LIBS)
  2098. # Build wolfCrypt test as a library. This will compile test.c and make
  2099. # its functions available as a CMake target that other CMake targets can
  2100. # pull in, in addition to producing the library itself. Note that this
  2101. # feature is not enabled by default, and the API of this library and
  2102. # wofcryptbench_lib should NOT be treated as stable.
  2103. add_library(wolfcrypttest_lib
  2104. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
  2105. set_target_properties(wolfcrypttest_lib PROPERTIES OUTPUT_NAME "wolfcrypttest")
  2106. target_link_libraries(wolfcrypttest_lib wolfssl)
  2107. target_compile_options(wolfcrypttest_lib PRIVATE "-DNO_MAIN_DRIVER")
  2108. if(WOLFSSL_CRYPT_TESTS_HELP)
  2109. target_compile_options(wolfcrypttest_lib PRIVATE "-DHAVE_WOLFCRYPT_TEST_OPTIONS")
  2110. endif()
  2111. # Make another library for the wolfCrypt benchmark code.
  2112. add_library(wolfcryptbench_lib
  2113. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
  2114. set_target_properties(wolfcryptbench_lib PROPERTIES OUTPUT_NAME "wolfcryptbench")
  2115. target_link_libraries(wolfcryptbench_lib wolfssl)
  2116. target_compile_options(wolfcryptbench_lib PRIVATE "-DNO_MAIN_DRIVER")
  2117. endif()
  2118. # Build wolfCrypt test executable.
  2119. add_executable(wolfcrypttest
  2120. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
  2121. target_link_libraries(wolfcrypttest wolfssl)
  2122. set_property(TARGET wolfcrypttest
  2123. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  2124. ${WOLFSSL_OUTPUT_BASE}/wolfcrypt/test)
  2125. set_property(TARGET wolfcrypttest
  2126. PROPERTY RUNTIME_OUTPUT_NAME
  2127. testwolfcrypt)
  2128. if(WOLFSSL_CRYPT_TESTS_HELP)
  2129. target_compile_options(wolfcrypttest PRIVATE "-DHAVE_WOLFCRYPT_TEST_OPTIONS")
  2130. endif()
  2131. add_test(NAME wolfcrypttest
  2132. COMMAND $<TARGET_FILE:wolfcrypttest>
  2133. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  2134. # Build wolfCrypt benchmark executable.
  2135. add_executable(wolfcryptbench
  2136. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
  2137. target_include_directories(wolfcryptbench PRIVATE
  2138. ${CMAKE_CURRENT_BINARY_DIR})
  2139. target_link_libraries(wolfcryptbench wolfssl)
  2140. set_property(TARGET wolfcryptbench
  2141. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  2142. ${WOLFSSL_OUTPUT_BASE}/wolfcrypt/benchmark)
  2143. set_property(TARGET wolfcryptbench
  2144. PROPERTY RUNTIME_OUTPUT_NAME
  2145. benchmark)
  2146. endif()
  2147. ####################################################
  2148. # Installation
  2149. ####################################################
  2150. include(GNUInstallDirs)
  2151. set(HEADER_EXCLUDE
  2152. "internal.h"
  2153. "wolfssl/wolfcrypt/port/nrf51.h"
  2154. "wolfssl/wolfcrypt/port/arm"
  2155. "wolfssl/wolfcrypt/port/cypress"
  2156. "wolfssl/wolfcrypt/port/Espressif"
  2157. "wolfssl/wolfcrypt/port/iotsafe"
  2158. "wolfssl/wolfcrypt/port/nxp"
  2159. "wolfssl/wolfcrypt/port/pic"
  2160. "wolfssl/wolfcrypt/port/Renesas"
  2161. "wolfssl/wolfcrypt/port/silabs"
  2162. "wolfssl/wolfcrypt/port/st"
  2163. "wolfssl/wolfcrypt/port/ti"
  2164. "wolfssl/wolfcrypt/port/xilinx"
  2165. )
  2166. # TODO: add support for the various ports
  2167. # For distro build don't install options.h.
  2168. # It depends on the architecture and conflicts with Multi-Arch.
  2169. if(BUILD_DISTRO)
  2170. list(APPEND HEADER_EXCLUDE
  2171. "options.h")
  2172. endif()
  2173. if(NOT BUILD_CRYPTOAUTHLIB)
  2174. list(APPEND HEADER_EXCLUDE
  2175. "wolfssl/wolfcrypt/port/atmel")
  2176. endif()
  2177. if(NOT BUILD_AFALG)
  2178. list(APPEND HEADER_EXCLUDE
  2179. "wolfssl/wolfcrypt/port/af_alg")
  2180. endif()
  2181. if(NOT BUILD_KCAPI)
  2182. list(APPEND HEADER_EXCLUDE
  2183. "wolfssl/wolfcrypt/port/kcapi"
  2184. )
  2185. endif()
  2186. if(NOT BUILD_DEVCRYPTO)
  2187. list(APPEND HEADER_EXCLUDE
  2188. "wolfssl/wolfcrypt/port/devcrypto")
  2189. endif()
  2190. if(NOT BUILD_ASYNCCRYPT)
  2191. list(APPEND HEADER_EXCLUDE
  2192. "wolfssl/wolfcrypt/async.h")
  2193. endif()
  2194. if(NOT BUILD_PKCS11)
  2195. list(APPEND HEADER_EXCLUDE
  2196. "wolfssl/wolfcrypt/wc_pkcs11.h"
  2197. "wolfssl/wolfcrypt/pkcs11.h"
  2198. )
  2199. endif()
  2200. if(NOT BUILD_CAVIUM AND NOT BUILD_OCTEON_SYNC)
  2201. list(APPEND HEADER_EXCLUDE
  2202. "wolfssl/wolfcrypt/port/cavium")
  2203. else()
  2204. if(NOT BUILD_CAVIUM)
  2205. list(APPEND HEADER_EXCLUDE
  2206. "wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h")
  2207. endif()
  2208. if(NOT BUILD_OCTEON_SYNC)
  2209. list(APPEND HEADER_EXCLUDE
  2210. "wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h"
  2211. )
  2212. endif()
  2213. endif()
  2214. if(NOT BUILD_INTEL_QA AND NOT BUILD_INTEL_QA_SYNC)
  2215. list(APPEND HEADER_EXCLUDE
  2216. "wolfssl/wolfcrypt/port/intel")
  2217. else()
  2218. if(NOT BUILD_INTEL_QA)
  2219. list(APPEND HEADER_EXCLUDE
  2220. "wolfssl/wolfcrypt/port/intel/quickassist.h"
  2221. "wolfssl/wolfcrypt/port/intel/quickassist_mem.h"
  2222. )
  2223. endif()
  2224. if(NOT BUILD_INTEL_QA_SYNC)
  2225. list(APPEND HEADER_EXCLUDE
  2226. "wolfssl/wolfcrypt/port/intel/quickassist_sync.h")
  2227. endif()
  2228. endif()
  2229. if(NOT BUILD_SP)
  2230. list(APPEND HEADER_EXCLUDE
  2231. "wolfssl/wolfcrypt/sp.h")
  2232. endif()
  2233. if(NOT BUILD_SP_INT)
  2234. list(APPEND HEADER_EXCLUDE
  2235. "wolfssl/wolfcrypt/sp_int.h")
  2236. endif()
  2237. if(NOT BUILD_SELFTEST)
  2238. list(APPEND HEADER_EXCLUDE
  2239. "wolfssl/wolfcrypt/selftest.h")
  2240. endif()
  2241. if(NOT BUILD_FIPS OR BUILD_FIPS_V1)
  2242. list(APPEND HEADER_EXCLUDE
  2243. "wolfssl/wolfcrypt/fips.h")
  2244. endif()
  2245. if(NOT BUILD_QNXCAAM OR BUILD_CAAM)
  2246. list(APPEND HEADER_EXCLUDE
  2247. "wolfssl/wolfcrypt/port/caam"
  2248. )
  2249. endif()
  2250. list(JOIN HEADER_EXCLUDE "|" EXCLUDED_HEADERS_REGEX)
  2251. string(PREPEND EXCLUDED_HEADERS_REGEX "(")
  2252. string(APPEND EXCLUDED_HEADERS_REGEX ")")
  2253. if(WOLFSSL_INSTALL)
  2254. set(INSTALLED_EXAMPLES
  2255. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver/echoserver.c
  2256. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-server.c
  2257. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-client-dtls.c
  2258. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-client.c
  2259. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-server-dtls.c
  2260. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient/echoclient.c
  2261. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c
  2262. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c
  2263. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
  2264. # Install the library
  2265. install(TARGETS wolfssl
  2266. EXPORT wolfssl-targets
  2267. LIBRARY DESTINATION lib
  2268. ARCHIVE DESTINATION lib
  2269. RUNTIME DESTINATION bin
  2270. )
  2271. # Install the headers
  2272. install(DIRECTORY ${WOLFSSL_OUTPUT_BASE}/wolfssl/
  2273. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wolfssl
  2274. FILES_MATCHING PATTERN "*.h"
  2275. REGEX ${EXCLUDED_HEADERS_REGEX} EXCLUDE)
  2276. install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/
  2277. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wolfssl
  2278. FILES_MATCHING PATTERN "*.h"
  2279. REGEX ${EXCLUDED_HEADERS_REGEX} EXCLUDE)
  2280. # Install the examples
  2281. install(FILES ${INSTALLED_EXAMPLES}
  2282. DESTINATION ${CMAKE_INSTALL_DOCDIR}/example)
  2283. # Install README.txt and taoCert.txt
  2284. install(FILES
  2285. ${CMAKE_CURRENT_SOURCE_DIR}/doc/README.txt
  2286. ${CMAKE_CURRENT_SOURCE_DIR}/certs/taoCert.txt
  2287. DESTINATION ${CMAKE_INSTALL_DOCDIR})
  2288. # Install the export set
  2289. install(EXPORT wolfssl-targets
  2290. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/wolfssl
  2291. FILE wolfssl-targets.cmake
  2292. NAMESPACE wolfssl::)
  2293. # TODO: Distro build + rules for what to include in the distro.
  2294. # See various include.am files.
  2295. set(prefix ${CMAKE_INSTALL_PREFIX})
  2296. set(exec_prefix "\${prefix}")
  2297. set(libdir "\${exec_prefix}/lib")
  2298. set(includedir "\${prefix}/include")
  2299. set(VERSION ${PROJECT_VERSION})
  2300. # Setting libm in Libs.private of wolfssl.pc.
  2301. # See "Link Libraries" in above about `m` insertion to LINK_LIBRARIES
  2302. get_target_property(_wolfssl_dep_libs wolfssl LINK_LIBRARIES)
  2303. list(FIND _wolfssl_dep_libs m _dep_libm)
  2304. if ("${_dep_libm}" GREATER -1)
  2305. set(LIBM -lm)
  2306. else()
  2307. set(LIBM)
  2308. endif()
  2309. configure_file(support/wolfssl.pc.in ${CMAKE_CURRENT_BINARY_DIR}/support/wolfssl.pc @ONLY)
  2310. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/support/wolfssl.pc
  2311. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  2312. include(CMakePackageConfigHelpers)
  2313. configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
  2314. "${CMAKE_CURRENT_BINARY_DIR}/wolfssl-config.cmake"
  2315. INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/wolfssl"
  2316. NO_SET_AND_CHECK_MACRO
  2317. NO_CHECK_REQUIRED_COMPONENTS_MACRO
  2318. )
  2319. export(EXPORT wolfssl-targets
  2320. FILE "${CMAKE_CURRENT_BINARY_DIR}/wolfssl-targets.cmake"
  2321. NAMESPACE wolfssl::
  2322. )
  2323. write_basic_package_version_file(
  2324. "${CMAKE_CURRENT_BINARY_DIR}/wolfssl-config-version.cmake"
  2325. VERSION "${wolfssl_VERSION_MAJOR}.${wolfssl_VERSION_MINOR}"
  2326. COMPATIBILITY AnyNewerVersion
  2327. )
  2328. install(FILES
  2329. ${CMAKE_CURRENT_BINARY_DIR}/wolfssl-config.cmake
  2330. ${CMAKE_CURRENT_BINARY_DIR}/wolfssl-config-version.cmake
  2331. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/wolfssl
  2332. )
  2333. endif()