settings.h 87 KB

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