settings.h 84 KB

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