CMakeLists.txt 82 KB

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