settings.h 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174
  1. /* settings.h
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /*
  22. * ************************************************************************
  23. *
  24. * ******************************** NOTICE ********************************
  25. *
  26. * ************************************************************************
  27. *
  28. * This method of uncommenting a line in settings.h is outdated.
  29. *
  30. * Please use user_settings.h / WOLFSSL_USER_SETTINGS
  31. *
  32. * or
  33. *
  34. * ./configure CFLAGS="-DFLAG"
  35. *
  36. * For more information see:
  37. *
  38. * https://www.wolfssl.com/how-do-i-manage-the-build-configuration-of-wolfssl/
  39. *
  40. */
  41. /* Place OS specific preprocessor flags, defines, includes here, will be
  42. included into every file because types.h includes it */
  43. #ifndef WOLF_CRYPT_SETTINGS_H
  44. #define WOLF_CRYPT_SETTINGS_H
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /* This flag allows wolfSSL to include options.h instead of having client
  49. * projects do it themselves. This should *NEVER* be defined when building
  50. * wolfSSL as it can cause hard to debug problems. */
  51. #ifdef EXTERNAL_OPTS_OPENVPN
  52. #include <wolfssl/options.h>
  53. #endif
  54. /* Uncomment next line if using IPHONE */
  55. /* #define IPHONE */
  56. /* Uncomment next line if using ThreadX */
  57. /* #define THREADX */
  58. /* Uncomment next line if using Micrium uC/OS-III */
  59. /* #define MICRIUM */
  60. /* Uncomment next line if using Deos RTOS*/
  61. /* #define WOLFSSL_DEOS*/
  62. /* Uncomment next line if using Mbed */
  63. /* #define MBED */
  64. /* Uncomment next line if using Microchip PIC32 ethernet starter kit */
  65. /* #define MICROCHIP_PIC32 */
  66. /* Uncomment next line if using Microchip TCP/IP stack, version 5 */
  67. /* #define MICROCHIP_TCPIP_V5 */
  68. /* Uncomment next line if using Microchip TCP/IP stack, version 6 or later */
  69. /* #define MICROCHIP_TCPIP */
  70. /* Uncomment next line if using above Microchip TCP/IP defines with BSD API */
  71. /* #define MICROCHIP_TCPIP_BSD_API */
  72. /* Uncomment next line if using PIC32MZ Crypto Engine */
  73. /* #define WOLFSSL_MICROCHIP_PIC32MZ */
  74. /* Uncomment next line if using FreeRTOS */
  75. /* #define FREERTOS */
  76. /* Uncomment next line if using FreeRTOS+ TCP */
  77. /* #define FREERTOS_TCP */
  78. /* Uncomment next line if using FreeRTOS Windows Simulator */
  79. /* #define FREERTOS_WINSIM */
  80. /* Uncomment next line if using RTIP */
  81. /* #define EBSNET */
  82. /* Uncomment next line if using lwip */
  83. /* #define WOLFSSL_LWIP */
  84. /* Uncomment next line if building wolfSSL for a game console */
  85. /* #define WOLFSSL_GAME_BUILD */
  86. /* Uncomment next line if building wolfSSL for LSR */
  87. /* #define WOLFSSL_LSR */
  88. /* Uncomment next line if building for Freescale Classic MQX version 5.0 */
  89. /* #define FREESCALE_MQX_5_0 */
  90. /* Uncomment next line if building for Freescale Classic MQX version 4.0 */
  91. /* #define FREESCALE_MQX_4_0 */
  92. /* Uncomment next line if building for Freescale Classic MQX/RTCS/MFS */
  93. /* #define FREESCALE_MQX */
  94. /* Uncomment next line if building for Freescale KSDK MQX/RTCS/MFS */
  95. /* #define FREESCALE_KSDK_MQX */
  96. /* Uncomment next line if building for Freescale KSDK Bare Metal */
  97. /* #define FREESCALE_KSDK_BM */
  98. /* Uncomment next line if building for Freescale KSDK FreeRTOS, */
  99. /* (old name FREESCALE_FREE_RTOS) */
  100. /* #define FREESCALE_KSDK_FREERTOS */
  101. /* Uncomment next line if using STM32F2 */
  102. /* #define WOLFSSL_STM32F2 */
  103. /* Uncomment next line if using STM32F4 */
  104. /* #define WOLFSSL_STM32F4 */
  105. /* Uncomment next line if using STM32FL */
  106. /* #define WOLFSSL_STM32FL */
  107. /* Uncomment next line if using STM32F7 */
  108. /* #define WOLFSSL_STM32F7 */
  109. /* Uncomment next line if using QL SEP settings */
  110. /* #define WOLFSSL_QL */
  111. /* Uncomment next line if building for EROAD */
  112. /* #define WOLFSSL_EROAD */
  113. /* Uncomment next line if building for IAR EWARM */
  114. /* #define WOLFSSL_IAR_ARM */
  115. /* Uncomment next line if building for Rowley CrossWorks ARM */
  116. /* #define WOLFSSL_ROWLEY_ARM */
  117. /* Uncomment next line if using TI-RTOS settings */
  118. /* #define WOLFSSL_TIRTOS */
  119. /* Uncomment next line if building with PicoTCP */
  120. /* #define WOLFSSL_PICOTCP */
  121. /* Uncomment next line if building for PicoTCP demo bundle */
  122. /* #define WOLFSSL_PICOTCP_DEMO */
  123. /* Uncomment next line if building for uITRON4 */
  124. /* #define WOLFSSL_uITRON4 */
  125. /* Uncomment next line if building for uT-Kernel */
  126. /* #define WOLFSSL_uTKERNEL2 */
  127. /* Uncomment next line if using Max Strength build */
  128. /* #define WOLFSSL_MAX_STRENGTH */
  129. /* Uncomment next line if building for VxWorks */
  130. /* #define WOLFSSL_VXWORKS */
  131. /* Uncomment next line if building for Nordic nRF5x platform */
  132. /* #define WOLFSSL_NRF5x */
  133. /* Uncomment next line to enable deprecated less secure static DH suites */
  134. /* #define WOLFSSL_STATIC_DH */
  135. /* Uncomment next line to enable deprecated less secure static RSA suites */
  136. /* #define WOLFSSL_STATIC_RSA */
  137. /* Uncomment next line if building for ARDUINO */
  138. /* Uncomment both lines if building for ARDUINO on INTEL_GALILEO */
  139. /* #define WOLFSSL_ARDUINO */
  140. /* #define INTEL_GALILEO */
  141. /* Uncomment next line to enable asynchronous crypto WC_PENDING_E */
  142. /* #define WOLFSSL_ASYNC_CRYPT */
  143. /* Uncomment next line if building for uTasker */
  144. /* #define WOLFSSL_UTASKER */
  145. /* Uncomment next line if building for embOS */
  146. /* #define WOLFSSL_EMBOS */
  147. /* Uncomment next line if building for RIOT-OS */
  148. /* #define WOLFSSL_RIOT_OS */
  149. /* Uncomment next line if building for using XILINX hardened crypto */
  150. /* #define WOLFSSL_XILINX_CRYPT */
  151. /* Uncomment next line if building for using XILINX */
  152. /* #define WOLFSSL_XILINX */
  153. /* Uncomment next line if building for WICED Studio. */
  154. /* #define WOLFSSL_WICED */
  155. /* Uncomment next line if building for Nucleus 1.2 */
  156. /* #define WOLFSSL_NUCLEUS_1_2 */
  157. /* Uncomment next line if building for using Apache mynewt */
  158. /* #define WOLFSSL_APACHE_MYNEWT */
  159. /* For Espressif chips see example user_settings.h
  160. *
  161. * https://github.com/wolfSSL/wolfssl/blob/master/IDE/Espressif/ESP-IDF/user_settings.h
  162. */
  163. /* Uncomment next line if building for using ESP-IDF */
  164. /* #define WOLFSSL_ESPIDF */
  165. /* Uncomment next line if using Espressif ESP32-WROOM-32 */
  166. /* #define WOLFSSL_ESP32 */
  167. /* Uncomment next line if using Espressif ESP32-WROOM-32SE */
  168. /* #define WOLFSSL_ESPWROOM32SE */
  169. /* Uncomment next line if using ARM CRYPTOCELL*/
  170. /* #define WOLFSSL_CRYPTOCELL */
  171. /* Uncomment next line if using RENESAS TSIP */
  172. /* #define WOLFSSL_RENESAS_TSIP */
  173. /* Uncomment next line if using RENESAS RX64N */
  174. /* #define WOLFSSL_RENESAS_RX65N */
  175. /* Uncomment next line if using RENESAS SCE Protected Mode */
  176. /* #define WOLFSSL_RENESAS_SCEPROTECT */
  177. /* Uncomment next line if using RENESAS RA6M4 */
  178. /* #define WOLFSSL_RENESAS_RA6M4 */
  179. /* Uncomment next line if using RENESAS RX64 hardware acceleration */
  180. /* #define WOLFSSL_RENESAS_RX64_HASH */
  181. /* Uncomment next line if using Solaris OS*/
  182. /* #define WOLFSSL_SOLARIS */
  183. /* Uncomment next line if building for Linux Kernel Module */
  184. /* #define WOLFSSL_LINUXKM */
  185. /* Uncomment next line if building for devkitPro */
  186. /* #define DEVKITPRO */
  187. /* Uncomment next line if building for Dolphin Emulator */
  188. /* #define DOLPHIN_EMULATOR */
  189. /* Uncomment next line if using MAXQ1065 */
  190. /* #define WOLFSSL_MAXQ1065 */
  191. /* Uncomment next line if using MAXQ108x */
  192. /* #define WOLFSSL_MAXQ108X */
  193. #ifdef WOLFSSL_USER_SETTINGS
  194. #include "user_settings.h"
  195. #elif defined(USE_HAL_DRIVER) && !defined(HAVE_CONFIG_H)
  196. /* STM Configuration File (generated by CubeMX) */
  197. #include "wolfSSL.I-CUBE-wolfSSL_conf.h"
  198. #endif
  199. #include <wolfssl/wolfcrypt/visibility.h>
  200. #define WOLFSSL_MAKE_FIPS_VERSION(major, minor) (((major) * 256) + (minor))
  201. #if !defined(HAVE_FIPS)
  202. #define WOLFSSL_FIPS_VERSION_CODE WOLFSSL_MAKE_FIPS_VERSION(0,0)
  203. #elif !defined(HAVE_FIPS_VERSION)
  204. #define WOLFSSL_FIPS_VERSION_CODE WOLFSSL_MAKE_FIPS_VERSION(1,0)
  205. #elif !defined(HAVE_FIPS_VERSION_MINOR)
  206. #define WOLFSSL_FIPS_VERSION_CODE WOLFSSL_MAKE_FIPS_VERSION(HAVE_FIPS_VERSION,0)
  207. #else
  208. #define WOLFSSL_FIPS_VERSION_CODE WOLFSSL_MAKE_FIPS_VERSION(HAVE_FIPS_VERSION,HAVE_FIPS_VERSION_MINOR)
  209. #endif
  210. #define FIPS_VERSION_LT(major,minor) (WOLFSSL_FIPS_VERSION_CODE < WOLFSSL_MAKE_FIPS_VERSION(major,minor))
  211. #define FIPS_VERSION_LE(major,minor) (WOLFSSL_FIPS_VERSION_CODE <= WOLFSSL_MAKE_FIPS_VERSION(major,minor))
  212. #define FIPS_VERSION_EQ(major,minor) (WOLFSSL_FIPS_VERSION_CODE == WOLFSSL_MAKE_FIPS_VERSION(major,minor))
  213. #define FIPS_VERSION_GE(major,minor) (WOLFSSL_FIPS_VERSION_CODE >= WOLFSSL_MAKE_FIPS_VERSION(major,minor))
  214. #define FIPS_VERSION_GT(major,minor) (WOLFSSL_FIPS_VERSION_CODE > WOLFSSL_MAKE_FIPS_VERSION(major,minor))
  215. /* make sure old RNG name is used with CTaoCrypt FIPS */
  216. #ifdef HAVE_FIPS
  217. #if FIPS_VERSION_LT(2,0)
  218. #define WC_RNG RNG
  219. #else
  220. #ifndef WOLFSSL_STM32L4
  221. #define RNG WC_RNG
  222. #endif
  223. #endif
  224. /* blinding adds API not available yet in FIPS mode */
  225. #undef WC_RSA_BLINDING
  226. #endif
  227. #ifdef WOLFSSL_HARDEN_TLS
  228. #if WOLFSSL_HARDEN_TLS != 112 && WOLFSSL_HARDEN_TLS != 128
  229. #error "WOLFSSL_HARDEN_TLS must be defined either to 112 or 128 bits of security."
  230. #endif
  231. #endif
  232. /* OpenSSL compat layer */
  233. #if defined(OPENSSL_EXTRA) && !defined(OPENSSL_COEXIST)
  234. #undef WOLFSSL_ALWAYS_VERIFY_CB
  235. #define WOLFSSL_ALWAYS_VERIFY_CB
  236. #undef WOLFSSL_VERIFY_CB_ALL_CERTS
  237. #define WOLFSSL_VERIFY_CB_ALL_CERTS
  238. #undef WOLFSSL_EXTRA_ALERTS
  239. #define WOLFSSL_EXTRA_ALERTS
  240. #undef HAVE_EXT_CACHE
  241. #define HAVE_EXT_CACHE
  242. #undef WOLFSSL_FORCE_CACHE_ON_TICKET
  243. #define WOLFSSL_FORCE_CACHE_ON_TICKET
  244. #undef WOLFSSL_AKID_NAME
  245. #define WOLFSSL_AKID_NAME
  246. #undef HAVE_CTS
  247. #define HAVE_CTS
  248. #endif /* OPENSSL_EXTRA && !OPENSSL_COEXIST */
  249. /* Special small OpenSSL compat layer for certs */
  250. #ifdef OPENSSL_EXTRA_X509_SMALL
  251. #undef WOLFSSL_EKU_OID
  252. #define WOLFSSL_EKU_OID
  253. #undef WOLFSSL_MULTI_ATTRIB
  254. #define WOLFSSL_MULTI_ATTRIB
  255. #undef WOLFSSL_NO_OPENSSL_RAND_CB
  256. #define WOLFSSL_NO_OPENSSL_RAND_CB
  257. #endif /* OPENSSL_EXTRA_X509_SMALL */
  258. #if defined(_WIN32) && !defined(_M_X64) && \
  259. defined(HAVE_AESGCM) && defined(WOLFSSL_AESNI)
  260. /* The _M_X64 macro is what's used in the headers for MSC to tell if it
  261. * has the 64-bit versions of the 128-bit integers available. If one is
  262. * building on 32-bit Windows with AES-NI, turn off the AES-GCMloop
  263. * unrolling. */
  264. #define AES_GCM_AESNI_NO_UNROLL
  265. #endif
  266. #ifdef IPHONE
  267. #define SIZEOF_LONG_LONG 8
  268. #endif
  269. #ifdef THREADX
  270. #define SIZEOF_LONG_LONG 8
  271. #endif
  272. #ifdef HAVE_NETX
  273. #ifdef NEED_THREADX_TYPES
  274. #include <types.h>
  275. #endif
  276. #include <nx_api.h>
  277. #endif
  278. #if defined(WOLFSSL_ESPIDF)
  279. #define FREERTOS
  280. #define WOLFSSL_LWIP
  281. #define NO_WRITEV
  282. #define SIZEOF_LONG_LONG 8
  283. #define NO_WOLFSSL_DIR
  284. #define WOLFSSL_NO_CURRDIR
  285. #define TFM_TIMING_RESISTANT
  286. #define ECC_TIMING_RESISTANT
  287. #define WC_RSA_BLINDING
  288. #if defined(WOLFSSL_ESPWROOM32)
  289. /* WOLFSSL_ESPWROOM32 is a legacy macro gate.
  290. ** Not be be confused with WOLFSSL_ESPWROOM32SE, naming a specific board */
  291. #undef WOLFSSL_ESP32
  292. #define WOLFSSL_ESP32
  293. #endif
  294. #if defined(WOLFSSL_ESP32) || defined(WOLFSSL_ESPWROOM32SE)
  295. #ifndef NO_ESP32_CRYPT
  296. #define WOLFSSL_ESP32_CRYPT
  297. #if defined(ESP32_USE_RSA_PRIMITIVE) && \
  298. !defined(NO_WOLFSSL_ESP32_CRYPT_RSA_PRI)
  299. #define WOLFSSL_ESP32_CRYPT_RSA_PRI
  300. #define WOLFSSL_SMALL_STACK
  301. #endif
  302. #endif
  303. #endif
  304. #endif /* WOLFSSL_ESPIDF */
  305. #if defined(WOLFSSL_RENESAS_TSIP)
  306. #define TSIP_TLS_HMAC_KEY_INDEX_WORDSIZE 64
  307. #define TSIP_TLS_MASTERSECRET_SIZE 80 /* 20 words */
  308. #define TSIP_TLS_ENCPUBKEY_SZ_BY_CERTVRFY 560 /* in byte */
  309. #endif /* WOLFSSL_RENESAS_TSIP */
  310. #if !defined(WOLFSSL_NO_HASH_RAW) && defined(WOLFSSL_RENESAS_RX64_HASH)
  311. /* RAW hash function APIs are not implemented with RX64 hardware acceleration */
  312. #define WOLFSSL_NO_HASH_RAW
  313. #endif
  314. #if defined(WOLFSSL_RENESAS_SCEPROTECT)
  315. #define FSPSM_TLS_MASTERSECRET_SIZE 80 /* 20 words */
  316. #define TSIP_TLS_HMAC_KEY_INDEX_WORDSIZE 64
  317. #define TSIP_TLS_ENCPUBKEY_SZ_BY_CERTVRFY 560 /* in bytes */
  318. #define FSPSM_TLS_CLIENTRANDOM_SZ 36 /* in bytes */
  319. #define FSPSM_TLS_SERVERRANDOM_SZ 36 /* in bytes */
  320. #define FSPSM_TLS_ENCRYPTED_ECCPUBKEY_SZ 96 /* in bytes */
  321. #define WOLFSSL_RENESAS_FSPSM_ECC
  322. #if defined(WOLFSSL_RENESAS_FSPSM_ECC)
  323. #define HAVE_PK_CALLBACKS
  324. /* #define DEBUG_PK_CB */
  325. #endif
  326. #endif
  327. #if defined(WOLFSSL_RENESAS_RA6M3G) || defined(WOLFSSL_RENESAS_RA6M3) ||\
  328. defined(WOLFSSL_RENESAS_RA6M4)
  329. /* settings in user_settings.h */
  330. #endif
  331. #if defined(WOLFSSL_LWIP_NATIVE) || \
  332. defined(HAVE_LWIP_NATIVE) /* using LwIP native TCP socket */
  333. #undef WOLFSSL_USER_IO
  334. #define WOLFSSL_USER_IO
  335. #if defined(HAVE_LWIP_NATIVE)
  336. #define WOLFSSL_LWIP
  337. #define NO_WRITEV
  338. #define SINGLE_THREADED
  339. #define NO_FILESYSTEM
  340. #endif
  341. #endif
  342. #if defined(WOLFSSL_CONTIKI)
  343. #include <contiki.h>
  344. #define WOLFSSL_UIP
  345. #define NO_WOLFSSL_MEMORY
  346. #define NO_WRITEV
  347. #define SINGLE_THREADED
  348. #define WOLFSSL_USER_IO
  349. #define NO_FILESYSTEM
  350. #ifndef CUSTOM_RAND_GENERATE
  351. #define CUSTOM_RAND_TYPE uint16_t
  352. #define CUSTOM_RAND_GENERATE random_rand
  353. #endif
  354. static inline word32 LowResTimer(void)
  355. {
  356. return clock_seconds();
  357. }
  358. #endif
  359. #if defined(WOLFSSL_IAR_ARM) || defined(WOLFSSL_ROWLEY_ARM)
  360. #define NO_MAIN_DRIVER
  361. #define SINGLE_THREADED
  362. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_4096)
  363. #define USE_CERT_BUFFERS_1024
  364. #endif
  365. #define BENCH_EMBEDDED
  366. #define NO_FILESYSTEM
  367. #define NO_WRITEV
  368. #define WOLFSSL_USER_IO
  369. #define BENCH_EMBEDDED
  370. #endif
  371. #ifdef MICROCHIP_PIC32
  372. /* #define WOLFSSL_MICROCHIP_PIC32MZ */
  373. #define SIZEOF_LONG_LONG 8
  374. #define SINGLE_THREADED
  375. #ifndef MICROCHIP_TCPIP_BSD_API
  376. #define WOLFSSL_USER_IO
  377. #endif
  378. #define NO_WRITEV
  379. #define NO_DEV_RANDOM
  380. #define NO_FILESYSTEM
  381. #define TFM_TIMING_RESISTANT
  382. #define NO_BIG_INT
  383. #endif
  384. #ifdef WOLFSSL_MICROCHIP_PIC32MZ
  385. #define WOLFSSL_HAVE_MIN
  386. #define WOLFSSL_HAVE_MAX
  387. #ifndef NO_PIC32MZ_CRYPT
  388. #define WOLFSSL_PIC32MZ_CRYPT
  389. #endif
  390. #ifndef NO_PIC32MZ_RNG
  391. #define WOLFSSL_PIC32MZ_RNG
  392. #endif
  393. #ifndef NO_PIC32MZ_HASH
  394. #define WOLFSSL_PIC32MZ_HASH
  395. #endif
  396. #endif
  397. #ifdef MICROCHIP_TCPIP_V5
  398. /* include timer functions */
  399. #include "TCPIP Stack/TCPIP.h"
  400. #endif
  401. #ifdef MICROCHIP_TCPIP
  402. /* include timer, NTP functions */
  403. #ifdef MICROCHIP_MPLAB_HARMONY
  404. #include "tcpip/tcpip.h"
  405. #else
  406. #include "system/system_services.h"
  407. #include "tcpip/sntp.h"
  408. #endif
  409. #endif
  410. #ifdef WOLFSSL_ATECC508A
  411. /* backwards compatibility */
  412. #ifndef WOLFSSL_ATECC_NO_ECDH_ENC
  413. #define WOLFSSL_ATECC_ECDH_ENC
  414. #endif
  415. #ifdef WOLFSSL_ATECC508A_DEBUG
  416. #define WOLFSSL_ATECC_DEBUG
  417. #endif
  418. #endif
  419. #ifdef MBED
  420. #define WOLFSSL_USER_IO
  421. #define NO_FILESYSTEM
  422. #define NO_CERTS
  423. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_4096)
  424. #define USE_CERT_BUFFERS_1024
  425. #endif
  426. #define NO_WRITEV
  427. #define NO_DEV_RANDOM
  428. #define NO_SHA512
  429. #define NO_DH
  430. /* Allows use of DH with fixed points if uncommented and NO_DH is removed */
  431. /* WOLFSSL_DH_CONST */
  432. #define NO_DSA
  433. #define HAVE_ECC
  434. #define NO_SESSION_CACHE
  435. #define WOLFSSL_CMSIS_RTOS
  436. #endif
  437. #ifdef WOLFSSL_EROAD
  438. #define FREESCALE_MQX
  439. #define FREESCALE_MMCAU
  440. #define SINGLE_THREADED
  441. #define NO_STDIO_FILESYSTEM
  442. #define WOLFSSL_LEANPSK
  443. #define HAVE_NULL_CIPHER
  444. #define NO_OLD_TLS
  445. #define NO_ASN
  446. #define NO_BIG_INT
  447. #define NO_RSA
  448. #define NO_DSA
  449. #define NO_DH
  450. /* Allows use of DH with fixed points if uncommented and NO_DH is removed */
  451. /* WOLFSSL_DH_CONST */
  452. #define NO_CERTS
  453. #define NO_PWDBASED
  454. #define NO_DES3
  455. #define NO_MD4
  456. #define NO_RC4
  457. #define NO_MD5
  458. #define NO_SESSION_CACHE
  459. #define NO_MAIN_DRIVER
  460. #endif
  461. #ifdef WOLFSSL_PICOTCP
  462. #ifndef errno
  463. #define errno pico_err
  464. #endif
  465. #include "pico_defines.h"
  466. #include "pico_stack.h"
  467. #include "pico_constants.h"
  468. #include "pico_protocol.h"
  469. #ifndef CUSTOM_RAND_GENERATE
  470. #define CUSTOM_RAND_GENERATE pico_rand
  471. #endif
  472. #endif
  473. #ifdef WOLFSSL_PICOTCP_DEMO
  474. #define WOLFSSL_STM32
  475. #define TFM_TIMING_RESISTANT
  476. #define XMALLOC(s, h, type) PICO_ZALLOC((s))
  477. #define XFREE(p, h, type) PICO_FREE((p))
  478. #define SINGLE_THREADED
  479. #define NO_WRITEV
  480. #define WOLFSSL_USER_IO
  481. #define NO_DEV_RANDOM
  482. #define NO_FILESYSTEM
  483. #endif
  484. #ifdef FREERTOS_WINSIM
  485. #define FREERTOS
  486. #define USE_WINDOWS_API
  487. #endif
  488. #ifdef WOLFSSL_VXWORKS
  489. /* VxWorks simulator incorrectly detects building for i386 */
  490. #ifdef VXWORKS_SIM
  491. #define TFM_NO_ASM
  492. #endif
  493. /* For VxWorks pthreads wrappers for mutexes uncomment the next line. */
  494. /* #define WOLFSSL_PTHREADS */
  495. #define WOLFSSL_HAVE_MIN
  496. #define WOLFSSL_HAVE_MAX
  497. #define NO_MAIN_DRIVER
  498. #define NO_DEV_RANDOM
  499. #define NO_WRITEV
  500. #define HAVE_STRINGS_H
  501. #endif
  502. #ifdef WOLFSSL_ARDUINO
  503. #define NO_WRITEV
  504. #define NO_WOLFSSL_DIR
  505. #define SINGLE_THREADED
  506. #define NO_DEV_RANDOM
  507. #ifndef INTEL_GALILEO /* Galileo has time.h compatibility */
  508. #define TIME_OVERRIDES
  509. #ifndef XTIME
  510. #error "Must define XTIME externally see porting guide"
  511. #error "https://www.wolfssl.com/docs/porting-guide/"
  512. #endif
  513. #ifndef XGMTIME
  514. #error "Must define XGMTIME externally see porting guide"
  515. #error "https://www.wolfssl.com/docs/porting-guide/"
  516. #endif
  517. #endif
  518. #define WOLFSSL_USER_IO
  519. #define HAVE_ECC
  520. #define NO_DH
  521. #define NO_SESSION_CACHE
  522. #endif
  523. #ifdef WOLFSSL_UTASKER
  524. /* uTasker configuration - used for fnRandom() */
  525. #include "config.h"
  526. #define SINGLE_THREADED
  527. #define NO_WOLFSSL_DIR
  528. #define WOLFSSL_HAVE_MIN
  529. #define NO_WRITEV
  530. #define HAVE_ECC
  531. #define ALT_ECC_SIZE
  532. #define TFM_TIMING_RESISTANT
  533. #define ECC_TIMING_RESISTANT
  534. /* used in wolfCrypt test */
  535. #define NO_MAIN_DRIVER
  536. #define USE_CERT_BUFFERS_2048
  537. /* uTasker port uses RAW sockets, use I/O callbacks
  538. * See wolfSSL uTasker example for sample callbacks */
  539. #define WOLFSSL_USER_IO
  540. /* uTasker filesystem not ported */
  541. #define NO_FILESYSTEM
  542. /* uTasker RNG is abstracted, calls HW RNG when available */
  543. #define CUSTOM_RAND_GENERATE fnRandom
  544. #define CUSTOM_RAND_TYPE unsigned short
  545. /* user needs to define XTIME to function that provides
  546. * seconds since Unix epoch */
  547. #ifndef XTIME
  548. #error XTIME must be defined in wolfSSL settings.h
  549. /* #define XTIME fnSecondsSinceEpoch */
  550. #endif
  551. /* use uTasker std library replacements where available */
  552. #define STRING_USER
  553. #define XMEMCPY(d,s,l) uMemcpy((d),(s),(l))
  554. #define XMEMSET(b,c,l) uMemset((b),(c),(l))
  555. #define XMEMCMP(s1,s2,n) uMemcmp((s1),(s2),(n))
  556. #define XMEMMOVE(d,s,l) memmove((d),(s),(l))
  557. #define XSTRLEN(s1) uStrlen((s1))
  558. #define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
  559. #define XSTRSTR(s1,s2) strstr((s1),(s2))
  560. #define XSTRNSTR(s1,s2,n) mystrnstr((s1),(s2),(n))
  561. #define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
  562. #define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
  563. #define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
  564. #if defined(WOLFSSL_CERT_EXT) || defined(OPENSSL_EXTRA) \
  565. || defined(HAVE_ALPN)
  566. #define XSTRTOK strtok_r
  567. #endif
  568. #endif
  569. #ifdef WOLFSSL_EMBOS
  570. #define NO_FILESYSTEM /* Not ported at this time */
  571. #define USE_CERT_BUFFERS_2048 /* use when NO_FILESYSTEM */
  572. #define NO_MAIN_DRIVER
  573. #define NO_RC4
  574. #endif
  575. #ifdef WOLFSSL_RIOT_OS
  576. #define TFM_NO_ASM
  577. #define NO_FILESYSTEM
  578. #define USE_CERT_BUFFERS_2048
  579. #if defined(WOLFSSL_GNRC) && !defined(WOLFSSL_DTLS)
  580. #define WOLFSSL_DTLS
  581. #endif
  582. #endif
  583. #ifdef WOLFSSL_CHIBIOS
  584. /* ChibiOS definitions. This file is distributed with chibiOS. */
  585. #include "wolfssl_chibios.h"
  586. #endif
  587. #ifdef WOLFSSL_PB
  588. /* PB is using older 1.2 version of Nucleus */
  589. #undef WOLFSSL_NUCLEUS
  590. #define WOLFSSL_NUCLEUS_1_2
  591. #endif
  592. #ifdef WOLFSSL_NUCLEUS_1_2
  593. #define NO_WRITEV
  594. #define NO_WOLFSSL_DIR
  595. #if !defined(NO_ASN_TIME) && !defined(USER_TIME)
  596. #error User must define XTIME, see manual
  597. #endif
  598. #if !defined(XMALLOC_OVERRIDE) && !defined(XMALLOC_USER)
  599. extern void* nucleus_malloc(unsigned long size, void* heap, int type);
  600. extern void* nucleus_realloc(void* ptr, unsigned long size, void* heap,
  601. int type);
  602. extern void nucleus_free(void* ptr, void* heap, int type);
  603. #define XMALLOC(s, h, type) nucleus_malloc((s), (h), (type))
  604. #define XREALLOC(p, n, h, t) nucleus_realloc((p), (n), (h), (t))
  605. #define XFREE(p, h, type) nucleus_free((p), (h), (type))
  606. #endif
  607. #endif
  608. #ifdef WOLFSSL_NRF5x
  609. #define SIZEOF_LONG 4
  610. #define SIZEOF_LONG_LONG 8
  611. #define NO_DEV_RANDOM
  612. #define NO_FILESYSTEM
  613. #define NO_MAIN_DRIVER
  614. #define NO_WRITEV
  615. #define SINGLE_THREADED
  616. #define TFM_TIMING_RESISTANT
  617. #define WOLFSSL_NRF51
  618. #define WOLFSSL_USER_IO
  619. #define NO_SESSION_CACHE
  620. #endif
  621. /* Micrium will use Visual Studio for compilation but not the Win32 API */
  622. #if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) && \
  623. !defined(FREERTOS_TCP) && !defined(EBSNET) && !defined(WOLFSSL_EROAD) && \
  624. !defined(WOLFSSL_UTASKER) && !defined(INTIME_RTOS)
  625. #define USE_WINDOWS_API
  626. #endif
  627. #if defined(WOLFSSL_uITRON4)
  628. #define XMALLOC_USER
  629. #include <stddef.h>
  630. #define ITRON_POOL_SIZE 1024*20
  631. extern int uITRON4_minit(size_t poolsz) ;
  632. extern void *uITRON4_malloc(size_t sz) ;
  633. extern void *uITRON4_realloc(void *p, size_t sz) ;
  634. extern void uITRON4_free(void *p) ;
  635. #define XMALLOC(sz, heap, type) uITRON4_malloc(sz)
  636. #define XREALLOC(p, sz, heap, type) uITRON4_realloc(p, sz)
  637. #define XFREE(p, heap, type) uITRON4_free(p)
  638. #endif
  639. #if defined(WOLFSSL_uTKERNEL2)
  640. #ifndef NO_TKERNEL_MEM_POOL
  641. #define XMALLOC_OVERRIDE
  642. int uTKernel_init_mpool(unsigned int sz); /* initializing malloc pool */
  643. void* uTKernel_malloc(unsigned int sz);
  644. void* uTKernel_realloc(void *p, unsigned int sz);
  645. void uTKernel_free(void *p);
  646. #define XMALLOC(s, h, type) uTKernel_malloc((s))
  647. #define XREALLOC(p, n, h, t) uTKernel_realloc((p), (n))
  648. #define XFREE(p, h, type) uTKernel_free((p))
  649. #endif
  650. #ifndef NO_STDIO_FGETS_REMAP
  651. #include <stdio.h>
  652. #include "tm/tmonitor.h"
  653. /* static char* gets(char *buff); */
  654. static char* fgets(char *buff, int sz, XFILE fp) {
  655. char * s = buff;
  656. *s = '\0';
  657. while (1) {
  658. *s = tm_getchar(-1);
  659. tm_putchar(*s);
  660. if (*s == '\r') {
  661. tm_putchar('\n');
  662. *s = '\0';
  663. break;
  664. }
  665. s++;
  666. }
  667. return buff;
  668. }
  669. #endif /* !NO_STDIO_FGETS_REMAP */
  670. #endif
  671. #if defined(WOLFSSL_LEANPSK) && !defined(XMALLOC_USER) && \
  672. !defined(NO_WOLFSSL_MEMORY)
  673. #include <stdlib.h>
  674. #define XMALLOC(s, h, type) malloc((s))
  675. #define XFREE(p, h, type) free((p))
  676. #define XREALLOC(p, n, h, t) realloc((p), (n))
  677. #endif
  678. #if defined(XMALLOC_USER) && defined(SSN_BUILDING_LIBYASSL)
  679. #undef XMALLOC
  680. #define XMALLOC yaXMALLOC
  681. #undef XFREE
  682. #define XFREE yaXFREE
  683. #undef XREALLOC
  684. #define XREALLOC yaXREALLOC
  685. #endif
  686. #ifdef FREERTOS
  687. #include "FreeRTOS.h"
  688. #include <task.h>
  689. #if !defined(XMALLOC_USER) && !defined(NO_WOLFSSL_MEMORY) && \
  690. !defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFSSL_TRACK_MEMORY)
  691. #define XMALLOC(s, h, type) pvPortMalloc((s))
  692. #define XFREE(p, h, type) vPortFree((p))
  693. #if defined(WOLFSSL_ESPIDF)
  694. /* In IDF, realloc(p, n) is equivalent to
  695. * heap_caps_realloc(p, s, MALLOC_CAP_8BIT) */
  696. #define XREALLOC(p, n, h, t) realloc((p), (n))
  697. /* FreeRTOS pvPortRealloc() implementation can be found here:
  698. * https://github.com/wolfSSL/wolfssl-freertos/pull/3/files */
  699. #elif defined(USE_INTEGER_HEAP_MATH) || defined(OPENSSL_EXTRA)
  700. #define XREALLOC(p, n, h, t) pvPortRealloc((p), (n))
  701. #endif
  702. #endif
  703. #ifndef NO_WRITEV
  704. #define NO_WRITEV
  705. #endif
  706. #ifndef HAVE_SHA512
  707. #ifndef NO_SHA512
  708. #define NO_SHA512
  709. #endif
  710. #endif
  711. #ifndef HAVE_DH
  712. #ifndef NO_DH
  713. #define NO_DH
  714. #endif
  715. #endif
  716. #ifndef NO_DSA
  717. #define NO_DSA
  718. #endif
  719. #ifndef SINGLE_THREADED
  720. #include "semphr.h"
  721. #endif
  722. #endif
  723. #ifdef FREERTOS_TCP
  724. #if !defined(NO_WOLFSSL_MEMORY) && !defined(XMALLOC_USER) && \
  725. !defined(WOLFSSL_STATIC_MEMORY)
  726. #define XMALLOC(s, h, type) pvPortMalloc((s))
  727. #define XFREE(p, h, type) vPortFree((p))
  728. #endif
  729. #define WOLFSSL_GENSEED_FORTEST
  730. #define NO_WOLFSSL_DIR
  731. #define NO_WRITEV
  732. #define TFM_TIMING_RESISTANT
  733. #define NO_MAIN_DRIVER
  734. #endif
  735. #ifdef WOLFSSL_TI_CRYPT
  736. #define NO_GCM_ENCRYPT_EXTRA
  737. #define NO_PUBLIC_GCM_SET_IV
  738. #define NO_PUBLIC_CCM_SET_NONCE
  739. #endif
  740. #ifdef WOLFSSL_TIRTOS
  741. #define SIZEOF_LONG_LONG 8
  742. #define NO_WRITEV
  743. #define NO_WOLFSSL_DIR
  744. /* Enable SP math by default, unless fast math
  745. * specified in user_settings.
  746. */
  747. #ifndef USE_FAST_MATH
  748. #define WOLFSSL_HAVE_SP_ECC
  749. #define SP_WORD_SIZE 32
  750. #define WOLFSSL_HAVE_SP_RSA
  751. #define WOLFSSL_SP_4096
  752. #endif
  753. #define TFM_TIMING_RESISTANT
  754. #define ECC_TIMING_RESISTANT
  755. #define WC_RSA_BLINDING
  756. #define NO_DEV_RANDOM
  757. #define NO_FILESYSTEM
  758. #define NO_SIG_WRAPPER
  759. #define NO_MAIN_DRIVER
  760. #define USE_CERT_BUFFERS_2048
  761. #define NO_ERROR_STRINGS
  762. /* Uncomment this setting if your toolchain does not offer time.h header */
  763. /* #define USER_TIME */
  764. #define HAVE_ECC
  765. #define HAVE_ALPN
  766. #define USE_WOLF_STRTOK /* use with HAVE_ALPN */
  767. #define HAVE_TLS_EXTENSIONS
  768. #define HAVE_AESGCM
  769. #define HAVE_SUPPORTED_CURVES
  770. #ifdef __IAR_SYSTEMS_ICC__
  771. #pragma diag_suppress=Pa089
  772. #elif !defined(__GNUC__)
  773. /* Suppress the sslpro warning */
  774. #pragma diag_suppress=11
  775. #endif
  776. #include <ti/sysbios/hal/Seconds.h>
  777. #endif
  778. #ifdef EBSNET
  779. #include "rtip.h"
  780. /* #define DEBUG_WOLFSSL */
  781. #define NO_WOLFSSL_DIR /* tbd */
  782. #if (POLLOS)
  783. #define SINGLE_THREADED
  784. #endif
  785. #if (defined(RTPLATFORM) && (RTPLATFORM != 0))
  786. #if (!RTP_LITTLE_ENDIAN)
  787. #define BIG_ENDIAN_ORDER
  788. #endif
  789. #else
  790. #if (!KS_LITTLE_ENDIAN)
  791. #define BIG_ENDIAN_ORDER
  792. #endif
  793. #endif
  794. #if (WINMSP3)
  795. #undef SIZEOF_LONG
  796. #define SIZEOF_LONG_LONG 8
  797. #else
  798. #if !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
  799. #error settings.h - please implement SIZEOF_LONG and SIZEOF_LONG_LONG
  800. #endif
  801. #endif
  802. #if (WINMSP3)
  803. #define strtok_r strtok_s
  804. #endif
  805. #define XMALLOC(s, h, type) ((void *)rtp_malloc((s), SSL_PRO_MALLOC))
  806. #define XFREE(p, h, type) (rtp_free(p))
  807. #define XREALLOC(p, n, h, t) (rtp_realloc((p), (n), (t)))
  808. #if (WINMSP3)
  809. #define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
  810. #else
  811. #ifndef XSTRNCASECMP
  812. #error settings.h - please implement XSTRNCASECMP - needed for HAVE_ECC
  813. #endif
  814. #endif
  815. #define WOLFSSL_HAVE_MAX
  816. #define WOLFSSL_HAVE_MIN
  817. #define TFM_TIMING_RESISTANT
  818. #define WC_RSA_BLINDING
  819. #define ECC_TIMING_RESISTANT
  820. #define HAVE_ECC
  821. #endif /* EBSNET */
  822. #ifdef WOLFSSL_GAME_BUILD
  823. #define SIZEOF_LONG_LONG 8
  824. #endif
  825. #ifdef WOLFSSL_LSR
  826. #define HAVE_WEBSERVER
  827. #define SIZEOF_LONG_LONG 8
  828. #define WOLFSSL_LOW_MEMORY
  829. #define NO_WRITEV
  830. #define NO_SHA512
  831. #define NO_DH
  832. /* Allows use of DH with fixed points if uncommented and NO_DH is removed */
  833. /* WOLFSSL_DH_CONST */
  834. #define NO_DSA
  835. #define NO_DEV_RANDOM
  836. #define NO_WOLFSSL_DIR
  837. #ifndef NO_FILESYSTEM
  838. #define LSR_FS
  839. #include "inc/hw_types.h"
  840. #include "fs.h"
  841. #endif
  842. #define WOLFSSL_LWIP
  843. #include <errno.h> /* for tcp errno */
  844. #define WOLFSSL_SAFERTOS
  845. #if defined(__IAR_SYSTEMS_ICC__)
  846. /* enum uses enum */
  847. #pragma diag_suppress=Pa089
  848. #endif
  849. #endif
  850. #ifdef WOLFSSL_SAFERTOS
  851. #ifndef SINGLE_THREADED
  852. #include "SafeRTOS/semphr.h"
  853. #endif
  854. #ifndef WOLFSSL_NO_MALLOC
  855. #include "SafeRTOS/heap.h"
  856. #endif
  857. #if !defined(XMALLOC_USER) && !defined(NO_WOLFSSL_MEMORY) && \
  858. !defined(WOLFSSL_STATIC_MEMORY)
  859. #define XMALLOC(s, h, type) pvPortMalloc((s))
  860. #define XFREE(p, h, type) vPortFree((p))
  861. /* FreeRTOS pvPortRealloc() implementation can be found here:
  862. https://github.com/wolfSSL/wolfssl-freertos/pull/3/files */
  863. #if !defined(USE_FAST_MATH) || defined(HAVE_ED25519) || \
  864. defined(HAVE_ED448)
  865. #define XREALLOC(p, n, h, t) pvPortRealloc((p), (n))
  866. #endif
  867. #endif
  868. #endif
  869. #ifdef WOLFSSL_LOW_MEMORY
  870. #undef RSA_LOW_MEM
  871. #define RSA_LOW_MEM
  872. #undef WOLFSSL_SMALL_STACK
  873. #define WOLFSSL_SMALL_STACK
  874. #undef TFM_TIMING_RESISTANT
  875. #define TFM_TIMING_RESISTANT
  876. #endif
  877. /* To support storing some of the large constant tables in flash memory rather than SRAM.
  878. Useful for processors that have limited SRAM, such as the AVR family of microtrollers. */
  879. #ifdef WOLFSSL_USE_FLASHMEM
  880. /* This is supported on the avr-gcc compiler, for more information see:
  881. https://gcc.gnu.org/onlinedocs/gcc/Named-Address-Spaces.html */
  882. #define FLASH_QUALIFIER __flash
  883. /* Copy data out of flash memory and into SRAM */
  884. #define XMEMCPY_P(pdest, psrc, size) memcpy_P((pdest), (psrc), (size))
  885. #else
  886. #define FLASH_QUALIFIER
  887. #endif
  888. #ifdef FREESCALE_MQX_5_0
  889. /* use normal Freescale MQX port, but with minor changes for 5.0 */
  890. #define FREESCALE_MQX
  891. #endif
  892. #ifdef FREESCALE_MQX_4_0
  893. /* use normal Freescale MQX port, but with minor changes for 4.0 */
  894. #define FREESCALE_MQX
  895. #endif
  896. #ifdef FREESCALE_MQX
  897. #define FREESCALE_COMMON
  898. #include "mqx.h"
  899. #ifndef NO_FILESYSTEM
  900. #include "mfs.h"
  901. #if (defined(MQX_USE_IO_OLD) && MQX_USE_IO_OLD) || \
  902. defined(FREESCALE_MQX_5_0)
  903. #include "fio.h"
  904. #define NO_STDIO_FILESYSTEM
  905. #else
  906. #include "nio.h"
  907. #endif
  908. #endif
  909. #ifndef SINGLE_THREADED
  910. #include "mutex.h"
  911. #endif
  912. #if !defined(XMALLOC_OVERRIDE) && !defined(XMALLOC_USER)
  913. #define XMALLOC_OVERRIDE
  914. #define XMALLOC(s, h, t) (void *)_mem_alloc_system((s))
  915. #define XFREE(p, h, t) {void* xp = (p); if ((xp)) _mem_free((xp));}
  916. /* Note: MQX has no realloc, using fastmath above */
  917. #endif
  918. #ifdef USE_FAST_MATH
  919. /* Undef first to avoid re-definition if user_settings.h defines */
  920. #undef TFM_TIMING_RESISTANT
  921. #define TFM_TIMING_RESISTANT
  922. #undef ECC_TIMING_RESISTANT
  923. #define ECC_TIMING_RESISTANT
  924. #undef WC_RSA_BLINDING
  925. #define WC_RSA_BLINDING
  926. #endif
  927. #endif
  928. #ifdef FREESCALE_KSDK_MQX
  929. #define FREESCALE_COMMON
  930. #include <mqx.h>
  931. #ifndef NO_FILESYSTEM
  932. #if (defined(MQX_USE_IO_OLD) && MQX_USE_IO_OLD) || \
  933. defined(FREESCALE_MQX_5_0)
  934. #include <fio.h>
  935. #else
  936. #include <stdio.h>
  937. #include <nio.h>
  938. #endif
  939. #endif
  940. #ifndef SINGLE_THREADED
  941. #include <mutex.h>
  942. #endif
  943. #define XMALLOC(s, h, t) (void *)_mem_alloc_system((s))
  944. #define XFREE(p, h, t) {void* xp = (p); if ((xp)) _mem_free((xp));}
  945. #define XREALLOC(p, n, h, t) _mem_realloc((p), (n)) /* since MQX 4.1.2 */
  946. #define MQX_FILE_PTR FILE *
  947. #define IO_SEEK_SET SEEK_SET
  948. #define IO_SEEK_END SEEK_END
  949. #endif /* FREESCALE_KSDK_MQX */
  950. #if defined(FREESCALE_FREE_RTOS) || defined(FREESCALE_KSDK_FREERTOS)
  951. #define NO_FILESYSTEM
  952. #define WOLFSSL_CRYPT_HW_MUTEX 1
  953. #if !defined(XMALLOC_USER) && !defined(NO_WOLFSSL_MEMORY)
  954. #define XMALLOC(s, h, type) pvPortMalloc((s))
  955. #define XFREE(p, h, type) vPortFree((p))
  956. #endif
  957. /* #define USER_TICKS */
  958. /* Allows use of DH with fixed points if uncommented and NO_DH is removed */
  959. /* WOLFSSL_DH_CONST */
  960. #define WOLFSSL_LWIP
  961. #define FREERTOS_TCP
  962. #define FREESCALE_FREE_RTOS
  963. #define FREERTOS_SOCKET_ERROR ( -1 )
  964. #define FREERTOS_EWOULDBLOCK ( -2 )
  965. #define FREERTOS_EINVAL ( -4 )
  966. #define FREERTOS_EADDRNOTAVAIL ( -5 )
  967. #define FREERTOS_EADDRINUSE ( -6 )
  968. #define FREERTOS_ENOBUFS ( -7 )
  969. #define FREERTOS_ENOPROTOOPT ( -8 )
  970. #endif /* FREESCALE_FREE_RTOS || FREESCALE_KSDK_FREERTOS */
  971. #ifdef FREESCALE_KSDK_BM
  972. #define FREESCALE_COMMON
  973. #define WOLFSSL_USER_IO
  974. #define SINGLE_THREADED
  975. #define NO_FILESYSTEM
  976. #ifndef TIME_OVERRIDES
  977. #define USER_TICKS
  978. #endif
  979. #endif /* FREESCALE_KSDK_BM */
  980. #ifdef FREESCALE_COMMON
  981. #define SIZEOF_LONG_LONG 8
  982. /* disable features */
  983. #undef NO_WRITEV
  984. #define NO_WRITEV
  985. #undef NO_DEV_RANDOM
  986. #define NO_DEV_RANDOM
  987. #undef NO_WOLFSSL_DIR
  988. #define NO_WOLFSSL_DIR
  989. #undef NO_RC4
  990. #define NO_RC4
  991. /* enable features */
  992. #define USE_CERT_BUFFERS_2048
  993. #define BENCH_EMBEDDED
  994. #define TFM_TIMING_RESISTANT
  995. #define ECC_TIMING_RESISTANT
  996. #undef HAVE_ECC
  997. #ifndef WOLFCRYPT_FIPS_RAND
  998. #define HAVE_ECC
  999. #endif
  1000. #ifndef NO_AES
  1001. #undef HAVE_AESCCM
  1002. #define HAVE_AESCCM
  1003. #undef HAVE_AESGCM
  1004. #define HAVE_AESGCM
  1005. #undef WOLFSSL_AES_COUNTER
  1006. #define WOLFSSL_AES_COUNTER
  1007. #undef WOLFSSL_AES_DIRECT
  1008. #define WOLFSSL_AES_DIRECT
  1009. #endif
  1010. #ifdef FREESCALE_KSDK_1_3
  1011. #include "fsl_device_registers.h"
  1012. #elif !defined(FREESCALE_MQX)
  1013. /* Classic MQX does not have fsl_common.h */
  1014. #include "fsl_common.h"
  1015. #endif
  1016. /* random seed */
  1017. #define NO_OLD_RNGNAME
  1018. #if defined(FREESCALE_NO_RNG)
  1019. /* nothing to define */
  1020. #elif defined(FSL_FEATURE_SOC_TRNG_COUNT) && (FSL_FEATURE_SOC_TRNG_COUNT > 0)
  1021. #define FREESCALE_KSDK_2_0_TRNG
  1022. #elif defined(FSL_FEATURE_SOC_RNG_COUNT) && (FSL_FEATURE_SOC_RNG_COUNT > 0)
  1023. #ifdef FREESCALE_KSDK_1_3
  1024. #include "fsl_rnga_driver.h"
  1025. #define FREESCALE_RNGA
  1026. #define RNGA_INSTANCE (0)
  1027. #else
  1028. #define FREESCALE_KSDK_2_0_RNGA
  1029. #endif
  1030. #elif !defined(FREESCALE_KSDK_BM) && !defined(FREESCALE_FREE_RTOS) && !defined(FREESCALE_KSDK_FREERTOS)
  1031. #define FREESCALE_RNGA
  1032. #define RNGA_INSTANCE (0)
  1033. /* defaulting to K70 RNGA, user should change if different */
  1034. /* #define FREESCALE_K53_RNGB */
  1035. #define FREESCALE_K70_RNGA
  1036. #endif
  1037. /* HW crypto */
  1038. /* automatic enable based on Kinetis feature */
  1039. /* if case manual selection is required, for example for benchmarking purposes,
  1040. * just define FREESCALE_USE_MMCAU or FREESCALE_USE_LTC or none of these two macros (for software only)
  1041. * both can be enabled simultaneously as LTC has priority over MMCAU in source code.
  1042. */
  1043. /* #define FSL_HW_CRYPTO_MANUAL_SELECTION */
  1044. #ifndef FSL_HW_CRYPTO_MANUAL_SELECTION
  1045. #if defined(FSL_FEATURE_SOC_MMCAU_COUNT) && FSL_FEATURE_SOC_MMCAU_COUNT
  1046. #define FREESCALE_USE_MMCAU
  1047. #endif
  1048. #if defined(FSL_FEATURE_SOC_LTC_COUNT) && FSL_FEATURE_SOC_LTC_COUNT
  1049. #define FREESCALE_USE_LTC
  1050. #endif
  1051. #else
  1052. /* #define FREESCALE_USE_MMCAU */
  1053. /* #define FREESCALE_USE_LTC */
  1054. #endif
  1055. #endif /* FREESCALE_COMMON */
  1056. /* Classic pre-KSDK mmCAU library */
  1057. #ifdef FREESCALE_USE_MMCAU_CLASSIC
  1058. #define FREESCALE_USE_MMCAU
  1059. #define FREESCALE_MMCAU_CLASSIC
  1060. #define FREESCALE_MMCAU_CLASSIC_SHA
  1061. #endif
  1062. /* KSDK mmCAU library */
  1063. #ifdef FREESCALE_USE_MMCAU
  1064. /* AES and DES */
  1065. #define FREESCALE_MMCAU
  1066. /* MD5, SHA-1 and SHA-256 */
  1067. #define FREESCALE_MMCAU_SHA
  1068. #endif /* FREESCALE_USE_MMCAU */
  1069. #ifdef FREESCALE_USE_LTC
  1070. #if defined(FSL_FEATURE_SOC_LTC_COUNT) && FSL_FEATURE_SOC_LTC_COUNT
  1071. #define FREESCALE_LTC
  1072. #define LTC_BASE LTC0
  1073. #if defined(FSL_FEATURE_LTC_HAS_DES) && FSL_FEATURE_LTC_HAS_DES
  1074. #define FREESCALE_LTC_DES
  1075. #endif
  1076. #if defined(FSL_FEATURE_LTC_HAS_GCM) && FSL_FEATURE_LTC_HAS_GCM
  1077. #define FREESCALE_LTC_AES_GCM
  1078. #endif
  1079. #if defined(FSL_FEATURE_LTC_HAS_SHA) && FSL_FEATURE_LTC_HAS_SHA
  1080. #define FREESCALE_LTC_SHA
  1081. #endif
  1082. #if defined(FSL_FEATURE_LTC_HAS_PKHA) && FSL_FEATURE_LTC_HAS_PKHA
  1083. #ifndef WOLFCRYPT_FIPS_RAND
  1084. #define FREESCALE_LTC_ECC
  1085. #endif
  1086. #define FREESCALE_LTC_TFM
  1087. /* the LTC PKHA hardware limit is 2048 bits (256 bytes) for integer arithmetic.
  1088. the LTC_MAX_INT_BYTES defines the size of local variables that hold big integers. */
  1089. /* size is multiplication of 2 big ints */
  1090. #if !defined(NO_RSA) || !defined(NO_DH)
  1091. #define LTC_MAX_INT_BYTES (256*2)
  1092. #else
  1093. #define LTC_MAX_INT_BYTES (48*2)
  1094. #endif
  1095. /* This FREESCALE_LTC_TFM_RSA_4096_ENABLE macro can be defined.
  1096. * In such a case both software and hardware algorithm
  1097. * for TFM is linked in. The decision for which algorithm is used is determined at runtime
  1098. * from size of inputs. If inputs and result can fit into LTC (see LTC_MAX_INT_BYTES)
  1099. * then we call hardware algorithm, otherwise we call software algorithm.
  1100. *
  1101. * Chinese reminder theorem is used to break RSA 4096 exponentiations (both public and private key)
  1102. * into several computations with 2048-bit modulus and exponents.
  1103. */
  1104. /* #define FREESCALE_LTC_TFM_RSA_4096_ENABLE */
  1105. /* ECC-384, ECC-256, ECC-224 and ECC-192 have been enabled with LTC PKHA acceleration */
  1106. #ifdef HAVE_ECC
  1107. #undef ECC_TIMING_RESISTANT
  1108. #define ECC_TIMING_RESISTANT
  1109. /* the LTC PKHA hardware limit is 512 bits (64 bytes) for ECC.
  1110. the LTC_MAX_ECC_BITS defines the size of local variables that hold ECC parameters
  1111. and point coordinates */
  1112. #ifndef LTC_MAX_ECC_BITS
  1113. #define LTC_MAX_ECC_BITS (384)
  1114. #endif
  1115. /* Enable curves up to 384 bits */
  1116. #if !defined(ECC_USER_CURVES) && !defined(HAVE_ALL_CURVES)
  1117. #define ECC_USER_CURVES
  1118. #define HAVE_ECC192
  1119. #define HAVE_ECC224
  1120. #undef NO_ECC256
  1121. #define HAVE_ECC384
  1122. #endif
  1123. #endif
  1124. #endif
  1125. #endif
  1126. #endif /* FREESCALE_USE_LTC */
  1127. #ifdef FREESCALE_LTC_TFM_RSA_4096_ENABLE
  1128. #undef USE_CERT_BUFFERS_4096
  1129. #define USE_CERT_BUFFERS_4096
  1130. #undef FP_MAX_BITS
  1131. #define FP_MAX_BITS (8192)
  1132. #undef SP_INT_BITS
  1133. #define SP_INT_BITS (4096)
  1134. #undef NO_DH
  1135. #define NO_DH
  1136. #undef NO_DSA
  1137. #define NO_DSA
  1138. #endif /* FREESCALE_LTC_TFM_RSA_4096_ENABLE */
  1139. /* if LTC has AES engine but doesn't have GCM, use software with LTC AES ECB mode */
  1140. #if defined(FREESCALE_USE_LTC) && !defined(FREESCALE_LTC_AES_GCM)
  1141. #define GCM_TABLE
  1142. #endif
  1143. #if defined(WOLFSSL_MAXQ1065) || defined(WOLFSSL_MAXQ108X)
  1144. #define MAXQ10XX_MODULE_INIT
  1145. #define HAVE_PK_CALLBACKS
  1146. #define WOLFSSL_STATIC_PSK
  1147. /* Server side support to be added at a later date. */
  1148. #define NO_WOLFSSL_SERVER
  1149. /* Need WOLFSSL_PUBLIC_ASN to use ProcessPeerCert callback. */
  1150. #define WOLFSSL_PUBLIC_ASN
  1151. #ifdef HAVE_PTHREAD
  1152. #define WOLFSSL_CRYPT_HW_MUTEX 1
  1153. #define MAXQ10XX_MUTEX
  1154. #endif
  1155. #define WOLFSSL_MAXQ10XX_CRYPTO
  1156. #define WOLFSSL_MAXQ10XX_TLS
  1157. #if defined(WOLFSSL_MAXQ1065)
  1158. #define MAXQ_DEVICE_ID 1065
  1159. #elif defined(WOLFSSL_MAXQ108X)
  1160. #define MAXQ_DEVICE_ID 1080
  1161. #else
  1162. #error "There is only support for MAXQ1065 or MAXQ1080"
  1163. #endif
  1164. #if defined(WOLFSSL_TICKET_NONCE_MALLOC)
  1165. #error "WOLFSSL_TICKET_NONCE_MALLOC disables the HKDF expand callbacks."
  1166. #endif
  1167. #endif /* WOLFSSL_MAXQ1065 || WOLFSSL_MAXQ108X */
  1168. #if defined(WOLFSSL_STM32F2) || defined(WOLFSSL_STM32F4) || \
  1169. defined(WOLFSSL_STM32F7) || defined(WOLFSSL_STM32F1) || \
  1170. defined(WOLFSSL_STM32L4) || defined(WOLFSSL_STM32L5) || \
  1171. defined(WOLFSSL_STM32WB) || defined(WOLFSSL_STM32H7) || \
  1172. defined(WOLFSSL_STM32G0) || defined(WOLFSSL_STM32U5) || \
  1173. defined(WOLFSSL_STM32H5)
  1174. #define SIZEOF_LONG_LONG 8
  1175. #ifndef CHAR_BIT
  1176. #define CHAR_BIT 8
  1177. #endif
  1178. #define NO_DEV_RANDOM
  1179. #define NO_WOLFSSL_DIR
  1180. #ifndef NO_STM32_RNG
  1181. #undef STM32_RNG
  1182. #define STM32_RNG
  1183. #ifdef WOLFSSL_STM32F427_RNG
  1184. #include "stm32f427xx.h"
  1185. #endif
  1186. #endif
  1187. #ifndef NO_STM32_CRYPTO
  1188. #undef STM32_CRYPTO
  1189. #define STM32_CRYPTO
  1190. #if defined(WOLFSSL_STM32L4) || defined(WOLFSSL_STM32L5) || \
  1191. defined(WOLFSSL_STM32WB) || defined(WOLFSSL_STM32U5)
  1192. #define NO_AES_192 /* hardware does not support 192-bit */
  1193. #endif
  1194. #endif
  1195. #ifndef NO_STM32_HASH
  1196. #undef STM32_HASH
  1197. #define STM32_HASH
  1198. #endif
  1199. #if !defined(__GNUC__) && !defined(__ICCARM__)
  1200. #define KEIL_INTRINSICS
  1201. #endif
  1202. #define NO_OLD_RNGNAME
  1203. #ifdef WOLFSSL_STM32_CUBEMX
  1204. #if defined(WOLFSSL_STM32F1)
  1205. #include "stm32f1xx_hal.h"
  1206. #elif defined(WOLFSSL_STM32F2)
  1207. #include "stm32f2xx_hal.h"
  1208. #elif defined(WOLFSSL_STM32L5)
  1209. #include "stm32l5xx_hal.h"
  1210. #elif defined(WOLFSSL_STM32L4)
  1211. #include "stm32l4xx_hal.h"
  1212. #elif defined(WOLFSSL_STM32F4)
  1213. #include "stm32f4xx_hal.h"
  1214. #elif defined(WOLFSSL_STM32F7)
  1215. #include "stm32f7xx_hal.h"
  1216. #elif defined(WOLFSSL_STM32F1)
  1217. #include "stm32f1xx_hal.h"
  1218. #elif defined(WOLFSSL_STM32H7)
  1219. #include "stm32h7xx_hal.h"
  1220. #elif defined(WOLFSSL_STM32WB)
  1221. #include "stm32wbxx_hal.h"
  1222. #elif defined(WOLFSSL_STM32G0)
  1223. #include "stm32g0xx_hal.h"
  1224. #elif defined(WOLFSSL_STM32U5)
  1225. #include "stm32u5xx_hal.h"
  1226. #elif defined(WOLFSSL_STM32H5)
  1227. #include "stm32h5xx_hal.h"
  1228. #endif
  1229. #if defined(WOLFSSL_CUBEMX_USE_LL) && defined(WOLFSSL_STM32L4)
  1230. #include "stm32l4xx_ll_rng.h"
  1231. #endif
  1232. #ifndef STM32_HAL_TIMEOUT
  1233. #define STM32_HAL_TIMEOUT 0xFF
  1234. #endif
  1235. #else
  1236. #if defined(WOLFSSL_STM32F2)
  1237. #include "stm32f2xx.h"
  1238. #ifdef STM32_CRYPTO
  1239. #include "stm32f2xx_cryp.h"
  1240. #endif
  1241. #ifdef STM32_HASH
  1242. #include "stm32f2xx_hash.h"
  1243. #endif
  1244. #elif defined(WOLFSSL_STM32F4)
  1245. #include "stm32f4xx.h"
  1246. #ifdef STM32_CRYPTO
  1247. #include "stm32f4xx_cryp.h"
  1248. #endif
  1249. #ifdef STM32_HASH
  1250. #include "stm32f4xx_hash.h"
  1251. #endif
  1252. #elif defined(WOLFSSL_STM32L5)
  1253. #include "stm32l5xx.h"
  1254. #ifdef STM32_CRYPTO
  1255. #include "stm32l5xx_cryp.h"
  1256. #endif
  1257. #ifdef STM32_HASH
  1258. #include "stm32l5xx_hash.h"
  1259. #endif
  1260. #elif defined(WOLFSSL_STM32L4)
  1261. #include "stm32l4xx.h"
  1262. #ifdef STM32_CRYPTO
  1263. #include "stm32l4xx_cryp.h"
  1264. #endif
  1265. #ifdef STM32_HASH
  1266. #include "stm32l4xx_hash.h"
  1267. #endif
  1268. #elif defined(WOLFSSL_STM32F7)
  1269. #include "stm32f7xx.h"
  1270. #elif defined(WOLFSSL_STM32H7)
  1271. #include "stm32h7xx.h"
  1272. #elif defined(WOLFSSL_STM32F1)
  1273. #include "stm32f1xx.h"
  1274. #endif
  1275. #endif /* WOLFSSL_STM32_CUBEMX */
  1276. #endif /* WOLFSSL_STM32F2 || WOLFSSL_STM32F4 || WOLFSSL_STM32L4 ||
  1277. WOLFSSL_STM32L5 || WOLFSSL_STM32F7 || WOLFSSL_STMWB ||
  1278. WOLFSSL_STM32H7 || WOLFSSL_STM32G0 || WOLFSSL_STM32U5 ||
  1279. WOLFSSL_STM32H5 */
  1280. #ifdef WOLFSSL_DEOS
  1281. #include <deos.h>
  1282. #include <timeout.h>
  1283. #include <socketapi.h>
  1284. #include <lwip-socket.h>
  1285. #include <mem.h>
  1286. #include <string.h>
  1287. #include <stdlib.h> /* for rand_r: pseudo-random number generator */
  1288. #include <stdio.h> /* for snprintf */
  1289. /* use external memory XMALLOC, XFREE and XREALLOC functions */
  1290. #define XMALLOC_USER
  1291. /* disable fall-back case, malloc, realloc and free are unavailable */
  1292. #define WOLFSSL_NO_MALLOC
  1293. /* file system has not been ported since it is a separate product. */
  1294. #define NO_FILESYSTEM
  1295. #ifdef NO_FILESYSTEM
  1296. #define NO_WOLFSSL_DIR
  1297. #define NO_WRITEV
  1298. #endif
  1299. #define TFM_TIMING_RESISTANT
  1300. #define ECC_TIMING_RESISTANT
  1301. #define WC_RSA_BLINDING
  1302. #define HAVE_ECC
  1303. #define TFM_ECC192
  1304. #define TFM_ECC224
  1305. #define TFM_ECC256
  1306. #define TFM_ECC384
  1307. #define TFM_ECC521
  1308. #define HAVE_TLS_EXTENSIONS
  1309. #define HAVE_SUPPORTED_CURVES
  1310. #define HAVE_EXTENDED_MASTER
  1311. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  1312. #define BIG_ENDIAN_ORDER
  1313. #else
  1314. #undef BIG_ENDIAN_ORDER
  1315. #define LITTLE_ENDIAN_ORDER
  1316. #endif
  1317. #endif /* WOLFSSL_DEOS*/
  1318. #ifdef MICRIUM
  1319. #include <stdlib.h>
  1320. #include <os.h>
  1321. #include <app_cfg.h>
  1322. #if defined(RTOS_MODULE_NET_AVAIL) || (APP_CFG_TCPIP_EN == DEF_ENABLED)
  1323. #include <net_cfg.h>
  1324. #include <net_sock.h>
  1325. #if (OS_VERSION < 50000)
  1326. #include <net_err.h>
  1327. #endif
  1328. #endif
  1329. #include <lib_mem.h>
  1330. #include <lib_math.h>
  1331. #include <lib_str.h>
  1332. #include <stdio.h>
  1333. #include <string.h>
  1334. #define TFM_TIMING_RESISTANT
  1335. #define ECC_TIMING_RESISTANT
  1336. #define WC_RSA_BLINDING
  1337. #define HAVE_HASHDRBG
  1338. #define HAVE_ECC
  1339. #if !defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFSSL_NO_MALLOC)
  1340. #define ALT_ECC_SIZE
  1341. #endif
  1342. #define TFM_ECC192
  1343. #define TFM_ECC224
  1344. #define TFM_ECC256
  1345. #define TFM_ECC384
  1346. #define TFM_ECC521
  1347. #define NO_RC4
  1348. #define HAVE_TLS_EXTENSIONS
  1349. #define HAVE_SUPPORTED_CURVES
  1350. #define HAVE_EXTENDED_MASTER
  1351. #define NO_WOLFSSL_DIR
  1352. #define NO_WRITEV
  1353. #if !defined(WOLFSSL_SILABS_SE_ACCEL) && !defined(STM32_RNG) && \
  1354. !defined(CUSTOM_RAND_GENERATE)
  1355. #define CUSTOM_RAND_TYPE RAND_NBR
  1356. #define CUSTOM_RAND_GENERATE Math_Rand
  1357. #endif
  1358. #define STRING_USER
  1359. #define XSTRCASECMP(s1,s2) strcasecmp((s1),(s2))
  1360. #define XSTRCMP(s1,s2) strcmp((s1),(s2))
  1361. #define XSTRLEN(pstr) ((CPU_SIZE_T)Str_Len((CPU_CHAR *)(pstr)))
  1362. #define XSTRNCPY(pstr_dest, pstr_src, len_max) \
  1363. ((CPU_CHAR *)Str_Copy_N((CPU_CHAR *)(pstr_dest), \
  1364. (CPU_CHAR *)(pstr_src), (CPU_SIZE_T)(len_max)))
  1365. #define XSTRNCMP(pstr_1, pstr_2, len_max) \
  1366. ((CPU_INT16S)Str_Cmp_N((CPU_CHAR *)(pstr_1), \
  1367. (CPU_CHAR *)(pstr_2), (CPU_SIZE_T)(len_max)))
  1368. #define XSTRNCASECMP(pstr_1, pstr_2, len_max) \
  1369. ((CPU_INT16S)Str_CmpIgnoreCase_N((CPU_CHAR *)(pstr_1), \
  1370. (CPU_CHAR *)(pstr_2), (CPU_SIZE_T)(len_max)))
  1371. #define XSTRSTR(pstr, pstr_srch) \
  1372. ((CPU_CHAR *)Str_Str((CPU_CHAR *)(pstr), \
  1373. (CPU_CHAR *)(pstr_srch)))
  1374. #define XSTRNSTR(pstr, pstr_srch, len_max) \
  1375. ((CPU_CHAR *)Str_Str_N((CPU_CHAR *)(pstr), \
  1376. (CPU_CHAR *)(pstr_srch),(CPU_SIZE_T)(len_max)))
  1377. #define XSTRNCAT(pstr_dest, pstr_cat, len_max) \
  1378. ((CPU_CHAR *)Str_Cat_N((CPU_CHAR *)(pstr_dest), \
  1379. (const CPU_CHAR *)(pstr_cat),(CPU_SIZE_T)(len_max)))
  1380. #ifndef XATOI /* if custom XATOI is not already defined */
  1381. #define XATOI(s) atoi((s))
  1382. #endif
  1383. #if defined(USE_WOLF_STRTOK)
  1384. #define XSTRTOK(s1, d, ptr) wc_strtok((s1), (d), (ptr))
  1385. #else
  1386. #define XSTRTOK(s1, d, ptr) strtok_r((s1), (d), (ptr))
  1387. #endif
  1388. #define XMEMSET(pmem, data_val, size) \
  1389. ((void)Mem_Set((void *)(pmem), \
  1390. (CPU_INT08U) (data_val), \
  1391. (CPU_SIZE_T)(size)))
  1392. #define XMEMCPY(pdest, psrc, size) ((void)Mem_Copy((void *)(pdest), \
  1393. (void *)(psrc), (CPU_SIZE_T)(size)))
  1394. #if (OS_VERSION < 50000)
  1395. #define XMEMCMP(pmem_1, pmem_2, size) \
  1396. (((CPU_BOOLEAN)Mem_Cmp((void *)(pmem_1), \
  1397. (void *)(pmem_2), \
  1398. (CPU_SIZE_T)(size))) ? DEF_NO : DEF_YES)
  1399. #else
  1400. /* Work around for Micrium OS version 5.8 change in behavior
  1401. * that returns DEF_NO for 0 size compare
  1402. */
  1403. #define XMEMCMP(pmem_1, pmem_2, size) \
  1404. (( (size < 1 ) || \
  1405. ((CPU_BOOLEAN)Mem_Cmp((void *)(pmem_1), \
  1406. (void *)(pmem_2), \
  1407. (CPU_SIZE_T)(size)) == DEF_YES)) \
  1408. ? 0 : 1)
  1409. #define XSNPRINTF snprintf
  1410. #endif
  1411. #define XMEMMOVE(pdest, psrc, size) ((void)Mem_Move((void *)(pdest), \
  1412. (void *)(psrc), (CPU_SIZE_T)(size)))
  1413. #if (OS_CFG_MUTEX_EN == DEF_DISABLED)
  1414. #define SINGLE_THREADED
  1415. #endif
  1416. #if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
  1417. #define BIG_ENDIAN_ORDER
  1418. #else
  1419. #undef BIG_ENDIAN_ORDER
  1420. #define LITTLE_ENDIAN_ORDER
  1421. #endif
  1422. #endif /* MICRIUM */
  1423. #if defined(sun) || defined(__sun)
  1424. # if defined(__SVR4) || defined(__svr4__)
  1425. /* Solaris */
  1426. #ifndef WOLFSSL_SOLARIS
  1427. #define WOLFSSL_SOLARIS
  1428. #endif
  1429. # else
  1430. /* SunOS */
  1431. # endif
  1432. #endif
  1433. #ifdef WOLFSSL_SOLARIS
  1434. /* Avoid naming clash with fp_zero from math.h > ieefp.h */
  1435. #define WOLFSSL_DH_CONST
  1436. #endif
  1437. #ifdef WOLFSSL_MCF5441X
  1438. #define BIG_ENDIAN_ORDER
  1439. #ifndef SIZEOF_LONG
  1440. #define SIZEOF_LONG 4
  1441. #endif
  1442. #ifndef SIZEOF_LONG_LONG
  1443. #define SIZEOF_LONG_LONG 8
  1444. #endif
  1445. #endif
  1446. #ifdef WOLFSSL_QL
  1447. #ifndef WOLFSSL_SEP
  1448. #define WOLFSSL_SEP
  1449. #endif
  1450. #ifndef OPENSSL_EXTRA
  1451. #define OPENSSL_EXTRA
  1452. #endif
  1453. #ifndef SESSION_CERTS
  1454. #define SESSION_CERTS
  1455. #endif
  1456. #ifndef HAVE_AESCCM
  1457. #define HAVE_AESCCM
  1458. #endif
  1459. #ifndef ATOMIC_USER
  1460. #define ATOMIC_USER
  1461. #endif
  1462. #ifndef WOLFSSL_DER_LOAD
  1463. #define WOLFSSL_DER_LOAD
  1464. #endif
  1465. #ifndef KEEP_PEER_CERT
  1466. #define KEEP_PEER_CERT
  1467. #endif
  1468. #ifndef HAVE_ECC
  1469. #define HAVE_ECC
  1470. #endif
  1471. #ifndef SESSION_INDEX
  1472. #define SESSION_INDEX
  1473. #endif
  1474. #endif /* WOLFSSL_QL */
  1475. #if defined(WOLFSSL_XILINX)
  1476. #if !defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  1477. #define NO_DEV_RANDOM
  1478. #endif
  1479. #define NO_WOLFSSL_DIR
  1480. #define HAVE_AESGCM
  1481. #endif
  1482. #if defined(WOLFSSL_XILINX_CRYPT) || defined(WOLFSSL_AFALG_XILINX)
  1483. #if defined(WOLFSSL_ARMASM)
  1484. #error can not use both ARMv8 instructions and XILINX hardened crypto
  1485. #endif
  1486. #if defined(WOLFSSL_SHA3)
  1487. /* only SHA3-384 is supported */
  1488. #undef WOLFSSL_NOSHA3_224
  1489. #undef WOLFSSL_NOSHA3_256
  1490. #undef WOLFSSL_NOSHA3_512
  1491. #define WOLFSSL_NOSHA3_224
  1492. #define WOLFSSL_NOSHA3_256
  1493. #define WOLFSSL_NOSHA3_512
  1494. #endif
  1495. #ifdef WOLFSSL_AFALG_XILINX_AES
  1496. #undef WOLFSSL_AES_DIRECT
  1497. #define WOLFSSL_AES_DIRECT
  1498. #endif
  1499. #endif /*(WOLFSSL_XILINX_CRYPT)*/
  1500. #ifdef WOLFSSL_KCAPI_AES
  1501. #define WOLFSSL_AES_GCM_FIXED_IV_AAD
  1502. #endif
  1503. #ifdef WOLFSSL_KCAPI_ECC
  1504. #undef ECC_USER_CURVES
  1505. #define ECC_USER_CURVES
  1506. #undef NO_ECC256
  1507. #undef HAVE_ECC384
  1508. #define HAVE_ECC384
  1509. #undef HAVE_ECC521
  1510. #define HAVE_ECC521
  1511. #endif
  1512. #if defined(WOLFSSL_APACHE_MYNEWT)
  1513. #include "os/os_malloc.h"
  1514. #if !defined(WOLFSSL_LWIP)
  1515. #include <mn_socket/mn_socket.h>
  1516. #endif
  1517. #if !defined(SIZEOF_LONG)
  1518. #define SIZEOF_LONG 4
  1519. #endif
  1520. #if !defined(SIZEOF_LONG_LONG)
  1521. #define SIZEOF_LONG_LONG 8
  1522. #endif
  1523. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  1524. #define BIG_ENDIAN_ORDER
  1525. #else
  1526. #undef BIG_ENDIAN_ORDER
  1527. #define LITTLE_ENDIAN_ORDER
  1528. #endif
  1529. #define NO_WRITEV
  1530. #define WOLFSSL_USER_IO
  1531. #define SINGLE_THREADED
  1532. #define NO_DEV_RANDOM
  1533. #define NO_DH
  1534. #define NO_WOLFSSL_DIR
  1535. #define NO_ERROR_STRINGS
  1536. #define HAVE_ECC
  1537. #define NO_SESSION_CACHE
  1538. #define NO_ERROR_STRINGS
  1539. #define XMALLOC_USER
  1540. #define XMALLOC(sz, heap, type) os_malloc(sz)
  1541. #define XREALLOC(p, sz, heap, type) os_realloc(p, sz)
  1542. #define XFREE(p, heap, type) os_free(p)
  1543. #endif /*(WOLFSSL_APACHE_MYNEWT)*/
  1544. #ifdef WOLFSSL_ZEPHYR
  1545. #include <zephyr/kernel.h>
  1546. #include <zephyr/sys/printk.h>
  1547. #include <zephyr/sys/util.h>
  1548. #include <stdlib.h>
  1549. #define WOLFSSL_DH_CONST
  1550. #define WOLFSSL_HAVE_MAX
  1551. #define NO_WRITEV
  1552. #define USE_FLAT_BENCHMARK_H
  1553. #define USE_FLAT_TEST_H
  1554. #define EXIT_FAILURE 1
  1555. #define MAIN_NO_ARGS
  1556. void *z_realloc(void *ptr, size_t size);
  1557. #define realloc z_realloc
  1558. #ifndef CONFIG_NET_SOCKETS_POSIX_NAMES
  1559. #define CONFIG_NET_SOCKETS_POSIX_NAMES
  1560. #endif
  1561. #endif
  1562. #ifdef WOLFSSL_IMX6
  1563. #ifndef SIZEOF_LONG_LONG
  1564. #define SIZEOF_LONG_LONG 8
  1565. #endif
  1566. #endif
  1567. /* Setting supported CAAM algorithms */
  1568. #ifdef WOLFSSL_IMX6Q_CAAM
  1569. #undef WOLFSSL_CAAM
  1570. #define WOLFSSL_CAAM
  1571. /* hardware does not support AES-GCM and ECC
  1572. * has the low power AES module only (no high power with GCM) */
  1573. #define WOLFSSL_LP_ONLY_CAAM_AES
  1574. #define WOLFSSL_NO_CAAM_ECC
  1575. #endif
  1576. #ifdef WOLFSSL_SECO_CAAM
  1577. #define WOLFSSL_CAAM
  1578. #define WOLFSSL_HASH_KEEP
  1579. #define WOLFSSL_NO_CAAM_BLOB
  1580. #endif
  1581. #ifdef WOLFSSL_IMXRT1170_CAAM
  1582. #define WOLFSSL_CAAM
  1583. #endif
  1584. /* OS specific support so far */
  1585. #ifdef WOLFSSL_QNX_CAAM
  1586. /* shim layer for QNX hashing not yet implemented */
  1587. #define WOLFSSL_NO_CAAM_HASH
  1588. #endif
  1589. #ifdef WOLFSSL_CAAM
  1590. /* switch for all AES type algos */
  1591. #undef WOLFSSL_CAAM_CIPHER
  1592. #define WOLFSSL_CAAM_CIPHER
  1593. #ifdef WOLFSSL_CAAM_CIPHER
  1594. #ifndef WOLFSSL_LP_ONLY_CAAM_AES
  1595. /* GCM and XTS mode are only available in the high power module */
  1596. #define WOLFSSL_CAAM_AESGCM
  1597. #define WOLFSSL_CAAM_AESXTS
  1598. #endif
  1599. #define WOLFSSL_CAAM_AESCCM
  1600. #define WOLFSSL_CAAM_AESCTR
  1601. #define WOLFSSL_CAAM_AESCBC
  1602. #define WOLFSSL_CAAM_CMAC
  1603. #endif /* WOLFSSL_CAAM_CIPHER */
  1604. #if defined(HAVE_AESGCM) || defined(WOLFSSL_AES_XTS) || \
  1605. defined(WOLFSSL_CMAC)
  1606. /* large performance gain with HAVE_AES_ECB defined */
  1607. #undef HAVE_AES_ECB
  1608. #define HAVE_AES_ECB
  1609. /* @TODO used for now until plugging in caam aes use with qnx */
  1610. #undef WOLFSSL_AES_DIRECT
  1611. #define WOLFSSL_AES_DIRECT
  1612. #endif
  1613. /* switch for all hashing algos */
  1614. #ifndef WOLFSSL_NO_CAAM_HASH
  1615. #define WOLFSSL_CAAM_HASH
  1616. #endif
  1617. #if defined(WOLFSSL_DEVCRYPTO_HMAC)
  1618. /* HMAC is through the devcrypto calls */
  1619. #define WOLFSSL_CAAM_HMAC
  1620. #endif
  1621. /* public key operations */
  1622. #ifndef WOLFSSL_NO_CAAM_ECC
  1623. #undef WOLFSSL_CAAM_ECC
  1624. #define WOLFSSL_CAAM_ECC
  1625. #endif
  1626. /* so far curve25519 support was only done with the SECO */
  1627. #ifdef WOLFSSL_SECO_CAAM
  1628. #define WOLFSSL_CAAM_CURVE25519
  1629. #endif
  1630. /* Blob support */
  1631. #ifndef WOLFSSL_NO_CAAM_BLOB
  1632. #define WOLFSSL_CAAM_BLOB
  1633. #endif
  1634. #endif
  1635. #if defined(NO_WC_SSIZE_TYPE) || defined(ssize_t)
  1636. /* ssize_t comes from system headers or user_settings.h */
  1637. #elif defined(WC_SSIZE_TYPE)
  1638. typedef WC_SSIZE_TYPE ssize_t;
  1639. #elif defined(_MSC_VER)
  1640. #include <BaseTsd.h>
  1641. typedef SSIZE_T ssize_t;
  1642. #endif
  1643. /* If DCP is used without SINGLE_THREADED, enforce WOLFSSL_CRYPT_HW_MUTEX */
  1644. #if defined(WOLFSSL_IMXRT_DCP) && !defined(SINGLE_THREADED)
  1645. #undef WOLFSSL_CRYPT_HW_MUTEX
  1646. #define WOLFSSL_CRYPT_HW_MUTEX 1
  1647. #endif
  1648. #if !defined(XMALLOC_USER) && !defined(MICRIUM_MALLOC) && \
  1649. !defined(WOLFSSL_LEANPSK) && !defined(NO_WOLFSSL_MEMORY) && \
  1650. !defined(XMALLOC_OVERRIDE)
  1651. #define USE_WOLFSSL_MEMORY
  1652. #endif
  1653. #ifdef WOLFSSL_EMBOS
  1654. #include "RTOS.h"
  1655. #if !defined(XMALLOC_USER) && !defined(NO_WOLFSSL_MEMORY) && \
  1656. !defined(WOLFSSL_STATIC_MEMORY)
  1657. #define XMALLOC(s, h, type) OS_HEAP_malloc((s))
  1658. #define XFREE(p, h, type) OS_HEAP_free((p))
  1659. #define XREALLOC(p, n, h, t) OS_HEAP_realloc(((p), (n))
  1660. #endif
  1661. #endif
  1662. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS)
  1663. #undef KEEP_PEER_CERT
  1664. #define KEEP_PEER_CERT
  1665. #endif
  1666. /* stream ciphers except arc4 need 32bit alignment, intel ok without */
  1667. #ifndef XSTREAM_ALIGN
  1668. #if defined(__x86_64__) || defined(__ia64__) || defined(__i386__)
  1669. #define NO_XSTREAM_ALIGN
  1670. #else
  1671. #define XSTREAM_ALIGN
  1672. #endif
  1673. #endif
  1674. /* write dup cannot be used with secure renegotiation because write dup
  1675. * make write side write only and read side read only */
  1676. #if defined(HAVE_WRITE_DUP) && defined(HAVE_SECURE_RENEGOTIATION)
  1677. #error "WRITE DUP and SECURE RENEGOTIATION cannot both be on"
  1678. #endif
  1679. #ifdef WOLFSSL_SGX
  1680. #ifdef _MSC_VER
  1681. #define NO_RC4
  1682. #ifndef HAVE_FIPS
  1683. #define WOLFCRYPT_ONLY
  1684. #define NO_DES3
  1685. #define NO_SHA
  1686. #define NO_MD5
  1687. #else
  1688. #define TFM_TIMING_RESISTANT
  1689. #define NO_WOLFSSL_DIR
  1690. #define NO_WRITEV
  1691. #define NO_MAIN_DRIVER
  1692. #define WOLFSSL_LOG_PRINTF
  1693. #define WOLFSSL_DH_CONST
  1694. #endif
  1695. #else
  1696. #define HAVE_ECC
  1697. #define NO_WRITEV
  1698. #define NO_MAIN_DRIVER
  1699. #define USER_TICKS
  1700. #define WOLFSSL_LOG_PRINTF
  1701. #define WOLFSSL_DH_CONST
  1702. #endif /* _MSC_VER */
  1703. #if !defined(HAVE_FIPS) && !defined(NO_RSA)
  1704. #define WC_RSA_BLINDING
  1705. #endif
  1706. #define NO_FILESYSTEM
  1707. #define ECC_TIMING_RESISTANT
  1708. #define TFM_TIMING_RESISTANT
  1709. #define SINGLE_THREADED
  1710. #define NO_ASN_TIME /* can not use headers such as windows.h */
  1711. #define HAVE_AESGCM
  1712. #define USE_CERT_BUFFERS_2048
  1713. #endif /* WOLFSSL_SGX */
  1714. /* FreeScale MMCAU hardware crypto has 4 byte alignment.
  1715. However, KSDK fsl_mmcau.h gives API with no alignment
  1716. requirements (4 byte alignment is managed internally by fsl_mmcau.c) */
  1717. #ifdef FREESCALE_MMCAU
  1718. #ifdef FREESCALE_MMCAU_CLASSIC
  1719. #define WOLFSSL_MMCAU_ALIGNMENT 4
  1720. #else
  1721. #define WOLFSSL_MMCAU_ALIGNMENT 0
  1722. #endif
  1723. #endif
  1724. /* if using hardware crypto and have alignment requirements, specify the
  1725. requirement here. The record header of SSL/TLS will prevent easy alignment.
  1726. This hint tries to help as much as possible. */
  1727. #ifndef WOLFSSL_GENERAL_ALIGNMENT
  1728. #ifdef WOLFSSL_AESNI
  1729. #define WOLFSSL_GENERAL_ALIGNMENT 16
  1730. #elif defined(XSTREAM_ALIGN)
  1731. #define WOLFSSL_GENERAL_ALIGNMENT 4
  1732. #elif defined(FREESCALE_MMCAU) || defined(FREESCALE_MMCAU_CLASSIC)
  1733. #define WOLFSSL_GENERAL_ALIGNMENT WOLFSSL_MMCAU_ALIGNMENT
  1734. #else
  1735. #define WOLFSSL_GENERAL_ALIGNMENT 0
  1736. #endif
  1737. #endif
  1738. #if defined(WOLFSSL_GENERAL_ALIGNMENT) && (WOLFSSL_GENERAL_ALIGNMENT > 0)
  1739. #if defined(_MSC_VER)
  1740. #define XGEN_ALIGN __declspec(align(WOLFSSL_GENERAL_ALIGNMENT))
  1741. #elif defined(__GNUC__)
  1742. #define XGEN_ALIGN __attribute__((aligned(WOLFSSL_GENERAL_ALIGNMENT)))
  1743. #else
  1744. #define XGEN_ALIGN
  1745. #endif
  1746. #else
  1747. #define XGEN_ALIGN
  1748. #endif
  1749. #if defined(__mips) || defined(__mips64) || \
  1750. defined(WOLFSSL_SP_MIPS64) || defined(WOLFSSL_SP_MIPS)
  1751. #undef WOLFSSL_SP_INT_DIGIT_ALIGN
  1752. #define WOLFSSL_SP_INT_DIGIT_ALIGN
  1753. #endif
  1754. #ifdef __APPLE__
  1755. #define WOLFSSL_SP_NO_DYN_STACK
  1756. #endif
  1757. #ifdef __INTEL_COMPILER
  1758. #pragma warning(disable:2259) /* explicit casts to smaller sizes, disable */
  1759. #endif
  1760. /* ---------------------------------------------------------------------------
  1761. * Math Library Selection (in order of preference)
  1762. * ---------------------------------------------------------------------------
  1763. */
  1764. #if !defined(HAVE_FIPS_VERSION) || \
  1765. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  1766. #if defined(WOLFSSL_SP_MATH_ALL)
  1767. /* 1) SP Math: wolfSSL proprietary math implementation (sp_int.c).
  1768. * Constant time: Always
  1769. * Enable: WOLFSSL_SP_MATH_ALL
  1770. */
  1771. #undef USE_FAST_MATH
  1772. #undef USE_INTEGER_HEAP_MATH
  1773. #elif defined(WOLFSSL_SP_MATH)
  1774. /* 2) SP Math with restricted key sizes: wolfSSL proprietary math
  1775. * implementation (sp_*.c).
  1776. * Constant time: Always
  1777. * Enable: WOLFSSL_SP_MATH
  1778. */
  1779. #undef USE_FAST_MATH
  1780. #undef USE_INTEGER_HEAP_MATH
  1781. #elif defined(USE_FAST_MATH)
  1782. /* 3) Tom's Fast Math: Stack based (tfm.c)
  1783. * Constant time: Only with TFM_TIMING_RESISTANT
  1784. * Enable: USE_FAST_MATH
  1785. */
  1786. #undef USE_INTEGER_HEAP_MATH
  1787. #elif defined(USE_INTEGER_HEAP_MATH)
  1788. /* 4) Integer Heap Math: Heap based (integer.c)
  1789. * Constant time: Not supported
  1790. * Enable: USE_INTEGER_HEAP_MATH
  1791. */
  1792. #elif defined(NO_BIG_INT)
  1793. /* 5) No big integer math libraries
  1794. */
  1795. #else
  1796. /* default is SP Math. */
  1797. #define WOLFSSL_SP_MATH_ALL
  1798. #endif
  1799. #else
  1800. /* FIPS 140-2 or older */
  1801. /* Default to fast math (tfm.c), but allow heap math (integer.c) */
  1802. #if !defined(USE_INTEGER_HEAP_MATH)
  1803. #undef USE_FAST_MATH
  1804. #define USE_FAST_MATH
  1805. #ifndef FP_MAX_BITS
  1806. #define FP_MAX_BITS 8192
  1807. #endif
  1808. #endif
  1809. #endif
  1810. /* Verify that only one of the above multi-precision math libraries is enabled */
  1811. #if (defined(WOLFSSL_SP_MATH_ALL) && \
  1812. (defined(USE_FAST_MATH) || defined(USE_INTEGER_HEAP_MATH))) || \
  1813. (defined(USE_FAST_MATH) && defined(USE_INTEGER_HEAP_MATH))
  1814. #error Cannot enable more than one multiple precision math library!
  1815. #endif
  1816. /*----------------------------------------------------------------------------*/
  1817. /* user can specify what curves they want with ECC_USER_CURVES otherwise
  1818. * all curves are on by default for now */
  1819. #ifndef ECC_USER_CURVES
  1820. #ifdef WOLFSSL_SP_MATH
  1821. /* for single precision math only make sure the enabled key sizes are
  1822. * included in the ECC curve table */
  1823. #if defined(WOLFSSL_SP_NO_256) && !defined(NO_ECC256)
  1824. #define NO_ECC256
  1825. #endif
  1826. #if defined(WOLFSSL_SP_384) && !defined(HAVE_ECC384)
  1827. #define HAVE_ECC384
  1828. #endif
  1829. #if defined(WOLFSSL_SP_521) && !defined(HAVE_ECC521)
  1830. #define HAVE_ECC521
  1831. #endif
  1832. #elif !defined(HAVE_ALL_CURVES)
  1833. #define HAVE_ALL_CURVES
  1834. #endif
  1835. #endif
  1836. /* The minimum allowed ECC key size */
  1837. /* Note: 224-bits is equivalent to 2048-bit RSA */
  1838. #ifndef ECC_MIN_KEY_SZ
  1839. #ifdef WOLFSSL_MIN_ECC_BITS
  1840. #define ECC_MIN_KEY_SZ WOLFSSL_MIN_ECC_BITS
  1841. #else
  1842. #if defined(WOLFSSL_HARDEN_TLS) && \
  1843. !defined(WOLFSSL_HARDEN_TLS_NO_PKEY_CHECK)
  1844. /* Using guidance from section 5.6.1
  1845. * https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r5.pdf */
  1846. #if WOLFSSL_HARDEN_TLS >= 128
  1847. #define ECC_MIN_KEY_SZ 256
  1848. #elif WOLFSSL_HARDEN_TLS >= 112
  1849. #define ECC_MIN_KEY_SZ 224
  1850. #endif
  1851. #elif FIPS_VERSION_GE(2,0)
  1852. /* FIPSv2 and ready (for now) includes 192-bit support */
  1853. #define ECC_MIN_KEY_SZ 192
  1854. #else
  1855. #define ECC_MIN_KEY_SZ 224
  1856. #endif
  1857. #endif
  1858. #endif
  1859. #if defined(WOLFSSL_HARDEN_TLS) && ECC_MIN_KEY_SZ < 224 && \
  1860. !defined(WOLFSSL_HARDEN_TLS_NO_PKEY_CHECK)
  1861. /* Implementations MUST NOT negotiate cipher suites offering less than
  1862. * 112 bits of security.
  1863. * https://www.rfc-editor.org/rfc/rfc9325#section-4.1
  1864. * Using guidance from section 5.6.1
  1865. * https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r5.pdf */
  1866. #error "For 112 bits of security ECC needs at least 224 bit keys"
  1867. #endif
  1868. /* ECC Configs */
  1869. #ifdef HAVE_ECC
  1870. /* By default enable Sign, Verify, DHE, Key Import and Key Export unless
  1871. * explicitly disabled */
  1872. #if !defined(NO_ECC_SIGN) && \
  1873. (!defined(ECC_TIMING_RESISTANT) || \
  1874. (defined(ECC_TIMING_RESISTANT) && !defined(WC_NO_RNG)))
  1875. #undef HAVE_ECC_SIGN
  1876. #define HAVE_ECC_SIGN
  1877. #endif
  1878. #ifndef NO_ECC_VERIFY
  1879. #undef HAVE_ECC_VERIFY
  1880. #define HAVE_ECC_VERIFY
  1881. #endif
  1882. #ifndef NO_ECC_CHECK_KEY
  1883. #undef HAVE_ECC_CHECK_KEY
  1884. #define HAVE_ECC_CHECK_KEY
  1885. #endif
  1886. #if !defined(NO_ECC_DHE) && !defined(WC_NO_RNG)
  1887. #undef HAVE_ECC_DHE
  1888. #define HAVE_ECC_DHE
  1889. #endif
  1890. #ifndef NO_ECC_KEY_IMPORT
  1891. #undef HAVE_ECC_KEY_IMPORT
  1892. #define HAVE_ECC_KEY_IMPORT
  1893. #endif
  1894. /* The ECC key export requires mp_int or SP */
  1895. #if (!defined(NO_ECC_KEY_EXPORT) && defined(WOLFSSL_SP_MATH)) || \
  1896. (!defined(NO_ECC_KEY_EXPORT) && !defined(NO_BIG_INT))
  1897. #undef HAVE_ECC_KEY_EXPORT
  1898. #define HAVE_ECC_KEY_EXPORT
  1899. #endif
  1900. #endif /* HAVE_ECC */
  1901. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && \
  1902. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  1903. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050) && \
  1904. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLFSSL_STM32_PKA)
  1905. #undef USE_ECC_B_PARAM
  1906. #define USE_ECC_B_PARAM
  1907. #endif
  1908. /* Curve25519 Configs */
  1909. #ifdef HAVE_CURVE25519
  1910. /* By default enable shared secret, key export and import */
  1911. #ifndef NO_CURVE25519_SHARED_SECRET
  1912. #undef HAVE_CURVE25519_SHARED_SECRET
  1913. #define HAVE_CURVE25519_SHARED_SECRET
  1914. #endif
  1915. #ifndef NO_CURVE25519_KEY_EXPORT
  1916. #undef HAVE_CURVE25519_KEY_EXPORT
  1917. #define HAVE_CURVE25519_KEY_EXPORT
  1918. #endif
  1919. #ifndef NO_CURVE25519_KEY_IMPORT
  1920. #undef HAVE_CURVE25519_KEY_IMPORT
  1921. #define HAVE_CURVE25519_KEY_IMPORT
  1922. #endif
  1923. #endif /* HAVE_CURVE25519 */
  1924. /* Ed25519 Configs */
  1925. #ifdef HAVE_ED25519
  1926. /* By default enable make key, sign, verify, key export and import */
  1927. #ifndef NO_ED25519_MAKE_KEY
  1928. #undef HAVE_ED25519_MAKE_KEY
  1929. #define HAVE_ED25519_MAKE_KEY
  1930. #endif
  1931. #ifndef NO_ED25519_SIGN
  1932. #ifndef HAVE_ED25519_MAKE_KEY
  1933. #error "Need HAVE_ED25519_MAKE_KEY with HAVE_ED25519_SIGN"
  1934. #endif
  1935. #undef HAVE_ED25519_SIGN
  1936. #define HAVE_ED25519_SIGN
  1937. #endif
  1938. #ifndef NO_ED25519_VERIFY
  1939. #undef HAVE_ED25519_VERIFY
  1940. #define HAVE_ED25519_VERIFY
  1941. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  1942. #undef WOLFSSL_ED25519_PERSISTENT_SHA
  1943. #define WOLFSSL_ED25519_PERSISTENT_SHA
  1944. #endif
  1945. #endif
  1946. #ifndef NO_ED25519_KEY_EXPORT
  1947. #undef HAVE_ED25519_KEY_EXPORT
  1948. #define HAVE_ED25519_KEY_EXPORT
  1949. #endif
  1950. #ifndef NO_ED25519_KEY_IMPORT
  1951. #undef HAVE_ED25519_KEY_IMPORT
  1952. #define HAVE_ED25519_KEY_IMPORT
  1953. #endif
  1954. #endif /* HAVE_ED25519 */
  1955. /* Curve448 Configs */
  1956. #ifdef HAVE_CURVE448
  1957. /* By default enable shared secret, key export and import */
  1958. #ifndef NO_CURVE448_SHARED_SECRET
  1959. #undef HAVE_CURVE448_SHARED_SECRET
  1960. #define HAVE_CURVE448_SHARED_SECRET
  1961. #endif
  1962. #ifndef NO_CURVE448_KEY_EXPORT
  1963. #undef HAVE_CURVE448_KEY_EXPORT
  1964. #define HAVE_CURVE448_KEY_EXPORT
  1965. #endif
  1966. #ifndef NO_CURVE448_KEY_IMPORT
  1967. #undef HAVE_CURVE448_KEY_IMPORT
  1968. #define HAVE_CURVE448_KEY_IMPORT
  1969. #endif
  1970. #endif /* HAVE_CURVE448 */
  1971. /* Ed448 Configs */
  1972. #ifdef HAVE_ED448
  1973. /* By default enable sign, verify, key export and import */
  1974. #ifndef NO_ED448_SIGN
  1975. #undef HAVE_ED448_SIGN
  1976. #define HAVE_ED448_SIGN
  1977. #endif
  1978. #ifndef NO_ED448_VERIFY
  1979. #undef HAVE_ED448_VERIFY
  1980. #define HAVE_ED448_VERIFY
  1981. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  1982. #undef WOLFSSL_ED448_PERSISTENT_SHA
  1983. #define WOLFSSL_ED448_PERSISTENT_SHA
  1984. #endif
  1985. #endif
  1986. #ifndef NO_ED448_KEY_EXPORT
  1987. #undef HAVE_ED448_KEY_EXPORT
  1988. #define HAVE_ED448_KEY_EXPORT
  1989. #endif
  1990. #ifndef NO_ED448_KEY_IMPORT
  1991. #undef HAVE_ED448_KEY_IMPORT
  1992. #define HAVE_ED448_KEY_IMPORT
  1993. #endif
  1994. #endif /* HAVE_ED448 */
  1995. /* AES Config */
  1996. #ifndef NO_AES
  1997. /* By default enable all AES key sizes, decryption and CBC */
  1998. #ifndef AES_MAX_KEY_SIZE
  1999. #undef AES_MAX_KEY_SIZE
  2000. #define AES_MAX_KEY_SIZE 256
  2001. #endif
  2002. #ifndef NO_AES_128
  2003. #undef WOLFSSL_AES_128
  2004. #define WOLFSSL_AES_128
  2005. #endif
  2006. #if !defined(NO_AES_192) && AES_MAX_KEY_SIZE >= 192
  2007. #undef WOLFSSL_AES_192
  2008. #define WOLFSSL_AES_192
  2009. #endif
  2010. #if !defined(NO_AES_256) && AES_MAX_KEY_SIZE >= 256
  2011. #undef WOLFSSL_AES_256
  2012. #define WOLFSSL_AES_256
  2013. #endif
  2014. #if !defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AES_256) && \
  2015. defined(HAVE_ECC_ENCRYPT)
  2016. #warning HAVE_ECC_ENCRYPT uses AES 128/256 bit keys
  2017. #endif
  2018. #ifndef NO_AES_DECRYPT
  2019. #undef HAVE_AES_DECRYPT
  2020. #define HAVE_AES_DECRYPT
  2021. #endif
  2022. #ifndef NO_AES_CBC
  2023. #undef HAVE_AES_CBC
  2024. #define HAVE_AES_CBC
  2025. #endif
  2026. #ifdef WOLFSSL_AES_XTS
  2027. /* AES-XTS makes calls to AES direct functions */
  2028. #ifndef WOLFSSL_AES_DIRECT
  2029. #define WOLFSSL_AES_DIRECT
  2030. #endif
  2031. #endif
  2032. #ifdef WOLFSSL_AES_CFB
  2033. /* AES-CFB makes calls to AES direct functions */
  2034. #ifndef WOLFSSL_AES_DIRECT
  2035. #define WOLFSSL_AES_DIRECT
  2036. #endif
  2037. #endif
  2038. #endif
  2039. #if (defined(WOLFSSL_TLS13) && defined(WOLFSSL_NO_TLS12)) || \
  2040. (!defined(HAVE_AES_CBC) && defined(NO_DES3) && defined(NO_RC4) && \
  2041. !defined(HAVE_CAMELLIA) & !defined(HAVE_NULL_CIPHER))
  2042. #define WOLFSSL_AEAD_ONLY
  2043. #endif
  2044. #if !defined(HAVE_PUBLIC_FFDHE) && !defined(NO_DH) && \
  2045. !defined(WOLFSSL_NO_PUBLIC_FFDHE) && \
  2046. (defined(HAVE_SELFTEST) || FIPS_VERSION_LE(2,0))
  2047. /* This should only be enabled for FIPS v2 or older. It enables use of the
  2048. * older wc_Dh_ffdhe####_Get() API's */
  2049. #define HAVE_PUBLIC_FFDHE
  2050. #endif
  2051. #if !defined(NO_DH) && !defined(HAVE_FFDHE)
  2052. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || \
  2053. defined(HAVE_FFDHE_4096) || defined(HAVE_FFDHE_6144) || \
  2054. defined(HAVE_FFDHE_8192)
  2055. #define HAVE_FFDHE
  2056. #endif
  2057. #endif
  2058. #if defined(HAVE_FFDHE_8192)
  2059. #define MIN_FFDHE_BITS 8192
  2060. #elif defined(HAVE_FFDHE_6144)
  2061. #define MIN_FFDHE_BITS 6144
  2062. #elif defined(HAVE_FFDHE_4096)
  2063. #define MIN_FFDHE_BITS 4096
  2064. #elif defined(HAVE_FFDHE_3072)
  2065. #define MIN_FFDHE_BITS 3072
  2066. #elif defined(HAVE_FFDHE_2048)
  2067. #define MIN_FFDHE_BITS 2048
  2068. #else
  2069. #define MIN_FFDHE_BITS 0
  2070. #endif
  2071. #define MIN_FFDHE_FP_MAX_BITS (MIN_FFDHE_BITS * 2)
  2072. #if defined(HAVE_FFDHE) && defined(FP_MAX_BITS)
  2073. #if MIN_FFDHE_FP_MAX_BITS > FP_MAX_BITS
  2074. #error "FFDHE parameters are too large for FP_MAX_BIT as set"
  2075. #endif
  2076. #endif
  2077. #if defined(HAVE_FFDHE) && defined(SP_INT_BITS)
  2078. #if MIN_FFDHE_BITS > SP_INT_BITS
  2079. #error "FFDHE parameters are too large for SP_INT_BIT as set"
  2080. #endif
  2081. #endif
  2082. /* if desktop type system and fastmath increase default max bits */
  2083. #if defined(WOLFSSL_X86_64_BUILD) || defined(WOLFSSL_AARCH64_BUILD)
  2084. #if defined(USE_FAST_MATH) && !defined(FP_MAX_BITS)
  2085. #if MIN_FFDHE_FP_MAX_BITS <= 8192
  2086. #define FP_MAX_BITS 8192
  2087. #else
  2088. #define FP_MAX_BITS MIN_FFDHE_FP_MAX_BITS
  2089. #endif
  2090. #endif
  2091. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(SP_INT_BITS)
  2092. #ifdef WOLFSSL_MYSQL_COMPATIBLE
  2093. #define SP_INT_BITS 8192
  2094. #elif MIN_FFDHE_BITS <= 4096
  2095. #define SP_INT_BITS 4096
  2096. #else
  2097. #define SP_INT_BITS MIN_FFDHE_BITS
  2098. #endif
  2099. #endif
  2100. #endif
  2101. /* If using the max strength build, ensure OLD TLS is disabled. */
  2102. #ifdef WOLFSSL_MAX_STRENGTH
  2103. #undef NO_OLD_TLS
  2104. #define NO_OLD_TLS
  2105. #endif
  2106. /* Default AES minimum auth tag sz, allow user to override */
  2107. #ifndef WOLFSSL_MIN_AUTH_TAG_SZ
  2108. #define WOLFSSL_MIN_AUTH_TAG_SZ 12
  2109. #endif
  2110. /* sniffer requires:
  2111. * static RSA cipher suites
  2112. * session stats and peak stats
  2113. */
  2114. #ifdef WOLFSSL_SNIFFER
  2115. #ifndef WOLFSSL_STATIC_RSA
  2116. #define WOLFSSL_STATIC_RSA
  2117. #endif
  2118. #ifndef WOLFSSL_STATIC_DH
  2119. #define WOLFSSL_STATIC_DH
  2120. #endif
  2121. /* Allow option to be disabled. */
  2122. #ifndef WOLFSSL_NO_SESSION_STATS
  2123. #ifndef WOLFSSL_SESSION_STATS
  2124. #define WOLFSSL_SESSION_STATS
  2125. #endif
  2126. #ifndef WOLFSSL_PEAK_SESSIONS
  2127. #define WOLFSSL_PEAK_SESSIONS
  2128. #endif
  2129. #endif
  2130. #endif
  2131. /* Decode Public Key extras on by default, user can turn off with
  2132. * WOLFSSL_NO_DECODE_EXTRA */
  2133. #ifndef WOLFSSL_NO_DECODE_EXTRA
  2134. #ifndef RSA_DECODE_EXTRA
  2135. #define RSA_DECODE_EXTRA
  2136. #endif
  2137. #ifndef ECC_DECODE_EXTRA
  2138. #define ECC_DECODE_EXTRA
  2139. #endif
  2140. #endif
  2141. /* C Sharp wrapper defines */
  2142. #ifdef HAVE_CSHARP
  2143. #ifndef WOLFSSL_DTLS
  2144. #define WOLFSSL_DTLS
  2145. #endif
  2146. #undef NO_PSK
  2147. #undef NO_SHA256
  2148. #undef NO_DH
  2149. #endif
  2150. /* Asynchronous Crypto */
  2151. #ifdef WOLFSSL_ASYNC_CRYPT
  2152. #if !defined(HAVE_CAVIUM) && !defined(HAVE_INTEL_QA) && \
  2153. !defined(WOLF_CRYPTO_CB) && !defined(HAVE_PK_CALLBACKS) && \
  2154. !defined(WOLFSSL_ASYNC_CRYPT_SW)
  2155. #error No async backend defined with WOLFSSL_ASYNC_CRYPT!
  2156. #endif
  2157. /* Make sure wolf events are enabled */
  2158. #undef HAVE_WOLF_EVENT
  2159. #define HAVE_WOLF_EVENT
  2160. #ifdef WOLFSSL_ASYNC_CRYPT_SW
  2161. #define WC_ASYNC_DEV_SIZE 168
  2162. #else
  2163. #define WC_ASYNC_DEV_SIZE 336
  2164. #endif
  2165. /* Enable ECC_CACHE_CURVE for ASYNC */
  2166. #if !defined(ECC_CACHE_CURVE)
  2167. #define ECC_CACHE_CURVE
  2168. #endif
  2169. #endif /* WOLFSSL_ASYNC_CRYPT */
  2170. #ifndef WC_ASYNC_DEV_SIZE
  2171. #define WC_ASYNC_DEV_SIZE 0
  2172. #endif
  2173. #ifdef HAVE_INTEL_QA /* Disable SHA512/224 and SHA512/256 support for QAT */
  2174. #define WOLFSSL_NOSHA512_224
  2175. #define WOLFSSL_NOSHA512_256
  2176. #endif
  2177. /* leantls checks */
  2178. #ifdef WOLFSSL_LEANTLS
  2179. #ifndef HAVE_ECC
  2180. #error leantls build needs ECC
  2181. #endif
  2182. #endif /* WOLFSSL_LEANTLS*/
  2183. /* restriction with static memory */
  2184. #ifdef WOLFSSL_STATIC_MEMORY
  2185. #if defined(HAVE_IO_POOL) || defined(XMALLOC_USER) || defined(NO_WOLFSSL_MEMORY)
  2186. #error static memory cannot be used with HAVE_IO_POOL, XMALLOC_USER or NO_WOLFSSL_MEMORY
  2187. #endif
  2188. #if !defined(WOLFSSL_SP_MATH_ALL) && !defined(USE_FAST_MATH) && \
  2189. !defined(WOLFSSL_SP_MATH) && !defined(NO_BIG_INT)
  2190. #error The static memory option is only supported for fast math or SP Math
  2191. #endif
  2192. #ifdef WOLFSSL_SMALL_STACK
  2193. #error static memory does not support small stack please undefine
  2194. #endif
  2195. #endif /* WOLFSSL_STATIC_MEMORY */
  2196. #ifdef HAVE_AES_KEYWRAP
  2197. #ifndef WOLFSSL_AES_DIRECT
  2198. #error AES key wrap requires AES direct please define WOLFSSL_AES_DIRECT
  2199. #endif
  2200. #endif
  2201. #ifdef HAVE_PKCS7
  2202. #if defined(NO_AES) && defined(NO_DES3)
  2203. #error PKCS7 needs either AES or 3DES enabled, please enable one
  2204. #endif
  2205. #ifndef HAVE_AES_KEYWRAP
  2206. #error PKCS7 requires AES key wrap please define HAVE_AES_KEYWRAP
  2207. #endif
  2208. #if defined(HAVE_ECC) && !defined(HAVE_X963_KDF)
  2209. #error PKCS7 requires X963 KDF please define HAVE_X963_KDF
  2210. #endif
  2211. #endif
  2212. #ifndef NO_PKCS12
  2213. #undef HAVE_PKCS12
  2214. #define HAVE_PKCS12
  2215. #endif
  2216. #if !defined(NO_PKCS8) || defined(HAVE_PKCS12)
  2217. #undef HAVE_PKCS8
  2218. #define HAVE_PKCS8
  2219. #endif
  2220. #if !defined(NO_PBKDF1) || defined(WOLFSSL_ENCRYPTED_KEYS) || \
  2221. defined(HAVE_PKCS8) || defined(HAVE_PKCS12)
  2222. #undef HAVE_PBKDF1
  2223. #define HAVE_PBKDF1
  2224. #endif
  2225. #if !defined(NO_PBKDF2) || defined(HAVE_PKCS7) || defined(HAVE_SCRYPT)
  2226. #undef HAVE_PBKDF2
  2227. #define HAVE_PBKDF2
  2228. #endif
  2229. #if !defined(WOLFCRYPT_ONLY) && !defined(NO_OLD_TLS) && \
  2230. (defined(NO_SHA) || defined(NO_MD5))
  2231. #error old TLS requires MD5 and SHA
  2232. #endif
  2233. /* for backwards compatibility */
  2234. #if defined(TEST_IPV6) && !defined(WOLFSSL_IPV6)
  2235. #define WOLFSSL_IPV6
  2236. #endif
  2237. #ifdef WOLFSSL_LINUXKM
  2238. #ifdef HAVE_CONFIG_H
  2239. #include <config.h>
  2240. #undef HAVE_CONFIG_H
  2241. #endif
  2242. #ifndef NO_DEV_RANDOM
  2243. #define NO_DEV_RANDOM
  2244. #endif
  2245. #ifndef NO_WRITEV
  2246. #define NO_WRITEV
  2247. #endif
  2248. #ifndef NO_FILESYSTEM
  2249. #define NO_FILESYSTEM
  2250. #endif
  2251. #ifndef NO_STDIO_FILESYSTEM
  2252. #define NO_STDIO_FILESYSTEM
  2253. #endif
  2254. #ifndef WOLFSSL_NO_SOCK
  2255. #define WOLFSSL_NO_SOCK
  2256. #endif
  2257. #ifndef WOLFSSL_DH_CONST
  2258. #define WOLFSSL_DH_CONST
  2259. #endif
  2260. #ifndef WOLFSSL_USER_IO
  2261. #define WOLFSSL_USER_IO
  2262. #endif
  2263. #ifndef USE_WOLF_STRTOK
  2264. #define USE_WOLF_STRTOK
  2265. #endif
  2266. #ifndef WOLFSSL_OLD_PRIME_CHECK
  2267. #define WOLFSSL_OLD_PRIME_CHECK
  2268. #endif
  2269. #ifndef WOLFSSL_TEST_SUBROUTINE
  2270. #define WOLFSSL_TEST_SUBROUTINE static
  2271. #endif
  2272. #undef HAVE_STRINGS_H
  2273. #undef HAVE_ERRNO_H
  2274. #undef HAVE_THREAD_LS
  2275. #undef WOLFSSL_HAVE_MIN
  2276. #undef WOLFSSL_HAVE_MAX
  2277. #define SIZEOF_LONG 8
  2278. #define SIZEOF_LONG_LONG 8
  2279. #define CHAR_BIT 8
  2280. #ifndef WOLFSSL_SP_DIV_64
  2281. #define WOLFSSL_SP_DIV_64
  2282. #endif
  2283. #ifndef WOLFSSL_SP_DIV_WORD_HALF
  2284. #define WOLFSSL_SP_DIV_WORD_HALF
  2285. #endif
  2286. #endif
  2287. /* Place any other flags or defines here */
  2288. #if defined(WOLFSSL_MYSQL_COMPATIBLE) && defined(_WIN32) \
  2289. && defined(HAVE_GMTIME_R)
  2290. #undef HAVE_GMTIME_R /* don't trust macro with windows */
  2291. #endif /* WOLFSSL_MYSQL_COMPATIBLE */
  2292. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) \
  2293. || defined(HAVE_LIGHTY)) && !defined(NO_TLS)
  2294. #define OPENSSL_NO_ENGINE
  2295. #ifndef OPENSSL_EXTRA
  2296. #define OPENSSL_EXTRA
  2297. #endif
  2298. /* Session Tickets will be enabled when --enable-opensslall is used.
  2299. * Time is required for ticket expiration checking */
  2300. #if !defined(HAVE_SESSION_TICKET) && !defined(NO_ASN_TIME)
  2301. #define HAVE_SESSION_TICKET
  2302. #endif
  2303. /* OCSP will be enabled in configure.ac when --enable-opensslall is used,
  2304. * but do not force all users to have it enabled. */
  2305. #ifndef HAVE_OCSP
  2306. /*#define HAVE_OCSP*/
  2307. #endif
  2308. #ifndef KEEP_OUR_CERT
  2309. #define KEEP_OUR_CERT
  2310. #endif
  2311. #ifndef HAVE_SNI
  2312. #define HAVE_SNI
  2313. #endif
  2314. #endif
  2315. /* Make sure setting OPENSSL_ALL also sets OPENSSL_EXTRA. */
  2316. #if defined(OPENSSL_ALL) && !defined(OPENSSL_EXTRA)
  2317. #define OPENSSL_EXTRA
  2318. #endif
  2319. #ifdef HAVE_SNI
  2320. #define SSL_CTRL_SET_TLSEXT_HOSTNAME 55
  2321. #endif
  2322. /* Disable time checking if no timer */
  2323. #if defined(NO_ASN_TIME)
  2324. #define NO_ASN_TIME_CHECK
  2325. #endif
  2326. /* both CURVE and ED small math should be enabled */
  2327. #ifdef CURVED25519_SMALL
  2328. #define CURVE25519_SMALL
  2329. #define ED25519_SMALL
  2330. #endif
  2331. /* both CURVE and ED small math should be enabled */
  2332. #ifdef CURVED448_SMALL
  2333. #define CURVE448_SMALL
  2334. #define ED448_SMALL
  2335. #endif
  2336. #ifndef WOLFSSL_ALERT_COUNT_MAX
  2337. #define WOLFSSL_ALERT_COUNT_MAX 5
  2338. #endif
  2339. /* warning for not using harden build options (default with ./configure) */
  2340. /* do not warn if big integer support is disabled */
  2341. #if !defined(WC_NO_HARDEN) && !defined(NO_BIG_INT)
  2342. #if (defined(USE_FAST_MATH) && !defined(TFM_TIMING_RESISTANT)) || \
  2343. (defined(HAVE_ECC) && !defined(ECC_TIMING_RESISTANT)) || \
  2344. (!defined(NO_RSA) && !defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS) && \
  2345. !defined(WC_NO_RNG))
  2346. #ifndef _MSC_VER
  2347. #warning "For timing resistance / side-channel attack prevention consider using harden options"
  2348. #else
  2349. #pragma message("Warning: For timing resistance / side-channel attack prevention consider using harden options")
  2350. #endif
  2351. #endif
  2352. #endif
  2353. #ifdef OPENSSL_COEXIST
  2354. /* make sure old names are disabled */
  2355. #ifndef NO_OLD_SSL_NAMES
  2356. #define NO_OLD_SSL_NAMES
  2357. #endif
  2358. #ifndef NO_OLD_WC_NAMES
  2359. #define NO_OLD_WC_NAMES
  2360. #endif
  2361. #endif
  2362. #if defined(NO_OLD_WC_NAMES) || defined(OPENSSL_EXTRA)
  2363. /* added to have compatibility with SHA256() */
  2364. #if !defined(NO_OLD_SHA_NAMES) && (!defined(HAVE_FIPS) || \
  2365. FIPS_VERSION_GT(2,0))
  2366. #define NO_OLD_SHA_NAMES
  2367. #endif
  2368. #if !defined(NO_OLD_MD5_NAME) && (!defined(HAVE_FIPS) || \
  2369. FIPS_VERSION_GT(2,0))
  2370. #define NO_OLD_MD5_NAME
  2371. #endif
  2372. #endif
  2373. /* switch for compatibility layer functionality. Has subparts i.e. BIO/X509
  2374. * When opensslextra is enabled all subparts should be turned on. */
  2375. #ifdef OPENSSL_EXTRA
  2376. #undef OPENSSL_EXTRA_X509_SMALL
  2377. #define OPENSSL_EXTRA_X509_SMALL
  2378. #endif /* OPENSSL_EXTRA */
  2379. /* support for converting DER to PEM */
  2380. #if (defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_NO_DER_TO_PEM)) || \
  2381. defined(WOLFSSL_CERT_GEN) || defined(OPENSSL_EXTRA)
  2382. #undef WOLFSSL_DER_TO_PEM
  2383. #define WOLFSSL_DER_TO_PEM
  2384. #endif
  2385. /* keep backwards compatibility enabling encrypted private key */
  2386. #ifndef WOLFSSL_ENCRYPTED_KEYS
  2387. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  2388. defined(HAVE_WEBSERVER)
  2389. #define WOLFSSL_ENCRYPTED_KEYS
  2390. #endif
  2391. #endif
  2392. /* support for disabling PEM to DER */
  2393. #if !defined(WOLFSSL_NO_PEM) && !defined(NO_CODING)
  2394. #undef WOLFSSL_PEM_TO_DER
  2395. #define WOLFSSL_PEM_TO_DER
  2396. #endif
  2397. /* Parts of the openssl compatibility layer require peer certs */
  2398. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) \
  2399. || defined(HAVE_LIGHTY)
  2400. #undef KEEP_PEER_CERT
  2401. #define KEEP_PEER_CERT
  2402. #endif
  2403. /*
  2404. * Keeps the "Finished" messages after a TLS handshake for use as the so-called
  2405. * "tls-unique" channel binding. See comment in internal.h around clientFinished
  2406. * and serverFinished for more information.
  2407. */
  2408. #if defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_WPAS)
  2409. #undef WOLFSSL_HAVE_TLS_UNIQUE
  2410. #define WOLFSSL_HAVE_TLS_UNIQUE
  2411. #endif
  2412. /* RAW hash function APIs are not implemented */
  2413. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_AFALG_HASH)
  2414. #undef WOLFSSL_NO_HASH_RAW
  2415. #define WOLFSSL_NO_HASH_RAW
  2416. #endif
  2417. /* XChacha not implemented with ARM assembly ChaCha */
  2418. #if defined(WOLFSSL_ARMASM)
  2419. #undef HAVE_XCHACHA
  2420. #endif
  2421. #if !defined(WOLFSSL_SHA384) && !defined(WOLFSSL_SHA512) && defined(NO_AES) && \
  2422. !defined(WOLFSSL_SHA3)
  2423. #undef WOLFSSL_NO_WORD64_OPS
  2424. #define WOLFSSL_NO_WORD64_OPS
  2425. #endif
  2426. #if !defined(WOLFCRYPT_ONLY) && \
  2427. (!defined(WOLFSSL_NO_TLS12) || defined(HAVE_KEYING_MATERIAL))
  2428. #undef WOLFSSL_HAVE_PRF
  2429. #define WOLFSSL_HAVE_PRF
  2430. #endif
  2431. #if defined(NO_ASN) && defined(WOLFCRYPT_ONLY) && !defined(WOLFSSL_WOLFSSH)
  2432. #undef WOLFSSL_NO_INT_ENCODE
  2433. #define WOLFSSL_NO_INT_ENCODE
  2434. #endif
  2435. #if defined(NO_ASN) && defined(WOLFCRYPT_ONLY)
  2436. #undef WOLFSSL_NO_INT_DECODE
  2437. #define WOLFSSL_NO_INT_DECODE
  2438. #endif
  2439. #if defined(WOLFCRYPT_ONLY) && defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  2440. defined(WC_NO_RSA_OAEP)
  2441. #undef WOLFSSL_NO_CT_OPS
  2442. #define WOLFSSL_NO_CT_OPS
  2443. #endif
  2444. #if defined(WOLFCRYPT_ONLY) && defined(NO_AES) && !defined(HAVE_CURVE25519) && \
  2445. !defined(HAVE_CURVE448) && defined(WC_NO_RNG) && defined(WC_NO_RSA_OAEP)
  2446. #undef WOLFSSL_NO_CONST_CMP
  2447. #define WOLFSSL_NO_CONST_CMP
  2448. #endif
  2449. #if defined(WOLFCRYPT_ONLY) && defined(NO_AES) && !defined(WOLFSSL_SHA384) && \
  2450. !defined(WOLFSSL_SHA512) && defined(WC_NO_RNG) && \
  2451. !defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL) \
  2452. && !defined(USE_FAST_MATH)
  2453. #undef WOLFSSL_NO_FORCE_ZERO
  2454. #define WOLFSSL_NO_FORCE_ZERO
  2455. #endif
  2456. /* Detect old cryptodev name */
  2457. #if defined(WOLF_CRYPTO_DEV) && !defined(WOLF_CRYPTO_CB)
  2458. #define WOLF_CRYPTO_CB
  2459. #endif
  2460. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_NO_SIGALG)
  2461. #error TLS 1.3 requires the Signature Algorithms extension to be enabled
  2462. #endif
  2463. #ifndef NO_WOLFSSL_BASE64_DECODE
  2464. #define WOLFSSL_BASE64_DECODE
  2465. #endif
  2466. #if defined(HAVE_EX_DATA) || defined(FORTRESS)
  2467. #if defined(FORTRESS) && !defined(HAVE_EX_DATA)
  2468. #define HAVE_EX_DATA
  2469. #endif
  2470. #ifndef MAX_EX_DATA
  2471. #define MAX_EX_DATA 5 /* allow for five items of ex_data */
  2472. #endif
  2473. #endif
  2474. #ifdef NO_WOLFSSL_SMALL_STACK
  2475. #undef WOLFSSL_SMALL_STACK
  2476. #endif
  2477. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SMALL_STACK_STATIC) && \
  2478. !defined(NO_WOLFSSL_SMALL_STACK_STATIC)
  2479. #define WOLFSSL_SMALL_STACK_STATIC
  2480. #endif
  2481. #ifdef WOLFSSL_SMALL_STACK_STATIC
  2482. #undef WOLFSSL_SMALL_STACK_STATIC
  2483. #define WOLFSSL_SMALL_STACK_STATIC static
  2484. #else
  2485. #define WOLFSSL_SMALL_STACK_STATIC
  2486. #endif
  2487. /* The client session cache requires time for timeout */
  2488. #if defined(NO_ASN_TIME) && !defined(NO_SESSION_CACHE)
  2489. #define NO_SESSION_CACHE
  2490. #endif
  2491. #if defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  2492. #define WOLFSSL_NO_DEF_TICKET_ENC_CB
  2493. #endif
  2494. #if defined(NO_ASN_TIME) && defined(HAVE_SESSION_TICKET)
  2495. #undef HAVE_SESSION_TICKET
  2496. #endif
  2497. /* Use static ECC structs for Position Independent Code (PIC) */
  2498. #if defined(__IAR_SYSTEMS_ICC__) && defined(__ROPI__)
  2499. #define WOLFSSL_ECC_CURVE_STATIC
  2500. #define WOLFSSL_NAMES_STATIC
  2501. #define WOLFSSL_NO_CONSTCHARCONST
  2502. #endif
  2503. /* FIPS v1 does not support TLS v1.3 (requires RSA PSS and HKDF) */
  2504. #if FIPS_VERSION_EQ(1,0)
  2505. #undef WC_RSA_PSS
  2506. #undef WOLFSSL_TLS13
  2507. #endif
  2508. /* FIPS v2 does not support WOLFSSL_PSS_LONG_SALT */
  2509. #if FIPS_VERSION_EQ(2,0)
  2510. #ifdef WOLFSSL_PSS_LONG_SALT
  2511. #undef WOLFSSL_PSS_LONG_SALT
  2512. #endif
  2513. #endif
  2514. /* For FIPSv2 make sure the ECDSA encoding allows extra bytes
  2515. * but make sure users consider enabling it */
  2516. #if !defined(NO_STRICT_ECDSA_LEN) && FIPS_VERSION_GE(2,0)
  2517. /* ECDSA length checks off by default for CAVP testing
  2518. * consider enabling strict checks in production */
  2519. #define NO_STRICT_ECDSA_LEN
  2520. #endif
  2521. /* Do not allow using small stack with no malloc */
  2522. #if defined(WOLFSSL_NO_MALLOC) && \
  2523. (defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_SMALL_STACK_CACHE))
  2524. #error Small stack cannot be used with no malloc (WOLFSSL_NO_MALLOC)
  2525. #endif
  2526. /* If malloc is disabled make sure it is also disabled in SP math */
  2527. #if defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_SP_NO_MALLOC) && \
  2528. (defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL))
  2529. #define WOLFSSL_SP_NO_MALLOC
  2530. #endif
  2531. /* Enable DH Extra for QT, openssl all, openssh and static ephemeral */
  2532. /* Allows export/import of DH key and params as DER */
  2533. #if !defined(NO_DH) && !defined(WOLFSSL_DH_EXTRA) && \
  2534. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH) || \
  2535. defined(WOLFSSL_STATIC_EPHEMERAL))
  2536. #define WOLFSSL_DH_EXTRA
  2537. #endif
  2538. /* DH Extra is not supported on FIPS v1 or v2 (is missing DhKey .pub/.priv) */
  2539. #if defined(WOLFSSL_DH_EXTRA) && defined(HAVE_FIPS) && FIPS_VERSION_LE(2,0)
  2540. #undef WOLFSSL_DH_EXTRA
  2541. #endif
  2542. /* wc_Sha512.devId isn't available before FIPS 5.1 */
  2543. #if defined(HAVE_FIPS) && FIPS_VERSION_LT(5,1)
  2544. #define NO_SHA2_CRYPTO_CB
  2545. #endif
  2546. /* Enable HAVE_ONE_TIME_AUTH by default for use with TLS cipher suites
  2547. * when poly1305 is enabled
  2548. */
  2549. #if defined(HAVE_POLY1305) && !defined(HAVE_ONE_TIME_AUTH)
  2550. #define HAVE_ONE_TIME_AUTH
  2551. #endif
  2552. /* Check for insecure build combination:
  2553. * secure renegotiation [enabled]
  2554. * extended master secret [disabled]
  2555. * session resumption [enabled]
  2556. */
  2557. #if defined(HAVE_SECURE_RENEGOTIATION) && !defined(HAVE_EXTENDED_MASTER) && \
  2558. (defined(HAVE_SESSION_TICKET) || !defined(NO_SESSION_CACHE))
  2559. /* secure renegotiation requires extended master secret with resumption */
  2560. #ifndef _MSC_VER
  2561. #warning Extended master secret must be enabled with secure renegotiation and session resumption
  2562. #else
  2563. #pragma message("Warning: Extended master secret must be enabled with secure renegotiation and session resumption")
  2564. #endif
  2565. /* Note: "--enable-renegotiation-indication" ("HAVE_RENEGOTIATION_INDICATION")
  2566. * only sends the secure renegotiation extension, but is not actually supported.
  2567. * This was added because some TLS peers required it even if not used, so we call
  2568. * this "(FAKE Secure Renegotiation)"
  2569. */
  2570. #endif
  2571. /* if secure renegotiation is enabled, make sure server info is enabled */
  2572. #if !defined(HAVE_RENEGOTIATION_INDICATION) && \
  2573. !defined(HAVE_SERVER_RENEGOTIATION_INFO) && \
  2574. defined(HAVE_SECURE_RENEGOTIATION) && \
  2575. !defined(NO_WOLFSSL_SERVER)
  2576. #define HAVE_SERVER_RENEGOTIATION_INFO
  2577. #endif
  2578. /* Crypto callbacks should enable hash flag support */
  2579. #if defined(WOLF_CRYPTO_CB) && !defined(WOLFSSL_HASH_FLAGS)
  2580. /* FIPS v1 and v2 do not support hash flags, so do not allow it with
  2581. * crypto callbacks */
  2582. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS) && \
  2583. defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION >= 3)
  2584. #define WOLFSSL_HASH_FLAGS
  2585. #endif
  2586. #endif
  2587. #ifdef WOLFSSL_HAVE_KYBER
  2588. #define HAVE_PQC
  2589. #endif
  2590. /* Enable Post-Quantum Cryptography if we have liboqs from the OpenQuantumSafe
  2591. * group */
  2592. #ifdef HAVE_LIBOQS
  2593. #define HAVE_PQC
  2594. #define HAVE_FALCON
  2595. #define HAVE_DILITHIUM
  2596. #ifndef WOLFSSL_NO_SPHINCS
  2597. #define HAVE_SPHINCS
  2598. #endif
  2599. #ifndef WOLFSSL_HAVE_KYBER
  2600. #define WOLFSSL_HAVE_KYBER
  2601. #define WOLFSSL_KYBER512
  2602. #define WOLFSSL_KYBER768
  2603. #define WOLFSSL_KYBER1024
  2604. #endif
  2605. #endif
  2606. #ifdef HAVE_PQM4
  2607. #define HAVE_PQC
  2608. #define WOLFSSL_HAVE_KYBER
  2609. #define WOLFSSL_KYBER512
  2610. #define WOLFSSL_NO_KYBER768
  2611. #define WOLFSSL_NO_KYBER1024
  2612. #endif
  2613. #if defined(HAVE_PQC) && !defined(HAVE_LIBOQS) && !defined(HAVE_PQM4) && \
  2614. !defined(WOLFSSL_HAVE_KYBER)
  2615. #error Please do not define HAVE_PQC yourself.
  2616. #endif
  2617. #if defined(HAVE_PQC) && defined(HAVE_LIBOQS) && defined(HAVE_PQM4)
  2618. #error Please do not define both HAVE_LIBOQS and HAVE_PQM4.
  2619. #endif
  2620. #if defined(HAVE_PQC) && defined(WOLFSSL_DTLS13) && \
  2621. !defined(WOLFSSL_DTLS_CH_FRAG)
  2622. #warning "Using DTLS 1.3 + pqc without WOLFSSL_DTLS_CH_FRAG will probably" \
  2623. "fail.Use --enable-dtls-frag-ch to enable it."
  2624. #endif
  2625. #if !defined(WOLFSSL_DTLS13) && defined(WOLFSSL_DTLS_CH_FRAG)
  2626. #error "WOLFSSL_DTLS_CH_FRAG only works with DTLS 1.3"
  2627. #endif
  2628. /* SRTP requires DTLS */
  2629. #if defined(WOLFSSL_SRTP) && !defined(WOLFSSL_DTLS)
  2630. #error The SRTP extension requires DTLS
  2631. #endif
  2632. /* Are we using an external private key store like:
  2633. * PKCS11 / HSM / crypto callback / PK callback */
  2634. #if !defined(WOLF_PRIVATE_KEY_ID) && !defined(NO_WOLF_PRIVATE_KEY_ID) && \
  2635. (defined(HAVE_PKCS11) || defined(HAVE_PK_CALLBACKS) || \
  2636. defined(WOLF_CRYPTO_CB) || defined(WOLFSSL_KCAPI))
  2637. /* Enables support for using wolfSSL_CTX_use_PrivateKey_Id and
  2638. * wolfSSL_CTX_use_PrivateKey_Label */
  2639. #define WOLF_PRIVATE_KEY_ID
  2640. #endif
  2641. /* With titan cache size there is too many sessions to fit with the default
  2642. * multiplier of 8 */
  2643. #if defined(TITAN_SESSION_CACHE) && !defined(NO_SESSION_CACHE_REF)
  2644. #define NO_SESSION_CACHE_REF
  2645. #endif
  2646. /* (D)TLS v1.3 requires 64-bit number wrappers */
  2647. #if defined(WOLFSSL_TLS13) || defined(WOLFSSL_DTLS_DROP_STATS)
  2648. #undef WOLFSSL_W64_WRAPPER
  2649. #define WOLFSSL_W64_WRAPPER
  2650. #endif
  2651. /* DTLS v1.3 requires AES ECB if using AES */
  2652. #if defined(WOLFSSL_DTLS13) && !defined(NO_AES) && \
  2653. !defined(WOLFSSL_AES_DIRECT)
  2654. #define WOLFSSL_AES_DIRECT
  2655. #endif
  2656. #if defined(WOLFSSL_DTLS13) && (!defined(WOLFSSL_DTLS) || \
  2657. !defined(WOLFSSL_TLS13))
  2658. #error "DTLS v1.3 requires both WOLFSSL_TLS13 and WOLFSSL_DTLS"
  2659. #endif
  2660. #if defined(WOLFSSL_DTLS_CID) && !defined(WOLFSSL_DTLS13)
  2661. #error "ConnectionID is supported for DTLSv1.3 only"
  2662. #endif
  2663. /* RSA Key Checking is disabled by default unless WOLFSSL_RSA_KEY_CHECK is
  2664. * defined or FIPS v2 3389, FIPS v5 or later.
  2665. * Not allowed for:
  2666. * RSA public only, CAVP selftest, fast RSA, user RSA, QAT or CryptoCell */
  2667. #if (defined(WOLFSSL_RSA_KEY_CHECK) || (defined(HAVE_FIPS) && FIPS_VERSION_GE(2,0))) && \
  2668. !defined(WOLFSSL_NO_RSA_KEY_CHECK) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  2669. !defined(HAVE_USER_RSA) && !defined(HAVE_FAST_RSA) && \
  2670. !defined(HAVE_INTEL_QA) && !defined(WOLFSSL_CRYPTOCELL) && \
  2671. !defined(HAVE_SELFTEST)
  2672. #undef WOLFSSL_RSA_KEY_CHECK
  2673. #define WOLFSSL_RSA_KEY_CHECK
  2674. #endif
  2675. /* SHAKE - Not allowed in FIPS */
  2676. #if defined(WOLFSSL_SHA3) && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  2677. #ifndef WOLFSSL_NO_SHAKE128
  2678. #undef WOLFSSL_SHAKE128
  2679. #define WOLFSSL_SHAKE128
  2680. #endif
  2681. #ifndef WOLFSSL_NO_SHAKE256
  2682. #undef WOLFSSL_SHAKE256
  2683. #define WOLFSSL_SHAKE256
  2684. #endif
  2685. #else
  2686. #undef WOLFSSL_NO_SHAKE128
  2687. #define WOLFSSL_NO_SHAKE128
  2688. #undef WOLFSSL_NO_SHAKE256
  2689. #define WOLFSSL_NO_SHAKE256
  2690. #endif
  2691. /* Encrypted Client Hello - requires HPKE */
  2692. #if defined(HAVE_ECH) && !defined(HAVE_HPKE)
  2693. #define HAVE_HPKE
  2694. #endif
  2695. /* Provide way to forcefully disable use of XREALLOC */
  2696. #ifdef WOLFSSL_NO_REALLOC
  2697. #undef XREALLOC
  2698. #endif
  2699. /* ---------------------------------------------------------------------------
  2700. * Deprecated Algorithm Handling
  2701. * Unless allowed via a build macro, disable support
  2702. * ---------------------------------------------------------------------------*/
  2703. /* RC4: Per RFC7465 Feb 2015, the cipher suite has been deprecated due to a
  2704. * number of exploits capable of decrypting portions of encrypted messages. */
  2705. #ifndef WOLFSSL_ALLOW_RC4
  2706. #undef NO_RC4
  2707. #define NO_RC4
  2708. #endif
  2709. #if !defined(WOLFSSL_NO_ASYNC_IO) || defined(WOLFSSL_ASYNC_CRYPT) || \
  2710. defined(WOLFSSL_NONBLOCK_OCSP)
  2711. /* Enable asynchronous support in TLS functions to support one or more of
  2712. * the following:
  2713. * - re-entry after a network blocking return
  2714. * - re-entry after OCSP blocking return
  2715. * - asynchronous cryptography */
  2716. #undef WOLFSSL_ASYNC_IO
  2717. #define WOLFSSL_ASYNC_IO
  2718. #endif
  2719. #ifdef WOLFSSL_SYS_CA_CERTS
  2720. #ifdef NO_FILESYSTEM
  2721. /* Turning off WOLFSSL_SYS_CA_CERTS b/c NO_FILESYSTEM is defined */
  2722. #undef WOLFSSL_SYS_CA_CERTS
  2723. #endif
  2724. #ifdef NO_CERTS
  2725. /* Turning off WOLFSSL_SYS_CA_CERTS b/c NO_CERTS is defined */
  2726. #undef WOLFSSL_SYS_CA_CERTS
  2727. #endif
  2728. #endif /* WOLFSSL_SYS_CA_CERTS */
  2729. #if defined(SESSION_CACHE_DYNAMIC_MEM) && defined(PERSIST_SESSION_CACHE)
  2730. #error "Dynamic session cache currently does not support persistent session cache."
  2731. #endif
  2732. #ifdef WOLFSSL_HARDEN_TLS
  2733. #if defined(HAVE_TRUNCATED_HMAC) && !defined(WOLFSSL_HARDEN_TLS_ALLOW_TRUNCATED_HMAC)
  2734. #error "Truncated HMAC Extension not allowed https://www.rfc-editor.org/rfc/rfc9325#section-4.6"
  2735. #endif
  2736. #if !defined(NO_OLD_TLS) && !defined(WOLFSSL_HARDEN_TLS_ALLOW_OLD_TLS)
  2737. #error "TLS < 1.2 protocol versions not allowed https://www.rfc-editor.org/rfc/rfc9325#section-3.1.1"
  2738. #endif
  2739. #if !defined(WOLFSSL_NO_TLS12) && !defined(HAVE_SECURE_RENEGOTIATION) && \
  2740. !defined(HAVE_SERVER_RENEGOTIATION_INFO) && !defined(WOLFSSL_HARDEN_TLS_NO_SCR_CHECK)
  2741. #error "TLS 1.2 requires at least HAVE_SERVER_RENEGOTIATION_INFO to send the secure renegotiation extension https://www.rfc-editor.org/rfc/rfc9325#section-3.5"
  2742. #endif
  2743. #if !defined(WOLFSSL_EXTRA_ALERTS) || !defined(WOLFSSL_CHECK_ALERT_ON_ERR)
  2744. #error "RFC9325 requires some additional alerts to be sent"
  2745. #endif
  2746. /* Ciphersuite check done in internal.h */
  2747. #endif
  2748. #ifdef __cplusplus
  2749. } /* extern "C" */
  2750. #endif
  2751. #endif