settings.h 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884
  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. #if !defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  1411. #define NO_DEV_RANDOM
  1412. #endif
  1413. #define NO_WOLFSSL_DIR
  1414. #define HAVE_AESGCM
  1415. #endif
  1416. #if defined(WOLFSSL_XILINX_CRYPT) || defined(WOLFSSL_AFALG_XILINX)
  1417. #if defined(WOLFSSL_ARMASM)
  1418. #error can not use both ARMv8 instructions and XILINX hardened crypto
  1419. #endif
  1420. #if defined(WOLFSSL_SHA3)
  1421. /* only SHA3-384 is supported */
  1422. #undef WOLFSSL_NOSHA3_224
  1423. #undef WOLFSSL_NOSHA3_256
  1424. #undef WOLFSSL_NOSHA3_512
  1425. #define WOLFSSL_NOSHA3_224
  1426. #define WOLFSSL_NOSHA3_256
  1427. #define WOLFSSL_NOSHA3_512
  1428. #endif
  1429. #ifdef WOLFSSL_AFALG_XILINX_AES
  1430. #undef WOLFSSL_AES_DIRECT
  1431. #define WOLFSSL_AES_DIRECT
  1432. #endif
  1433. #endif /*(WOLFSSL_XILINX_CRYPT)*/
  1434. #ifdef WOLFSSL_KCAPI_AES
  1435. #define WOLFSSL_AES_GCM_FIXED_IV_AAD
  1436. #endif
  1437. #ifdef WOLFSSL_KCAPI_ECC
  1438. #undef ECC_USER_CURVES
  1439. #define ECC_USER_CURVES
  1440. #undef NO_ECC256
  1441. #undef HAVE_ECC384
  1442. #define HAVE_ECC384
  1443. #undef HAVE_ECC521
  1444. #define HAVE_ECC521
  1445. #endif
  1446. #if defined(WOLFSSL_APACHE_MYNEWT)
  1447. #include "os/os_malloc.h"
  1448. #if !defined(WOLFSSL_LWIP)
  1449. #include <mn_socket/mn_socket.h>
  1450. #endif
  1451. #if !defined(SIZEOF_LONG)
  1452. #define SIZEOF_LONG 4
  1453. #endif
  1454. #if !defined(SIZEOF_LONG_LONG)
  1455. #define SIZEOF_LONG_LONG 8
  1456. #endif
  1457. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  1458. #define BIG_ENDIAN_ORDER
  1459. #else
  1460. #undef BIG_ENDIAN_ORDER
  1461. #define LITTLE_ENDIAN_ORDER
  1462. #endif
  1463. #define NO_WRITEV
  1464. #define WOLFSSL_USER_IO
  1465. #define SINGLE_THREADED
  1466. #define NO_DEV_RANDOM
  1467. #define NO_DH
  1468. #define NO_WOLFSSL_DIR
  1469. #define NO_ERROR_STRINGS
  1470. #define HAVE_ECC
  1471. #define NO_SESSION_CACHE
  1472. #define NO_ERROR_STRINGS
  1473. #define XMALLOC_USER
  1474. #define XMALLOC(sz, heap, type) os_malloc(sz)
  1475. #define XREALLOC(p, sz, heap, type) os_realloc(p, sz)
  1476. #define XFREE(p, heap, type) os_free(p)
  1477. #endif /*(WOLFSSL_APACHE_MYNEWT)*/
  1478. #ifdef WOLFSSL_ZEPHYR
  1479. #include <zephyr.h>
  1480. #include <sys/printk.h>
  1481. #include <sys/util.h>
  1482. #include <stdlib.h>
  1483. #define WOLFSSL_DH_CONST
  1484. #define WOLFSSL_HAVE_MAX
  1485. #define NO_WRITEV
  1486. #define USE_FLAT_BENCHMARK_H
  1487. #define USE_FLAT_TEST_H
  1488. #define EXIT_FAILURE 1
  1489. #define MAIN_NO_ARGS
  1490. void *z_realloc(void *ptr, size_t size);
  1491. #define realloc z_realloc
  1492. #ifndef CONFIG_NET_SOCKETS_POSIX_NAMES
  1493. #define CONFIG_NET_SOCKETS_POSIX_NAMES
  1494. #endif
  1495. #endif
  1496. #ifdef WOLFSSL_IMX6
  1497. #ifndef SIZEOF_LONG_LONG
  1498. #define SIZEOF_LONG_LONG 8
  1499. #endif
  1500. #endif
  1501. /* if defined turn on all CAAM support */
  1502. #ifdef WOLFSSL_IMX6_CAAM
  1503. #undef WOLFSSL_IMX6_CAAM_RNG
  1504. #define WOLFSSL_IMX6_CAAM_RNG
  1505. #undef WOLFSSL_IMX6_CAAM_BLOB
  1506. #define WOLFSSL_IMX6_CAAM_BLOB
  1507. #if defined(HAVE_AESGCM) || defined(WOLFSSL_AES_XTS)
  1508. /* large performance gain with HAVE_AES_ECB defined */
  1509. #undef HAVE_AES_ECB
  1510. #define HAVE_AES_ECB
  1511. /* @TODO used for now until plugging in caam aes use with qnx */
  1512. #undef WOLFSSL_AES_DIRECT
  1513. #define WOLFSSL_AES_DIRECT
  1514. #endif
  1515. #endif
  1516. /* If DCP is used without SINGLE_THREADED, enforce WOLFSSL_CRYPT_HW_MUTEX */
  1517. #if defined(WOLFSSL_IMXRT_DCP) && !defined(SINGLE_THREADED)
  1518. #undef WOLFSSL_CRYPT_HW_MUTEX
  1519. #define WOLFSSL_CRYPT_HW_MUTEX 1
  1520. #endif
  1521. #if !defined(XMALLOC_USER) && !defined(MICRIUM_MALLOC) && \
  1522. !defined(WOLFSSL_LEANPSK) && !defined(NO_WOLFSSL_MEMORY) && \
  1523. !defined(XMALLOC_OVERRIDE)
  1524. #define USE_WOLFSSL_MEMORY
  1525. #endif
  1526. #ifdef WOLFSSL_EMBOS
  1527. #include "RTOS.h"
  1528. #if !defined(XMALLOC_USER) && !defined(NO_WOLFSSL_MEMORY) && \
  1529. !defined(WOLFSSL_STATIC_MEMORY)
  1530. #define XMALLOC(s, h, type) OS_HEAP_malloc((s))
  1531. #define XFREE(p, h, type) OS_HEAP_free((p))
  1532. #define XREALLOC(p, n, h, t) OS_HEAP_realloc(((p), (n))
  1533. #endif
  1534. #endif
  1535. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS)
  1536. #undef KEEP_PEER_CERT
  1537. #define KEEP_PEER_CERT
  1538. #endif
  1539. /* stream ciphers except arc4 need 32bit alignment, intel ok without */
  1540. #ifndef XSTREAM_ALIGN
  1541. #if defined(__x86_64__) || defined(__ia64__) || defined(__i386__)
  1542. #define NO_XSTREAM_ALIGN
  1543. #else
  1544. #define XSTREAM_ALIGN
  1545. #endif
  1546. #endif
  1547. /* write dup cannot be used with secure renegotiation because write dup
  1548. * make write side write only and read side read only */
  1549. #if defined(HAVE_WRITE_DUP) && defined(HAVE_SECURE_RENEGOTIATION)
  1550. #error "WRITE DUP and SECURE RENEGOTIATION cannot both be on"
  1551. #endif
  1552. #ifdef WOLFSSL_SGX
  1553. #ifdef _MSC_VER
  1554. #define NO_RC4
  1555. #ifndef HAVE_FIPS
  1556. #define WOLFCRYPT_ONLY
  1557. #define NO_DES3
  1558. #define NO_SHA
  1559. #define NO_MD5
  1560. #else
  1561. #define TFM_TIMING_RESISTANT
  1562. #define NO_WOLFSSL_DIR
  1563. #define NO_WRITEV
  1564. #define NO_MAIN_DRIVER
  1565. #define WOLFSSL_LOG_PRINTF
  1566. #define WOLFSSL_DH_CONST
  1567. #endif
  1568. #else
  1569. #define HAVE_ECC
  1570. #define NO_WRITEV
  1571. #define NO_MAIN_DRIVER
  1572. #define USER_TICKS
  1573. #define WOLFSSL_LOG_PRINTF
  1574. #define WOLFSSL_DH_CONST
  1575. #endif /* _MSC_VER */
  1576. #if !defined(HAVE_FIPS) && !defined(NO_RSA)
  1577. #define WC_RSA_BLINDING
  1578. #endif
  1579. #define NO_FILESYSTEM
  1580. #define ECC_TIMING_RESISTANT
  1581. #define TFM_TIMING_RESISTANT
  1582. #define SINGLE_THREADED
  1583. #define NO_ASN_TIME /* can not use headers such as windows.h */
  1584. #define HAVE_AESGCM
  1585. #define USE_CERT_BUFFERS_2048
  1586. #define USE_FAST_MATH
  1587. #endif /* WOLFSSL_SGX */
  1588. /* FreeScale MMCAU hardware crypto has 4 byte alignment.
  1589. However, KSDK fsl_mmcau.h gives API with no alignment
  1590. requirements (4 byte alignment is managed internally by fsl_mmcau.c) */
  1591. #ifdef FREESCALE_MMCAU
  1592. #ifdef FREESCALE_MMCAU_CLASSIC
  1593. #define WOLFSSL_MMCAU_ALIGNMENT 4
  1594. #else
  1595. #define WOLFSSL_MMCAU_ALIGNMENT 0
  1596. #endif
  1597. #endif
  1598. /* if using hardware crypto and have alignment requirements, specify the
  1599. requirement here. The record header of SSL/TLS will prevent easy alignment.
  1600. This hint tries to help as much as possible. */
  1601. #ifndef WOLFSSL_GENERAL_ALIGNMENT
  1602. #ifdef WOLFSSL_AESNI
  1603. #define WOLFSSL_GENERAL_ALIGNMENT 16
  1604. #elif defined(XSTREAM_ALIGN)
  1605. #define WOLFSSL_GENERAL_ALIGNMENT 4
  1606. #elif defined(FREESCALE_MMCAU) || defined(FREESCALE_MMCAU_CLASSIC)
  1607. #define WOLFSSL_GENERAL_ALIGNMENT WOLFSSL_MMCAU_ALIGNMENT
  1608. #else
  1609. #define WOLFSSL_GENERAL_ALIGNMENT 0
  1610. #endif
  1611. #endif
  1612. #if defined(WOLFSSL_GENERAL_ALIGNMENT) && (WOLFSSL_GENERAL_ALIGNMENT > 0)
  1613. #if defined(_MSC_VER)
  1614. #define XGEN_ALIGN __declspec(align(WOLFSSL_GENERAL_ALIGNMENT))
  1615. #elif defined(__GNUC__)
  1616. #define XGEN_ALIGN __attribute__((aligned(WOLFSSL_GENERAL_ALIGNMENT)))
  1617. #else
  1618. #define XGEN_ALIGN
  1619. #endif
  1620. #else
  1621. #define XGEN_ALIGN
  1622. #endif
  1623. #ifdef __INTEL_COMPILER
  1624. #pragma warning(disable:2259) /* explicit casts to smaller sizes, disable */
  1625. #endif
  1626. /* ---------------------------------------------------------------------------
  1627. * Math Library Selection (in order of preference)
  1628. * ---------------------------------------------------------------------------
  1629. */
  1630. #if !defined(HAVE_FIPS_VERSION) || \
  1631. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  1632. #if defined(WOLFSSL_SP_MATH_ALL)
  1633. /* 1) SP Math: wolfSSL proprietary math implementation (sp_int.c).
  1634. * Constant time: Always
  1635. * Enable: WOLFSSL_SP_MATH_ALL
  1636. */
  1637. #elif defined(WOLFSSL_SP_MATH)
  1638. /* 2) SP Math with restricted key sizes: wolfSSL proprietary math
  1639. * implementation (sp_*.c).
  1640. * Constant time: Always
  1641. * Enable: WOLFSSL_SP_MATH
  1642. */
  1643. #elif defined(USE_FAST_MATH)
  1644. /* 3) Tom's Fast Math: Stack based (tfm.c)
  1645. * Constant time: Only with TFM_TIMING_RESISTANT
  1646. * Enable: USE_FAST_MATH
  1647. */
  1648. #elif defined(USE_INTEGER_HEAP_MATH)
  1649. /* 4) Integer Heap Math: Heap based (integer.c)
  1650. * Constant time: Not supported
  1651. * Enable: USE_INTEGER_HEAP_MATH
  1652. */
  1653. #else
  1654. /* default is SP Math. */
  1655. #define WOLFSSL_SP_MATH_ALL
  1656. #endif
  1657. #else
  1658. /* FIPS 140-2 or older */
  1659. /* Default to fast math (tfm.c), but allow heap math (integer.c) */
  1660. #if !defined(USE_INTEGER_HEAP_MATH)
  1661. #undef USE_FAST_MATH
  1662. #define USE_FAST_MATH
  1663. #ifndef FP_MAX_BITS
  1664. #define FP_MAX_BITS 8192
  1665. #endif
  1666. #endif
  1667. #endif
  1668. /*----------------------------------------------------------------------------*/
  1669. /* user can specify what curves they want with ECC_USER_CURVES otherwise
  1670. * all curves are on by default for now */
  1671. #ifndef ECC_USER_CURVES
  1672. #ifdef WOLFSSL_SP_MATH
  1673. /* for single precision math only make sure the enabled key sizes are
  1674. * included in the ECC curve table */
  1675. #if defined(WOLFSSL_SP_384) && !defined(HAVE_ECC384)
  1676. #define HAVE_ECC384
  1677. #endif
  1678. #if defined(WOLFSSL_SP_521) && !defined(HAVE_ECC521)
  1679. #define HAVE_ECC521
  1680. #endif
  1681. #elif !defined(HAVE_ALL_CURVES)
  1682. #define HAVE_ALL_CURVES
  1683. #endif
  1684. #endif
  1685. /* The minimum allowed ECC key size */
  1686. /* Note: 224-bits is equivalent to 2048-bit RSA */
  1687. #ifndef ECC_MIN_KEY_SZ
  1688. #ifdef WOLFSSL_MIN_ECC_BITS
  1689. #define ECC_MIN_KEY_SZ WOLFSSL_MIN_ECC_BITS
  1690. #else
  1691. #if FIPS_VERSION_GE(2,0)
  1692. /* FIPSv2 and ready (for now) includes 192-bit support */
  1693. #define ECC_MIN_KEY_SZ 192
  1694. #else
  1695. #define ECC_MIN_KEY_SZ 224
  1696. #endif
  1697. #endif
  1698. #endif
  1699. /* ECC Configs */
  1700. #ifdef HAVE_ECC
  1701. /* By default enable Sign, Verify, DHE, Key Import and Key Export unless explicitly disabled */
  1702. #if !defined(NO_ECC_SIGN) && \
  1703. (!defined(ECC_TIMING_RESISTANT) || \
  1704. (defined(ECC_TIMING_RESISTANT) && !defined(WC_NO_RNG)))
  1705. #undef HAVE_ECC_SIGN
  1706. #define HAVE_ECC_SIGN
  1707. #endif
  1708. #ifndef NO_ECC_VERIFY
  1709. #undef HAVE_ECC_VERIFY
  1710. #define HAVE_ECC_VERIFY
  1711. #endif
  1712. #ifndef NO_ECC_CHECK_KEY
  1713. #undef HAVE_ECC_CHECK_KEY
  1714. #define HAVE_ECC_CHECK_KEY
  1715. #endif
  1716. #if !defined(NO_ECC_DHE) && !defined(WC_NO_RNG)
  1717. #undef HAVE_ECC_DHE
  1718. #define HAVE_ECC_DHE
  1719. #endif
  1720. #ifndef NO_ECC_KEY_IMPORT
  1721. #undef HAVE_ECC_KEY_IMPORT
  1722. #define HAVE_ECC_KEY_IMPORT
  1723. #endif
  1724. #ifndef NO_ECC_KEY_EXPORT
  1725. #undef HAVE_ECC_KEY_EXPORT
  1726. #define HAVE_ECC_KEY_EXPORT
  1727. #endif
  1728. #endif /* HAVE_ECC */
  1729. /* Curve25519 Configs */
  1730. #ifdef HAVE_CURVE25519
  1731. /* By default enable shared secret, key export and import */
  1732. #ifndef NO_CURVE25519_SHARED_SECRET
  1733. #undef HAVE_CURVE25519_SHARED_SECRET
  1734. #define HAVE_CURVE25519_SHARED_SECRET
  1735. #endif
  1736. #ifndef NO_CURVE25519_KEY_EXPORT
  1737. #undef HAVE_CURVE25519_KEY_EXPORT
  1738. #define HAVE_CURVE25519_KEY_EXPORT
  1739. #endif
  1740. #ifndef NO_CURVE25519_KEY_IMPORT
  1741. #undef HAVE_CURVE25519_KEY_IMPORT
  1742. #define HAVE_CURVE25519_KEY_IMPORT
  1743. #endif
  1744. #endif /* HAVE_CURVE25519 */
  1745. /* Ed25519 Configs */
  1746. #ifdef HAVE_ED25519
  1747. /* By default enable sign, verify, key export and import */
  1748. #ifndef NO_ED25519_SIGN
  1749. #undef HAVE_ED25519_SIGN
  1750. #define HAVE_ED25519_SIGN
  1751. #endif
  1752. #ifndef NO_ED25519_VERIFY
  1753. #undef HAVE_ED25519_VERIFY
  1754. #define HAVE_ED25519_VERIFY
  1755. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  1756. #undef WOLFSSL_ED25519_PERSISTENT_SHA
  1757. #define WOLFSSL_ED25519_PERSISTENT_SHA
  1758. #endif
  1759. #endif
  1760. #ifndef NO_ED25519_KEY_EXPORT
  1761. #undef HAVE_ED25519_KEY_EXPORT
  1762. #define HAVE_ED25519_KEY_EXPORT
  1763. #endif
  1764. #ifndef NO_ED25519_KEY_IMPORT
  1765. #undef HAVE_ED25519_KEY_IMPORT
  1766. #define HAVE_ED25519_KEY_IMPORT
  1767. #endif
  1768. #endif /* HAVE_ED25519 */
  1769. /* Curve448 Configs */
  1770. #ifdef HAVE_CURVE448
  1771. /* By default enable shared secret, key export and import */
  1772. #ifndef NO_CURVE448_SHARED_SECRET
  1773. #undef HAVE_CURVE448_SHARED_SECRET
  1774. #define HAVE_CURVE448_SHARED_SECRET
  1775. #endif
  1776. #ifndef NO_CURVE448_KEY_EXPORT
  1777. #undef HAVE_CURVE448_KEY_EXPORT
  1778. #define HAVE_CURVE448_KEY_EXPORT
  1779. #endif
  1780. #ifndef NO_CURVE448_KEY_IMPORT
  1781. #undef HAVE_CURVE448_KEY_IMPORT
  1782. #define HAVE_CURVE448_KEY_IMPORT
  1783. #endif
  1784. #endif /* HAVE_CURVE448 */
  1785. /* Ed448 Configs */
  1786. #ifdef HAVE_ED448
  1787. /* By default enable sign, verify, key export and import */
  1788. #ifndef NO_ED448_SIGN
  1789. #undef HAVE_ED448_SIGN
  1790. #define HAVE_ED448_SIGN
  1791. #endif
  1792. #ifndef NO_ED448_VERIFY
  1793. #undef HAVE_ED448_VERIFY
  1794. #define HAVE_ED448_VERIFY
  1795. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  1796. #undef WOLFSSL_ED448_PERSISTENT_SHA
  1797. #define WOLFSSL_ED448_PERSISTENT_SHA
  1798. #endif
  1799. #endif
  1800. #ifndef NO_ED448_KEY_EXPORT
  1801. #undef HAVE_ED448_KEY_EXPORT
  1802. #define HAVE_ED448_KEY_EXPORT
  1803. #endif
  1804. #ifndef NO_ED448_KEY_IMPORT
  1805. #undef HAVE_ED448_KEY_IMPORT
  1806. #define HAVE_ED448_KEY_IMPORT
  1807. #endif
  1808. #endif /* HAVE_ED448 */
  1809. /* AES Config */
  1810. #ifndef NO_AES
  1811. /* By default enable all AES key sizes, decryption and CBC */
  1812. #ifndef AES_MAX_KEY_SIZE
  1813. #undef AES_MAX_KEY_SIZE
  1814. #define AES_MAX_KEY_SIZE 256
  1815. #endif
  1816. #ifndef NO_AES_128
  1817. #undef WOLFSSL_AES_128
  1818. #define WOLFSSL_AES_128
  1819. #endif
  1820. #if !defined(NO_AES_192) && AES_MAX_KEY_SIZE >= 192
  1821. #undef WOLFSSL_AES_192
  1822. #define WOLFSSL_AES_192
  1823. #endif
  1824. #if !defined(NO_AES_256) && AES_MAX_KEY_SIZE >= 256
  1825. #undef WOLFSSL_AES_256
  1826. #define WOLFSSL_AES_256
  1827. #endif
  1828. #if !defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AES_256) && \
  1829. defined(HAVE_ECC_ENCRYPT)
  1830. #warning HAVE_ECC_ENCRYPT uses AES 128/256 bit keys
  1831. #endif
  1832. #ifndef NO_AES_DECRYPT
  1833. #undef HAVE_AES_DECRYPT
  1834. #define HAVE_AES_DECRYPT
  1835. #endif
  1836. #ifndef NO_AES_CBC
  1837. #undef HAVE_AES_CBC
  1838. #define HAVE_AES_CBC
  1839. #endif
  1840. #ifdef WOLFSSL_AES_XTS
  1841. /* AES-XTS makes calls to AES direct functions */
  1842. #ifndef WOLFSSL_AES_DIRECT
  1843. #define WOLFSSL_AES_DIRECT
  1844. #endif
  1845. #endif
  1846. #ifdef WOLFSSL_AES_CFB
  1847. /* AES-CFB makes calls to AES direct functions */
  1848. #ifndef WOLFSSL_AES_DIRECT
  1849. #define WOLFSSL_AES_DIRECT
  1850. #endif
  1851. #endif
  1852. #endif
  1853. #if (defined(WOLFSSL_TLS13) && defined(WOLFSSL_NO_TLS12)) || \
  1854. (!defined(HAVE_AES_CBC) && defined(NO_DES3) && defined(NO_RC4) && \
  1855. !defined(HAVE_CAMELLIA) & !defined(HAVE_NULL_CIPHER))
  1856. #define WOLFSSL_AEAD_ONLY
  1857. #endif
  1858. #if !defined(HAVE_PUBLIC_FFDHE) && !defined(NO_DH) && \
  1859. !defined(WOLFSSL_NO_PUBLIC_FFDHE) && \
  1860. (defined(HAVE_SELFTEST) || FIPS_VERSION_LE(2,0))
  1861. /* This should only be enabled for FIPS v2 or older. It enables use of the
  1862. * older wc_Dh_ffdhe####_Get() API's */
  1863. #define HAVE_PUBLIC_FFDHE
  1864. #endif
  1865. #if !defined(NO_DH) && !defined(HAVE_FFDHE)
  1866. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || \
  1867. defined(HAVE_FFDHE_4096) || defined(HAVE_FFDHE_6144) || \
  1868. defined(HAVE_FFDHE_8192)
  1869. #define HAVE_FFDHE
  1870. #endif
  1871. #endif
  1872. #if defined(HAVE_FFDHE_8192)
  1873. #define MIN_FFDHE_BITS 8192
  1874. #elif defined(HAVE_FFDHE_6144)
  1875. #define MIN_FFDHE_BITS 6144
  1876. #elif defined(HAVE_FFDHE_4096)
  1877. #define MIN_FFDHE_BITS 4096
  1878. #elif defined(HAVE_FFDHE_3072)
  1879. #define MIN_FFDHE_BITS 3072
  1880. #elif defined(HAVE_FFDHE_2048)
  1881. #define MIN_FFDHE_BITS 2048
  1882. #else
  1883. #define MIN_FFDHE_BITS 0
  1884. #endif
  1885. #define MIN_FFDHE_FP_MAX_BITS (MIN_FFDHE_BITS * 2)
  1886. #if defined(HAVE_FFDHE) && defined(FP_MAX_BITS)
  1887. #if MIN_FFDHE_FP_MAX_BITS > FP_MAX_BITS
  1888. #error "FFDHE parameters are too large for FP_MAX_BIT as set"
  1889. #endif
  1890. #endif
  1891. #if defined(HAVE_FFDHE) && defined(SP_INT_BITS)
  1892. #if MIN_FFDHE_BITS > SP_INT_BITS
  1893. #error "FFDHE parameters are too large for SP_INT_BIT as set"
  1894. #endif
  1895. #endif
  1896. /* if desktop type system and fastmath increase default max bits */
  1897. #if defined(WOLFSSL_X86_64_BUILD) || defined(WOLFSSL_AARCH64_BUILD)
  1898. #if defined(USE_FAST_MATH) && !defined(FP_MAX_BITS)
  1899. #if MIN_FFDHE_FP_MAX_BITS <= 8192
  1900. #define FP_MAX_BITS 8192
  1901. #else
  1902. #define FP_MAX_BITS MIN_FFDHE_FP_MAX_BITS
  1903. #endif
  1904. #endif
  1905. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(SP_INT_BITS)
  1906. #ifdef WOLFSSL_MYSQL_COMPATIBLE
  1907. #define SP_INT_BITS 8192
  1908. #elif MIN_FFDHE_BITS <= 4096
  1909. #define SP_INT_BITS 4096
  1910. #else
  1911. #define SP_INT_BITS MIN_FFDHE_BITS
  1912. #endif
  1913. #endif
  1914. #endif
  1915. /* If using the max strength build, ensure OLD TLS is disabled. */
  1916. #ifdef WOLFSSL_MAX_STRENGTH
  1917. #undef NO_OLD_TLS
  1918. #define NO_OLD_TLS
  1919. #endif
  1920. /* Default AES minimum auth tag sz, allow user to override */
  1921. #ifndef WOLFSSL_MIN_AUTH_TAG_SZ
  1922. #define WOLFSSL_MIN_AUTH_TAG_SZ 12
  1923. #endif
  1924. /* sniffer requires:
  1925. * static RSA cipher suites
  1926. * session stats and peak stats
  1927. */
  1928. #ifdef WOLFSSL_SNIFFER
  1929. #ifndef WOLFSSL_STATIC_RSA
  1930. #define WOLFSSL_STATIC_RSA
  1931. #endif
  1932. #ifndef WOLFSSL_STATIC_DH
  1933. #define WOLFSSL_STATIC_DH
  1934. #endif
  1935. /* Allow option to be disabled. */
  1936. #ifndef WOLFSSL_NO_SESSION_STATS
  1937. #ifndef WOLFSSL_SESSION_STATS
  1938. #define WOLFSSL_SESSION_STATS
  1939. #endif
  1940. #ifndef WOLFSSL_PEAK_SESSIONS
  1941. #define WOLFSSL_PEAK_SESSIONS
  1942. #endif
  1943. #endif
  1944. #endif
  1945. /* Decode Public Key extras on by default, user can turn off with
  1946. * WOLFSSL_NO_DECODE_EXTRA */
  1947. #ifndef WOLFSSL_NO_DECODE_EXTRA
  1948. #ifndef RSA_DECODE_EXTRA
  1949. #define RSA_DECODE_EXTRA
  1950. #endif
  1951. #ifndef ECC_DECODE_EXTRA
  1952. #define ECC_DECODE_EXTRA
  1953. #endif
  1954. #endif
  1955. /* C Sharp wrapper defines */
  1956. #ifdef HAVE_CSHARP
  1957. #ifndef WOLFSSL_DTLS
  1958. #define WOLFSSL_DTLS
  1959. #endif
  1960. #undef NO_PSK
  1961. #undef NO_SHA256
  1962. #undef NO_DH
  1963. #endif
  1964. /* Asynchronous Crypto */
  1965. #ifdef WOLFSSL_ASYNC_CRYPT
  1966. #if !defined(HAVE_CAVIUM) && !defined(HAVE_INTEL_QA) && \
  1967. !defined(WOLFSSL_ASYNC_CRYPT_SW)
  1968. #error No async backend defined with WOLFSSL_ASYNC_CRYPT!
  1969. #endif
  1970. /* Make sure wolf events are enabled */
  1971. #undef HAVE_WOLF_EVENT
  1972. #define HAVE_WOLF_EVENT
  1973. #ifdef WOLFSSL_ASYNC_CRYPT_SW
  1974. #define WC_ASYNC_DEV_SIZE 168
  1975. #else
  1976. #define WC_ASYNC_DEV_SIZE 336
  1977. #endif
  1978. /* Enable ECC_CACHE_CURVE for ASYNC */
  1979. #if !defined(ECC_CACHE_CURVE)
  1980. #define ECC_CACHE_CURVE
  1981. #endif
  1982. #endif /* WOLFSSL_ASYNC_CRYPT */
  1983. #ifndef WC_ASYNC_DEV_SIZE
  1984. #define WC_ASYNC_DEV_SIZE 0
  1985. #endif
  1986. /* leantls checks */
  1987. #ifdef WOLFSSL_LEANTLS
  1988. #ifndef HAVE_ECC
  1989. #error leantls build needs ECC
  1990. #endif
  1991. #endif /* WOLFSSL_LEANTLS*/
  1992. /* restriction with static memory */
  1993. #ifdef WOLFSSL_STATIC_MEMORY
  1994. #if defined(HAVE_IO_POOL) || defined(XMALLOC_USER) || defined(NO_WOLFSSL_MEMORY)
  1995. #error static memory cannot be used with HAVE_IO_POOL, XMALLOC_USER or NO_WOLFSSL_MEMORY
  1996. #endif
  1997. #if !defined(WOLFSSL_SP_MATH_ALL) && !defined(USE_FAST_MATH) && \
  1998. !defined(NO_BIG_INT)
  1999. #error The static memory option is only supported for fast math or SP Math
  2000. #endif
  2001. #ifdef WOLFSSL_SMALL_STACK
  2002. #error static memory does not support small stack please undefine
  2003. #endif
  2004. #endif /* WOLFSSL_STATIC_MEMORY */
  2005. #ifdef HAVE_AES_KEYWRAP
  2006. #ifndef WOLFSSL_AES_DIRECT
  2007. #error AES key wrap requires AES direct please define WOLFSSL_AES_DIRECT
  2008. #endif
  2009. #endif
  2010. #ifdef HAVE_PKCS7
  2011. #if defined(NO_AES) && defined(NO_DES3)
  2012. #error PKCS7 needs either AES or 3DES enabled, please enable one
  2013. #endif
  2014. #ifndef HAVE_AES_KEYWRAP
  2015. #error PKCS7 requires AES key wrap please define HAVE_AES_KEYWRAP
  2016. #endif
  2017. #if defined(HAVE_ECC) && !defined(HAVE_X963_KDF)
  2018. #error PKCS7 requires X963 KDF please define HAVE_X963_KDF
  2019. #endif
  2020. #endif
  2021. #ifndef NO_PKCS12
  2022. #undef HAVE_PKCS12
  2023. #define HAVE_PKCS12
  2024. #endif
  2025. #if !defined(NO_PKCS8) || defined(HAVE_PKCS12)
  2026. #undef HAVE_PKCS8
  2027. #define HAVE_PKCS8
  2028. #endif
  2029. #if !defined(NO_PBKDF1) || defined(WOLFSSL_ENCRYPTED_KEYS) || \
  2030. defined(HAVE_PKCS8) || defined(HAVE_PKCS12)
  2031. #undef HAVE_PBKDF1
  2032. #define HAVE_PBKDF1
  2033. #endif
  2034. #if !defined(NO_PBKDF2) || defined(HAVE_PKCS7) || defined(HAVE_SCRYPT)
  2035. #undef HAVE_PBKDF2
  2036. #define HAVE_PBKDF2
  2037. #endif
  2038. #if !defined(WOLFCRYPT_ONLY) && !defined(NO_OLD_TLS) && \
  2039. (defined(NO_SHA) || defined(NO_MD5))
  2040. #error old TLS requires MD5 and SHA
  2041. #endif
  2042. /* for backwards compatibility */
  2043. #if defined(TEST_IPV6) && !defined(WOLFSSL_IPV6)
  2044. #define WOLFSSL_IPV6
  2045. #endif
  2046. #ifdef WOLFSSL_LINUXKM
  2047. #ifdef HAVE_CONFIG_H
  2048. #include <config.h>
  2049. #undef HAVE_CONFIG_H
  2050. #endif
  2051. #ifndef NO_DEV_RANDOM
  2052. #define NO_DEV_RANDOM
  2053. #endif
  2054. #ifndef NO_WRITEV
  2055. #define NO_WRITEV
  2056. #endif
  2057. #ifndef NO_FILESYSTEM
  2058. #define NO_FILESYSTEM
  2059. #endif
  2060. #ifndef NO_STDIO_FILESYSTEM
  2061. #define NO_STDIO_FILESYSTEM
  2062. #endif
  2063. #ifndef WOLFSSL_NO_SOCK
  2064. #define WOLFSSL_NO_SOCK
  2065. #endif
  2066. #ifndef WOLFSSL_DH_CONST
  2067. #define WOLFSSL_DH_CONST
  2068. #endif
  2069. #ifndef WOLFSSL_USER_IO
  2070. #define WOLFSSL_USER_IO
  2071. #endif
  2072. #ifndef USE_WOLF_STRTOK
  2073. #define USE_WOLF_STRTOK
  2074. #endif
  2075. #ifndef WOLFSSL_OLD_PRIME_CHECK
  2076. #define WOLFSSL_OLD_PRIME_CHECK
  2077. #endif
  2078. #ifndef WOLFSSL_TEST_SUBROUTINE
  2079. #define WOLFSSL_TEST_SUBROUTINE static
  2080. #endif
  2081. #undef HAVE_STRINGS_H
  2082. #undef HAVE_ERRNO_H
  2083. #undef HAVE_THREAD_LS
  2084. #undef WOLFSSL_HAVE_MIN
  2085. #undef WOLFSSL_HAVE_MAX
  2086. #define SIZEOF_LONG 8
  2087. #define SIZEOF_LONG_LONG 8
  2088. #define CHAR_BIT 8
  2089. #ifndef WOLFSSL_SP_DIV_64
  2090. #define WOLFSSL_SP_DIV_64
  2091. #endif
  2092. #ifndef WOLFSSL_SP_DIV_WORD_HALF
  2093. #define WOLFSSL_SP_DIV_WORD_HALF
  2094. #endif
  2095. #endif
  2096. /* Place any other flags or defines here */
  2097. #if defined(WOLFSSL_MYSQL_COMPATIBLE) && defined(_WIN32) \
  2098. && defined(HAVE_GMTIME_R)
  2099. #undef HAVE_GMTIME_R /* don't trust macro with windows */
  2100. #endif /* WOLFSSL_MYSQL_COMPATIBLE */
  2101. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) \
  2102. || defined(HAVE_LIGHTY)) && !defined(NO_TLS)
  2103. #define OPENSSL_NO_ENGINE
  2104. #ifndef OPENSSL_EXTRA
  2105. #define OPENSSL_EXTRA
  2106. #endif
  2107. /* Session Tickets will be enabled when --enable-opensslall is used.
  2108. * Time is required for ticket expiration checking */
  2109. #if !defined(HAVE_SESSION_TICKET) && !defined(NO_ASN_TIME)
  2110. #define HAVE_SESSION_TICKET
  2111. #endif
  2112. /* OCSP will be enabled in configure.ac when --enable-opensslall is used,
  2113. * but do not force all users to have it enabled. */
  2114. #ifndef HAVE_OCSP
  2115. /*#define HAVE_OCSP*/
  2116. #endif
  2117. #ifndef KEEP_OUR_CERT
  2118. #define KEEP_OUR_CERT
  2119. #endif
  2120. #ifndef HAVE_SNI
  2121. #define HAVE_SNI
  2122. #endif
  2123. #endif
  2124. #ifdef HAVE_SNI
  2125. #define SSL_CTRL_SET_TLSEXT_HOSTNAME 55
  2126. #endif
  2127. /* both CURVE and ED small math should be enabled */
  2128. #ifdef CURVED25519_SMALL
  2129. #define CURVE25519_SMALL
  2130. #define ED25519_SMALL
  2131. #endif
  2132. /* both CURVE and ED small math should be enabled */
  2133. #ifdef CURVED448_SMALL
  2134. #define CURVE448_SMALL
  2135. #define ED448_SMALL
  2136. #endif
  2137. #ifndef WOLFSSL_ALERT_COUNT_MAX
  2138. #define WOLFSSL_ALERT_COUNT_MAX 5
  2139. #endif
  2140. /* warning for not using harden build options (default with ./configure) */
  2141. #ifndef WC_NO_HARDEN
  2142. #if (defined(USE_FAST_MATH) && !defined(TFM_TIMING_RESISTANT)) || \
  2143. (defined(HAVE_ECC) && !defined(ECC_TIMING_RESISTANT)) || \
  2144. (!defined(NO_RSA) && !defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS) && \
  2145. !defined(WC_NO_RNG))
  2146. #ifndef _MSC_VER
  2147. #warning "For timing resistance / side-channel attack prevention consider using harden options"
  2148. #else
  2149. #pragma message("Warning: For timing resistance / side-channel attack prevention consider using harden options")
  2150. #endif
  2151. #endif
  2152. #endif
  2153. #ifdef OPENSSL_COEXIST
  2154. /* make sure old names are disabled */
  2155. #ifndef NO_OLD_SSL_NAMES
  2156. #define NO_OLD_SSL_NAMES
  2157. #endif
  2158. #ifndef NO_OLD_WC_NAMES
  2159. #define NO_OLD_WC_NAMES
  2160. #endif
  2161. #endif
  2162. #if defined(NO_OLD_WC_NAMES) || defined(OPENSSL_EXTRA)
  2163. /* added to have compatibility with SHA256() */
  2164. #if !defined(NO_OLD_SHA_NAMES) && (!defined(HAVE_FIPS) || \
  2165. FIPS_VERSION_GT(2,0))
  2166. #define NO_OLD_SHA_NAMES
  2167. #endif
  2168. #if !defined(NO_OLD_MD5_NAME) && (!defined(HAVE_FIPS) || \
  2169. FIPS_VERSION_GT(2,0))
  2170. #define NO_OLD_MD5_NAME
  2171. #endif
  2172. #endif
  2173. /* switch for compatibility layer functionality. Has subparts i.e. BIO/X509
  2174. * When opensslextra is enabled all subparts should be turned on. */
  2175. #ifdef OPENSSL_EXTRA
  2176. #undef OPENSSL_EXTRA_X509_SMALL
  2177. #define OPENSSL_EXTRA_X509_SMALL
  2178. #endif /* OPENSSL_EXTRA */
  2179. /* support for converting DER to PEM */
  2180. #if (defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_NO_DER_TO_PEM)) || \
  2181. defined(WOLFSSL_CERT_GEN) || defined(OPENSSL_EXTRA)
  2182. #undef WOLFSSL_DER_TO_PEM
  2183. #define WOLFSSL_DER_TO_PEM
  2184. #endif
  2185. /* keep backwards compatibility enabling encrypted private key */
  2186. #ifndef WOLFSSL_ENCRYPTED_KEYS
  2187. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  2188. defined(HAVE_WEBSERVER)
  2189. #define WOLFSSL_ENCRYPTED_KEYS
  2190. #endif
  2191. #endif
  2192. /* support for disabling PEM to DER */
  2193. #if !defined(WOLFSSL_NO_PEM) && !defined(NO_CODING)
  2194. #undef WOLFSSL_PEM_TO_DER
  2195. #define WOLFSSL_PEM_TO_DER
  2196. #endif
  2197. /* Parts of the openssl compatibility layer require peer certs */
  2198. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) \
  2199. || defined(HAVE_LIGHTY)
  2200. #undef KEEP_PEER_CERT
  2201. #define KEEP_PEER_CERT
  2202. #endif
  2203. /*
  2204. * Keeps the "Finished" messages after a TLS handshake for use as the so-called
  2205. * "tls-unique" channel binding. See comment in internal.h around clientFinished
  2206. * and serverFinished for more information.
  2207. */
  2208. #if defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_WPAS)
  2209. #undef WOLFSSL_HAVE_TLS_UNIQUE
  2210. #define WOLFSSL_HAVE_TLS_UNIQUE
  2211. #endif
  2212. /* RAW hash function APIs are not implemented */
  2213. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_AFALG_HASH)
  2214. #undef WOLFSSL_NO_HASH_RAW
  2215. #define WOLFSSL_NO_HASH_RAW
  2216. #endif
  2217. /* XChacha not implemented with ARM assembly ChaCha */
  2218. #if defined(WOLFSSL_ARMASM)
  2219. #undef HAVE_XCHACHA
  2220. #endif
  2221. #if !defined(WOLFSSL_SHA384) && !defined(WOLFSSL_SHA512) && defined(NO_AES) && \
  2222. !defined(WOLFSSL_SHA3)
  2223. #undef WOLFSSL_NO_WORD64_OPS
  2224. #define WOLFSSL_NO_WORD64_OPS
  2225. #endif
  2226. #if !defined(WOLFCRYPT_ONLY) && \
  2227. (!defined(WOLFSSL_NO_TLS12) || defined(HAVE_KEYING_MATERIAL))
  2228. #undef WOLFSSL_HAVE_PRF
  2229. #define WOLFSSL_HAVE_PRF
  2230. #endif
  2231. #if defined(NO_AES) && defined(NO_DES3) && !defined(HAVE_CAMELLIA) && \
  2232. !defined(WOLFSSL_HAVE_PRF) && defined(NO_PWDBASED)
  2233. #undef WOLFSSL_NO_XOR_OPS
  2234. #define WOLFSSL_NO_XOR_OPS
  2235. #endif
  2236. #if defined(NO_ASN) && defined(WOLFCRYPT_ONLY)
  2237. #undef WOLFSSL_NO_INT_ENCODE
  2238. #define WOLFSSL_NO_INT_ENCODE
  2239. #undef WOLFSSL_NO_INT_DECODE
  2240. #define WOLFSSL_NO_INT_DECODE
  2241. #endif
  2242. #if defined(WOLFCRYPT_ONLY) && defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  2243. defined(WC_NO_RSA_OAEP)
  2244. #undef WOLFSSL_NO_CT_OPS
  2245. #define WOLFSSL_NO_CT_OPS
  2246. #endif
  2247. #if defined(WOLFCRYPT_ONLY) && defined(NO_AES) && !defined(HAVE_CURVE25519) && \
  2248. !defined(HAVE_CURVE448) && defined(WC_NO_RNG) && defined(WC_NO_RSA_OAEP)
  2249. #undef WOLFSSL_NO_CONST_CMP
  2250. #define WOLFSSL_NO_CONST_CMP
  2251. #endif
  2252. #if defined(WOLFCRYPT_ONLY) && defined(NO_AES) && !defined(WOLFSSL_SHA384) && \
  2253. !defined(WOLFSSL_SHA512) && defined(WC_NO_RNG) && \
  2254. !defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL) \
  2255. && !defined(USE_FAST_MATH)
  2256. #undef WOLFSSL_NO_FORCE_ZERO
  2257. #define WOLFSSL_NO_FORCE_ZERO
  2258. #endif
  2259. /* Detect old cryptodev name */
  2260. #if defined(WOLF_CRYPTO_DEV) && !defined(WOLF_CRYPTO_CB)
  2261. #define WOLF_CRYPTO_CB
  2262. #endif
  2263. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_NO_SIGALG)
  2264. #error TLS 1.3 requires the Signature Algorithms extension to be enabled
  2265. #endif
  2266. #ifndef NO_WOLFSSL_BASE64_DECODE
  2267. #define WOLFSSL_BASE64_DECODE
  2268. #endif
  2269. #if defined(HAVE_EX_DATA) || defined(FORTRESS)
  2270. #if defined(FORTRESS) && !defined(HAVE_EX_DATA)
  2271. #define HAVE_EX_DATA
  2272. #endif
  2273. #ifndef MAX_EX_DATA
  2274. #define MAX_EX_DATA 5 /* allow for five items of ex_data */
  2275. #endif
  2276. #endif
  2277. #ifdef NO_WOLFSSL_SMALL_STACK
  2278. #undef WOLFSSL_SMALL_STACK
  2279. #endif
  2280. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SMALL_STACK_STATIC) && \
  2281. !defined(NO_WOLFSSL_SMALL_STACK_STATIC)
  2282. #define WOLFSSL_SMALL_STACK_STATIC
  2283. #endif
  2284. #ifdef WOLFSSL_SMALL_STACK_STATIC
  2285. #undef WOLFSSL_SMALL_STACK_STATIC
  2286. #define WOLFSSL_SMALL_STACK_STATIC static
  2287. #else
  2288. #define WOLFSSL_SMALL_STACK_STATIC
  2289. #endif
  2290. /* The client session cache requires time for timeout */
  2291. #if defined(NO_ASN_TIME) && !defined(NO_SESSION_CACHE)
  2292. #define NO_SESSION_CACHE
  2293. #endif
  2294. /* Use static ECC structs for Position Independant Code (PIC) */
  2295. #if defined(__IAR_SYSTEMS_ICC__) && defined(__ROPI__)
  2296. #define WOLFSSL_ECC_CURVE_STATIC
  2297. #define WOLFSSL_NAMES_STATIC
  2298. #define WOLFSSL_NO_CONSTCHARCONST
  2299. #endif
  2300. /* FIPS v1 does not support TLS v1.3 (requires RSA PSS and HKDF) */
  2301. #if FIPS_VERSION_EQ(1,0)
  2302. #undef WC_RSA_PSS
  2303. #undef WOLFSSL_TLS13
  2304. #endif
  2305. /* FIPS v2 does not support WOLFSSL_PSS_LONG_SALT */
  2306. #if FIPS_VERSION_EQ(2,0)
  2307. #ifdef WOLFSSL_PSS_LONG_SALT
  2308. #undef WOLFSSL_PSS_LONG_SALT
  2309. #endif
  2310. #endif
  2311. /* For FIPSv2 make sure the ECDSA encoding allows extra bytes
  2312. * but make sure users consider enabling it */
  2313. #if !defined(NO_STRICT_ECDSA_LEN) && FIPS_VERSION_GE(2,0)
  2314. /* ECDSA length checks off by default for CAVP testing
  2315. * consider enabling strict checks in production */
  2316. #define NO_STRICT_ECDSA_LEN
  2317. #endif
  2318. /* Do not allow using small stack with no malloc */
  2319. #if defined(WOLFSSL_NO_MALLOC) && \
  2320. (defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_SMALL_STACK_CACHE))
  2321. #error Small stack cannot be used with no malloc (WOLFSSL_NO_MALLOC)
  2322. #endif
  2323. /* Enable DH Extra for QT, openssl all, openssh and static ephemeral */
  2324. /* Allows export/import of DH key and params as DER */
  2325. #if !defined(NO_DH) && !defined(WOLFSSL_DH_EXTRA) && \
  2326. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH) || \
  2327. defined(WOLFSSL_STATIC_EPHEMERAL))
  2328. #define WOLFSSL_DH_EXTRA
  2329. #endif
  2330. /* DH Extra is not supported on FIPS v1 or v2 (is missing DhKey .pub/.priv) */
  2331. #if defined(WOLFSSL_DH_EXTRA) && defined(HAVE_FIPS) && FIPS_VERSION_LE(2,0)
  2332. #undef WOLFSSL_DH_EXTRA
  2333. #endif
  2334. /* wc_Sha512.devId isn't available before FIPS 5.1 */
  2335. #if defined(HAVE_FIPS) && FIPS_VERSION_LT(5,1)
  2336. #define NO_SHA2_CRYPTO_CB
  2337. #endif
  2338. /* Enable HAVE_ONE_TIME_AUTH by default for use with TLS cipher suites
  2339. * when poly1305 is enabled
  2340. */
  2341. #if defined(HAVE_POLY1305) && !defined(HAVE_ONE_TIME_AUTH)
  2342. #define HAVE_ONE_TIME_AUTH
  2343. #endif
  2344. /* Check for insecure build combination:
  2345. * secure renegotiation [enabled]
  2346. * extended master secret [disabled]
  2347. * session resumption [enabled]
  2348. */
  2349. #if defined(HAVE_SECURE_RENEGOTIATION) && !defined(HAVE_EXTENDED_MASTER) && \
  2350. (defined(HAVE_SESSION_TICKET) || !defined(NO_SESSION_CACHE))
  2351. /* secure renegotiation requires extended master secret with resumption */
  2352. #ifndef _MSC_VER
  2353. #warning Extended master secret must be enabled with secure renegotiation and session resumption
  2354. #else
  2355. #pragma message("Warning: Extended master secret must be enabled with secure renegotiation and session resumption")
  2356. #endif
  2357. /* Note: "--enable-renegotiation-indication" ("HAVE_RENEGOTIATION_INDICATION")
  2358. * only sends the secure renegotiation extension, but is not actually supported.
  2359. * This was added because some TLS peers required it even if not used, so we call
  2360. * this "(FAKE Secure Renegotiation)"
  2361. */
  2362. #endif
  2363. /* if secure renegotiation is enabled, make sure server info is enabled */
  2364. #if !defined(HAVE_RENEGOTIATION_INDICATION) && \
  2365. !defined(HAVE_SERVER_RENEGOTIATION_INFO) && \
  2366. defined(HAVE_SECURE_RENEGOTIATION) && \
  2367. !defined(NO_WOLFSSL_SERVER)
  2368. #define HAVE_SERVER_RENEGOTIATION_INFO
  2369. #endif
  2370. /* Crypto callbacks should enable hash flag support */
  2371. #if defined(WOLF_CRYPTO_CB) && !defined(WOLFSSL_HASH_FLAGS)
  2372. /* FIPS v1 and v2 do not support hash flags, so do not allow it with
  2373. * crypto callbacks */
  2374. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS) && \
  2375. defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION >= 3)
  2376. #define WOLFSSL_HASH_FLAGS
  2377. #endif
  2378. #endif
  2379. #ifdef WOLFSSL_HAVE_KYBER
  2380. #define HAVE_PQC
  2381. #endif
  2382. /* Enable Post-Quantum Cryptography if we have liboqs from the OpenQuantumSafe
  2383. * group */
  2384. #ifdef HAVE_LIBOQS
  2385. #define HAVE_PQC
  2386. #define HAVE_FALCON
  2387. #define HAVE_DILITHIUM
  2388. #define HAVE_SPHINCS
  2389. #define HAVE_KYBER
  2390. #endif
  2391. #ifdef HAVE_PQM4
  2392. #define HAVE_PQC
  2393. #define HAVE_KYBER
  2394. #endif
  2395. #if defined(HAVE_PQC) && !defined(HAVE_LIBOQS) && !defined(HAVE_PQM4) && \
  2396. !defined(WOLFSSL_HAVE_KYBER)
  2397. #error Please do not define HAVE_PQC yourself.
  2398. #endif
  2399. #if defined(HAVE_PQC) && defined(HAVE_LIBOQS) && defined(HAVE_PQM4)
  2400. #error Please do not define both HAVE_LIBOQS and HAVE_PQM4.
  2401. #endif
  2402. /* SRTP requires DTLS */
  2403. #if defined(WOLFSSL_SRTP) && !defined(WOLFSSL_DTLS)
  2404. #error The SRTP extension requires DTLS
  2405. #endif
  2406. /* Are we using an external private key store like:
  2407. * PKCS11 / HSM / crypto callback / PK callback */
  2408. #if !defined(WOLF_PRIVATE_KEY_ID) && !defined(NO_WOLF_PRIVATE_KEY_ID) && \
  2409. (defined(HAVE_PKCS11) || defined(HAVE_PK_CALLBACKS) || \
  2410. defined(WOLF_CRYPTO_CB) || defined(WOLFSSL_KCAPI))
  2411. /* Enables support for using wolfSSL_CTX_use_PrivateKey_Id and
  2412. * wolfSSL_CTX_use_PrivateKey_Label */
  2413. #define WOLF_PRIVATE_KEY_ID
  2414. #endif
  2415. /* With titan cache size there is too many sessions to fit with the default
  2416. * multiplier of 8 */
  2417. #if defined(TITAN_SESSION_CACHE) && !defined(NO_SESSION_CACHE_REF)
  2418. #define NO_SESSION_CACHE_REF
  2419. #endif
  2420. /* (D)TLS v1.3 requires 64-bit number wrappers */
  2421. #if defined(WOLFSSL_TLS13) || defined(WOLFSSL_DTLS_DROP_STATS)
  2422. #undef WOLFSSL_W64_WRAPPER
  2423. #define WOLFSSL_W64_WRAPPER
  2424. #endif
  2425. /* DTLS v1.3 requires AES ECB if using AES */
  2426. #if defined(WOLFSSL_DTLS13) && !defined(NO_AES) && \
  2427. !defined(WOLFSSL_AES_DIRECT)
  2428. #define WOLFSSL_AES_DIRECT
  2429. #endif
  2430. #if defined(WOLFSSL_DTLS13) && (!defined(WOLFSSL_DTLS) || \
  2431. !defined(WOLFSSL_TLS13))
  2432. #error "DTLS v1.3 requires both WOLFSSL_TLS13 and WOLFSSL_DTLS"
  2433. #endif
  2434. #if defined(WOLFSSL_DTLS_CID) && !defined(WOLFSSL_DTLS13)
  2435. #error "ConnectionID is supported for DTLSv1.3 only"
  2436. #endif
  2437. /* RSA Key Checking is disabled by default unless WOLFSSL_RSA_KEY_CHECK is
  2438. * defined or FIPS v2 3389, FIPS v5 or later.
  2439. * Not allowed for:
  2440. * RSA public only, CAVP selftest, fast RSA, user RSA, QAT or CryptoCell */
  2441. #if (defined(WOLFSSL_RSA_KEY_CHECK) || (defined(HAVE_FIPS) && FIPS_VERSION_GE(2,0))) && \
  2442. !defined(WOLFSSL_NO_RSA_KEY_CHECK) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  2443. !defined(HAVE_USER_RSA) && !defined(HAVE_FAST_RSA) && \
  2444. !defined(HAVE_INTEL_QA) && !defined(WOLFSSL_CRYPTOCELL) && \
  2445. !defined(HAVE_SELFTEST)
  2446. #undef WOLFSSL_RSA_KEY_CHECK
  2447. #define WOLFSSL_RSA_KEY_CHECK
  2448. #endif
  2449. /* SHAKE - Not allowed in FIPS */
  2450. #if defined(WOLFSSL_SHA3) && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  2451. #ifndef WOLFSSL_NO_SHAKE128
  2452. #undef WOLFSSL_SHAKE128
  2453. #define WOLFSSL_SHAKE128
  2454. #endif
  2455. #ifndef WOLFSSL_NO_SHAKE256
  2456. #undef WOLFSSL_SHAKE256
  2457. #define WOLFSSL_SHAKE256
  2458. #endif
  2459. #else
  2460. #undef WOLFSSL_NO_SHAKE128
  2461. #define WOLFSSL_NO_SHAKE128
  2462. #undef WOLFSSL_NO_SHAKE256
  2463. #define WOLFSSL_NO_SHAKE256
  2464. #endif
  2465. /* ---------------------------------------------------------------------------
  2466. * Depricated Algorithm Handling
  2467. * Unless allowed via a build macro, disable support
  2468. * ---------------------------------------------------------------------------*/
  2469. /* RC4: Per RFC7465 Feb 2015, the cipher suite has been deprecated due to a
  2470. * number of exploits capable of decrypting portions of encrypted messages. */
  2471. #ifndef WOLFSSL_ALLOW_RC4
  2472. #undef NO_RC4
  2473. #define NO_RC4
  2474. #endif
  2475. #if !defined(WOLFSSL_NO_ASYNC_IO) || defined(WOLFSSL_ASYNC_CRYPT) || \
  2476. defined(WOLFSSL_NONBLOCK_OCSP)
  2477. /* Enable asynchronous support in TLS functions to support one or more of
  2478. * the following:
  2479. * - re-entry after a network blocking return
  2480. * - re-entry after OCSP blocking return
  2481. * - asynchronous cryptography */
  2482. #undef WOLFSSL_ASYNC_IO
  2483. #define WOLFSSL_ASYNC_IO
  2484. #endif
  2485. #ifdef WOLFSSL_SYS_CA_CERTS
  2486. #ifdef NO_FILESYSTEM
  2487. #warning "Turning off WOLFSSL_SYS_CA_CERTS b/c NO_FILESYSTEM is defined."
  2488. #undef WOLFSSL_SYS_CA_CERTS
  2489. #endif
  2490. #ifdef NO_CERTS
  2491. #warning "Turning off WOLFSSL_SYS_CA_CERTS b/c NO_CERTS is defined."
  2492. #undef WOLFSSL_SYS_CA_CERTS
  2493. #endif
  2494. #if defined(__APPLE__) && !defined(HAVE_SECURITY_SECTRUSTSETTINGS_H)
  2495. #warning "Turning off WOLFSSL_SYS_CA_CERTS b/c no Security/SecTrustSettings.h header."
  2496. #undef WOLFSSL_SYS_CA_CERTS
  2497. #endif
  2498. #endif /* WOLFSSL_SYS_CA_CERTS */
  2499. #ifdef __cplusplus
  2500. } /* extern "C" */
  2501. #endif
  2502. #endif