settings.h 99 KB

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