settings.h 99 KB

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