settings.h 84 KB

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