internal.h 180 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880
  1. /* internal.h
  2. *
  3. * Copyright (C) 2006-2021 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. #ifndef WOLFSSL_INT_H
  22. #define WOLFSSL_INT_H
  23. #include <wolfssl/wolfcrypt/types.h>
  24. #include <wolfssl/ssl.h>
  25. #ifdef HAVE_CRL
  26. #include <wolfssl/crl.h>
  27. #endif
  28. #include <wolfssl/wolfcrypt/random.h>
  29. #ifndef NO_DES3
  30. #include <wolfssl/wolfcrypt/des3.h>
  31. #endif
  32. #ifndef NO_HC128
  33. #include <wolfssl/wolfcrypt/hc128.h>
  34. #endif
  35. #ifndef NO_RABBIT
  36. #include <wolfssl/wolfcrypt/rabbit.h>
  37. #endif
  38. #ifdef HAVE_CHACHA
  39. #include <wolfssl/wolfcrypt/chacha.h>
  40. #endif
  41. #ifndef NO_ASN
  42. #include <wolfssl/wolfcrypt/asn.h>
  43. #include <wolfssl/wolfcrypt/pkcs12.h>
  44. #endif
  45. #ifndef NO_MD5
  46. #include <wolfssl/wolfcrypt/md5.h>
  47. #endif
  48. #ifndef NO_SHA
  49. #include <wolfssl/wolfcrypt/sha.h>
  50. #endif
  51. #ifndef NO_AES
  52. #include <wolfssl/wolfcrypt/aes.h>
  53. #endif
  54. #ifdef HAVE_POLY1305
  55. #include <wolfssl/wolfcrypt/poly1305.h>
  56. #endif
  57. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && defined(OPENSSL_EXTRA)
  58. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  59. #endif
  60. #ifdef HAVE_CAMELLIA
  61. #include <wolfssl/wolfcrypt/camellia.h>
  62. #endif
  63. #include <wolfssl/wolfcrypt/logging.h>
  64. #ifndef NO_HMAC
  65. #include <wolfssl/wolfcrypt/hmac.h>
  66. #endif
  67. #ifndef NO_RC4
  68. #include <wolfssl/wolfcrypt/arc4.h>
  69. #endif
  70. #ifndef NO_SHA256
  71. #include <wolfssl/wolfcrypt/sha256.h>
  72. #endif
  73. #if defined(WOLFSSL_SHA384)
  74. #include <wolfssl/wolfcrypt/sha512.h>
  75. #endif
  76. #ifdef HAVE_OCSP
  77. #include <wolfssl/ocsp.h>
  78. #endif
  79. #ifdef WOLFSSL_SHA384
  80. #include <wolfssl/wolfcrypt/sha512.h>
  81. #endif
  82. #ifdef WOLFSSL_SHA512
  83. #include <wolfssl/wolfcrypt/sha512.h>
  84. #endif
  85. #ifdef HAVE_AESGCM
  86. #include <wolfssl/wolfcrypt/sha512.h>
  87. #endif
  88. #ifdef WOLFSSL_RIPEMD
  89. #include <wolfssl/wolfcrypt/ripemd.h>
  90. #endif
  91. #ifdef HAVE_IDEA
  92. #include <wolfssl/wolfcrypt/idea.h>
  93. #endif
  94. #ifndef NO_RSA
  95. #include <wolfssl/wolfcrypt/rsa.h>
  96. #endif
  97. #ifdef HAVE_ECC
  98. #include <wolfssl/wolfcrypt/ecc.h>
  99. #endif
  100. #ifndef NO_DH
  101. #include <wolfssl/wolfcrypt/dh.h>
  102. #endif
  103. #ifdef HAVE_ED25519
  104. #include <wolfssl/wolfcrypt/ed25519.h>
  105. #endif
  106. #ifdef HAVE_CURVE25519
  107. #include <wolfssl/wolfcrypt/curve25519.h>
  108. #endif
  109. #ifdef HAVE_ED448
  110. #include <wolfssl/wolfcrypt/ed448.h>
  111. #endif
  112. #ifdef HAVE_CURVE448
  113. #include <wolfssl/wolfcrypt/curve448.h>
  114. #endif
  115. #ifndef WOLFSSL_NO_DEF_TICKET_ENC_CB
  116. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && \
  117. !defined(WOLFSSL_TICKET_ENC_AES128_GCM) && \
  118. !defined(WOLFSSL_TICKET_ENC_AES256_GCM)
  119. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  120. #else
  121. #include <wolfssl/wolfcrypt/aes.h>
  122. #endif
  123. #endif
  124. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  125. #include <wolfssl/wolfcrypt/hash.h>
  126. #if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
  127. #include <wolfssl/callbacks.h>
  128. #endif
  129. #ifdef WOLFSSL_CALLBACKS
  130. #include <signal.h>
  131. #endif
  132. #ifdef USE_WINDOWS_API
  133. #ifdef WOLFSSL_GAME_BUILD
  134. #include "system/xtl.h"
  135. #else
  136. #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN)
  137. /* On WinCE winsock2.h must be included before windows.h */
  138. #include <winsock2.h>
  139. #endif
  140. #include <windows.h>
  141. #endif
  142. #elif defined(THREADX)
  143. #ifndef SINGLE_THREADED
  144. #include "tx_api.h"
  145. #endif
  146. #elif defined(WOLFSSL_DEOS)
  147. /* do nothing, just don't pick Unix */
  148. #elif defined(MICRIUM)
  149. /* do nothing, just don't pick Unix */
  150. #elif defined(FREERTOS) || defined(FREERTOS_TCP) || defined(WOLFSSL_SAFERTOS)
  151. /* do nothing */
  152. #elif defined(RTTHREAD)
  153. /* do nothing */
  154. #elif defined(EBSNET)
  155. /* do nothing */
  156. #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
  157. /* do nothing */
  158. #elif defined(FREESCALE_FREE_RTOS)
  159. #include "fsl_os_abstraction.h"
  160. #elif defined(WOLFSSL_uITRON4)
  161. /* do nothing */
  162. #elif defined(WOLFSSL_uTKERNEL2)
  163. /* do nothing */
  164. #elif defined(WOLFSSL_CMSIS_RTOS)
  165. #include "cmsis_os.h"
  166. #elif defined(WOLFSSL_CMSIS_RTOSv2)
  167. #include "cmsis_os2.h"
  168. #elif defined(WOLFSSL_MDK_ARM)
  169. #if defined(WOLFSSL_MDK5)
  170. #include "cmsis_os.h"
  171. #else
  172. #include <rtl.h>
  173. #endif
  174. #elif defined(MBED)
  175. #elif defined(WOLFSSL_TIRTOS)
  176. /* do nothing */
  177. #elif defined(INTIME_RTOS)
  178. #include <rt.h>
  179. #elif defined(WOLFSSL_NUCLEUS_1_2)
  180. /* do nothing */
  181. #elif defined(WOLFSSL_APACHE_MYNEWT)
  182. #if !defined(WOLFSSL_LWIP)
  183. void mynewt_ctx_clear(void *ctx);
  184. void* mynewt_ctx_new();
  185. #endif
  186. #elif defined(WOLFSSL_ZEPHYR)
  187. #ifndef SINGLE_THREADED
  188. #include <kernel.h>
  189. #endif
  190. #elif defined(WOLFSSL_TELIT_M2MB)
  191. /* do nothing */
  192. #else
  193. #ifndef SINGLE_THREADED
  194. #if defined(WOLFSSL_LINUXKM)
  195. #define WOLFSSL_KTHREADS
  196. #include <linux/kthread.h>
  197. #elif defined(WOLFSSL_USER_MUTEX)
  198. /* do nothing */
  199. #else
  200. #define WOLFSSL_PTHREADS
  201. #include <pthread.h>
  202. #endif
  203. #endif
  204. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM)
  205. #ifdef FUSION_RTOS
  206. #include <fclunistd.h>
  207. #else
  208. #include <unistd.h> /* for close of BIO */
  209. #endif
  210. #endif
  211. #endif
  212. #ifndef CHAR_BIT
  213. /* Needed for DTLS without big math */
  214. #include <limits.h>
  215. #endif
  216. #ifdef HAVE_LIBZ
  217. #include "zlib.h"
  218. #endif
  219. #ifdef WOLFSSL_ASYNC_CRYPT
  220. #include <wolfssl/wolfcrypt/async.h>
  221. #endif
  222. #ifdef OPENSSL_EXTRA
  223. #ifdef WOLFCRYPT_HAVE_SRP
  224. #include <wolfssl/wolfcrypt/srp.h>
  225. #endif
  226. #endif
  227. #ifdef _MSC_VER
  228. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  229. #pragma warning(disable: 4996)
  230. #endif
  231. #ifdef NO_SHA
  232. #define WC_SHA_DIGEST_SIZE 20
  233. #endif
  234. #ifdef NO_SHA256
  235. #define WC_SHA256_DIGEST_SIZE 32
  236. #endif
  237. #ifdef NO_MD5
  238. #define WC_MD5_DIGEST_SIZE 16
  239. #endif
  240. #ifdef __cplusplus
  241. extern "C" {
  242. #endif
  243. /* Define or comment out the cipher suites you'd like to be compiled in
  244. make sure to use at least one BUILD_SSL_xxx or BUILD_TLS_xxx is defined
  245. When adding cipher suites, add name to cipher_names, idx to cipher_name_idx
  246. Now that there is a maximum strength crypto build, the following BUILD_XXX
  247. flags need to be divided into two groups selected by WOLFSSL_MAX_STRENGTH.
  248. Those that do not use Perfect Forward Security and do not use AEAD ciphers
  249. need to be switched off. Allowed suites use (EC)DHE, AES-GCM|CCM, or
  250. CHACHA-POLY.
  251. */
  252. /* Check that if WOLFSSL_MAX_STRENGTH is set that all the required options are
  253. * not turned off. */
  254. #if defined(WOLFSSL_MAX_STRENGTH) && \
  255. ((!defined(HAVE_ECC) && (defined(NO_DH) || defined(NO_RSA))) || \
  256. (!defined(HAVE_AESGCM) && !defined(HAVE_AESCCM) && \
  257. (!defined(HAVE_POLY1305) || !defined(HAVE_CHACHA))) || \
  258. (defined(NO_SHA256) && !defined(WOLFSSL_SHA384)) || \
  259. !defined(NO_OLD_TLS))
  260. #error "You are trying to build max strength with requirements disabled."
  261. #endif
  262. /* Have QSH : Quantum-safe Handshake */
  263. #if defined(HAVE_QSH)
  264. #define BUILD_TLS_QSH
  265. #endif
  266. #ifndef WOLFSSL_NO_TLS12
  267. #ifndef WOLFSSL_MAX_STRENGTH
  268. #ifdef WOLFSSL_AEAD_ONLY
  269. /* AES CBC ciphers are not allowed in AEAD only mode */
  270. #undef HAVE_AES_CBC
  271. #endif
  272. #ifndef WOLFSSL_AEAD_ONLY
  273. #if !defined(NO_RSA) && !defined(NO_RC4)
  274. #if defined(WOLFSSL_STATIC_RSA)
  275. #if !defined(NO_SHA)
  276. #define BUILD_SSL_RSA_WITH_RC4_128_SHA
  277. #endif
  278. #if !defined(NO_MD5)
  279. #define BUILD_SSL_RSA_WITH_RC4_128_MD5
  280. #endif
  281. #endif
  282. #if !defined(NO_TLS) && defined(HAVE_NTRU) && !defined(NO_SHA) \
  283. && defined(WOLFSSL_STATIC_RSA)
  284. #define BUILD_TLS_NTRU_RSA_WITH_RC4_128_SHA
  285. #endif
  286. #endif
  287. #if !defined(NO_RSA) && !defined(NO_DES3)
  288. #if !defined(NO_SHA)
  289. #if defined(WOLFSSL_STATIC_RSA)
  290. #define BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA
  291. #endif
  292. #if !defined(NO_TLS) && defined(HAVE_NTRU) \
  293. && defined(WOLFSSL_STATIC_RSA)
  294. #define BUILD_TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA
  295. #endif
  296. #endif
  297. #endif
  298. #if !defined(NO_RSA) && defined(HAVE_IDEA)
  299. #if !defined(NO_SHA) && defined(WOLFSSL_STATIC_RSA)
  300. #define BUILD_SSL_RSA_WITH_IDEA_CBC_SHA
  301. #endif
  302. #endif
  303. #endif /* !WOLFSSL_AEAD_ONLY */
  304. #if !defined(NO_RSA) && !defined(NO_AES) && !defined(NO_TLS)
  305. #if !defined(NO_SHA) && defined(HAVE_AES_CBC)
  306. #if defined(WOLFSSL_STATIC_RSA)
  307. #ifdef WOLFSSL_AES_128
  308. #define BUILD_TLS_RSA_WITH_AES_128_CBC_SHA
  309. #endif
  310. #ifdef WOLFSSL_AES_256
  311. #define BUILD_TLS_RSA_WITH_AES_256_CBC_SHA
  312. #endif
  313. #endif
  314. #if defined(HAVE_NTRU) && defined(WOLFSSL_STATIC_RSA)
  315. #ifdef WOLFSSL_AES_128
  316. #define BUILD_TLS_NTRU_RSA_WITH_AES_128_CBC_SHA
  317. #endif
  318. #ifdef WOLFSSL_AES_256
  319. #define BUILD_TLS_NTRU_RSA_WITH_AES_256_CBC_SHA
  320. #endif
  321. #endif
  322. #endif
  323. #if defined(WOLFSSL_STATIC_RSA)
  324. #if !defined (NO_SHA256) && defined(HAVE_AES_CBC)
  325. #ifdef WOLFSSL_AES_128
  326. #define BUILD_TLS_RSA_WITH_AES_128_CBC_SHA256
  327. #endif
  328. #ifdef WOLFSSL_AES_256
  329. #define BUILD_TLS_RSA_WITH_AES_256_CBC_SHA256
  330. #endif
  331. #endif
  332. #if defined (HAVE_AESGCM)
  333. #ifdef WOLFSSL_AES_128
  334. #define BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256
  335. #endif
  336. #if defined (WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  337. #define BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384
  338. #endif
  339. #endif
  340. #if defined (HAVE_AESCCM)
  341. #ifdef WOLFSSL_AES_128
  342. #define BUILD_TLS_RSA_WITH_AES_128_CCM_8
  343. #endif
  344. #ifdef WOLFSSL_AES_256
  345. #define BUILD_TLS_RSA_WITH_AES_256_CCM_8
  346. #endif
  347. #endif
  348. #endif
  349. #endif
  350. #if defined(HAVE_CAMELLIA) && !defined(NO_TLS) && !defined(NO_CAMELLIA_CBC)
  351. #ifndef NO_RSA
  352. #if defined(WOLFSSL_STATIC_RSA)
  353. #if !defined(NO_SHA)
  354. #define BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
  355. #define BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA
  356. #endif
  357. #ifndef NO_SHA256
  358. #define BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
  359. #define BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256
  360. #endif
  361. #endif
  362. #if !defined(NO_DH)
  363. #if !defined(NO_SHA)
  364. #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
  365. #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
  366. #endif
  367. #ifndef NO_SHA256
  368. #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
  369. #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256
  370. #endif
  371. #endif
  372. #endif
  373. #endif
  374. #if defined(WOLFSSL_STATIC_PSK)
  375. #if !defined(NO_PSK) && !defined(NO_AES) && !defined(NO_TLS)
  376. #if !defined(NO_SHA)
  377. #ifdef WOLFSSL_AES_128
  378. #define BUILD_TLS_PSK_WITH_AES_128_CBC_SHA
  379. #endif
  380. #ifdef WOLFSSL_AES_256
  381. #define BUILD_TLS_PSK_WITH_AES_256_CBC_SHA
  382. #endif
  383. #endif
  384. #ifndef NO_SHA256
  385. #ifdef WOLFSSL_AES_128
  386. #ifdef HAVE_AES_CBC
  387. #define BUILD_TLS_PSK_WITH_AES_128_CBC_SHA256
  388. #endif
  389. #ifdef HAVE_AESGCM
  390. #define BUILD_TLS_PSK_WITH_AES_128_GCM_SHA256
  391. #endif
  392. #endif /* WOLFSSL_AES_128 */
  393. #ifdef HAVE_AESCCM
  394. #ifdef WOLFSSL_AES_128
  395. #define BUILD_TLS_PSK_WITH_AES_128_CCM_8
  396. #define BUILD_TLS_PSK_WITH_AES_128_CCM
  397. #endif
  398. #ifdef WOLFSSL_AES_256
  399. #define BUILD_TLS_PSK_WITH_AES_256_CCM_8
  400. #define BUILD_TLS_PSK_WITH_AES_256_CCM
  401. #endif
  402. #endif
  403. #endif
  404. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  405. #ifdef HAVE_AES_CBC
  406. #define BUILD_TLS_PSK_WITH_AES_256_CBC_SHA384
  407. #endif
  408. #ifdef HAVE_AESGCM
  409. #define BUILD_TLS_PSK_WITH_AES_256_GCM_SHA384
  410. #endif
  411. #endif
  412. #endif
  413. #endif
  414. #if !defined(NO_TLS) && defined(HAVE_NULL_CIPHER)
  415. #if !defined(NO_RSA)
  416. #if defined(WOLFSSL_STATIC_RSA)
  417. #ifndef NO_MD5
  418. #define BUILD_TLS_RSA_WITH_NULL_MD5
  419. #endif
  420. #if !defined(NO_SHA)
  421. #define BUILD_TLS_RSA_WITH_NULL_SHA
  422. #endif
  423. #ifndef NO_SHA256
  424. #define BUILD_TLS_RSA_WITH_NULL_SHA256
  425. #endif
  426. #endif
  427. #endif
  428. #if !defined(NO_PSK) && defined(WOLFSSL_STATIC_PSK)
  429. #if !defined(NO_SHA)
  430. #define BUILD_TLS_PSK_WITH_NULL_SHA
  431. #endif
  432. #ifndef NO_SHA256
  433. #define BUILD_TLS_PSK_WITH_NULL_SHA256
  434. #endif
  435. #ifdef WOLFSSL_SHA384
  436. #define BUILD_TLS_PSK_WITH_NULL_SHA384
  437. #endif
  438. #endif
  439. #endif
  440. #if defined(WOLFSSL_STATIC_RSA)
  441. #if !defined(NO_HC128) && !defined(NO_RSA) && !defined(NO_TLS)
  442. #ifndef NO_MD5
  443. #define BUILD_TLS_RSA_WITH_HC_128_MD5
  444. #endif
  445. #if !defined(NO_SHA)
  446. #define BUILD_TLS_RSA_WITH_HC_128_SHA
  447. #endif
  448. #endif
  449. #if !defined(NO_RABBIT) && !defined(NO_TLS) && !defined(NO_RSA)
  450. #if !defined(NO_SHA)
  451. #define BUILD_TLS_RSA_WITH_RABBIT_SHA
  452. #endif
  453. #endif
  454. #endif
  455. #if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
  456. !defined(NO_RSA)
  457. #if !defined(NO_SHA)
  458. #if defined(WOLFSSL_AES_128) && defined(HAVE_AES_CBC)
  459. #define BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
  460. #endif
  461. #if defined(WOLFSSL_AES_256) && defined(HAVE_AES_CBC)
  462. #define BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA
  463. #endif
  464. #if !defined(NO_DES3)
  465. #define BUILD_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
  466. #endif
  467. #endif
  468. #if !defined(NO_SHA256) && defined(HAVE_AES_CBC)
  469. #ifdef WOLFSSL_AES_128
  470. #define BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
  471. #endif
  472. #ifdef WOLFSSL_AES_256
  473. #define BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
  474. #endif
  475. #endif
  476. #endif
  477. #if defined(HAVE_ANON) && !defined(NO_TLS) && !defined(NO_DH) && \
  478. !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  479. #ifdef HAVE_AES_CBC
  480. #define BUILD_TLS_DH_anon_WITH_AES_128_CBC_SHA
  481. #endif
  482. #if defined(WOLFSSL_SHA384) && defined(HAVE_AESGCM)
  483. #define BUILD_TLS_DH_anon_WITH_AES_256_GCM_SHA384
  484. #endif
  485. #endif
  486. #if !defined(NO_DH) && !defined(NO_PSK) && !defined(NO_TLS)
  487. #ifndef NO_SHA256
  488. #if !defined(NO_AES) && defined(WOLFSSL_AES_128) && \
  489. defined(HAVE_AES_CBC)
  490. #define BUILD_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
  491. #endif
  492. #ifdef HAVE_NULL_CIPHER
  493. #define BUILD_TLS_DHE_PSK_WITH_NULL_SHA256
  494. #endif
  495. #endif
  496. #ifdef WOLFSSL_SHA384
  497. #if !defined(NO_AES) && defined(WOLFSSL_AES_256) && \
  498. defined(HAVE_AES_CBC)
  499. #define BUILD_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
  500. #endif
  501. #ifdef HAVE_NULL_CIPHER
  502. #define BUILD_TLS_DHE_PSK_WITH_NULL_SHA384
  503. #endif
  504. #endif
  505. #endif
  506. #if (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || \
  507. defined(HAVE_CURVE448)) && !defined(NO_TLS)
  508. #if !defined(NO_AES)
  509. #if !defined(NO_SHA) && defined(HAVE_AES_CBC)
  510. #if !defined(NO_RSA)
  511. #ifdef WOLFSSL_AES_128
  512. #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
  513. #endif
  514. #ifdef WOLFSSL_AES_256
  515. #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
  516. #endif
  517. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  518. #ifdef WOLFSSL_AES_128
  519. #define BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
  520. #endif
  521. #ifdef WOLFSSL_AES_256
  522. #define BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
  523. #endif
  524. #endif
  525. #endif
  526. #if defined(HAVE_ECC) || \
  527. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  528. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  529. #ifdef WOLFSSL_AES_128
  530. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
  531. #endif
  532. #ifdef WOLFSSL_AES_256
  533. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
  534. #endif
  535. #endif
  536. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  537. #ifdef WOLFSSL_AES_128
  538. #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
  539. #endif
  540. #ifdef WOLFSSL_AES_256
  541. #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
  542. #endif
  543. #endif
  544. #endif /* NO_SHA */
  545. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  546. defined(HAVE_AES_CBC)
  547. #if !defined(NO_RSA)
  548. #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
  549. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  550. #define BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
  551. #endif
  552. #endif
  553. #if defined(HAVE_ECC) || \
  554. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  555. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  556. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
  557. #endif
  558. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  559. #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
  560. #endif
  561. #endif
  562. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  563. defined(HAVE_AES_CBC)
  564. #if !defined(NO_RSA)
  565. #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
  566. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  567. #define BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
  568. #endif
  569. #endif
  570. #if defined(HAVE_ECC) || \
  571. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  572. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  573. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
  574. #endif
  575. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  576. #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
  577. #endif
  578. #endif
  579. #if defined (HAVE_AESGCM)
  580. #if !defined(NO_RSA)
  581. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  582. #ifdef WOLFSSL_AES_128
  583. #define BUILD_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
  584. #endif
  585. #endif
  586. #if defined(WOLFSSL_SHA384)
  587. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  588. #ifdef WOLFSSL_AES_256
  589. #define BUILD_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
  590. #endif
  591. #endif
  592. #endif
  593. #endif
  594. #if defined(WOLFSSL_STATIC_DH) && defined(WOLFSSL_AES_128) && \
  595. defined(HAVE_ECC)
  596. #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
  597. #endif
  598. #if defined(WOLFSSL_SHA384)
  599. #if defined(WOLFSSL_STATIC_DH) && \
  600. defined(WOLFSSL_AES_256) && defined(HAVE_ECC)
  601. #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
  602. #endif
  603. #endif
  604. #endif
  605. #endif /* NO_AES */
  606. #if !defined(NO_RC4)
  607. #if !defined(NO_SHA)
  608. #if !defined(NO_RSA)
  609. #ifndef WOLFSSL_AEAD_ONLY
  610. #define BUILD_TLS_ECDHE_RSA_WITH_RC4_128_SHA
  611. #endif
  612. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  613. #define BUILD_TLS_ECDH_RSA_WITH_RC4_128_SHA
  614. #endif
  615. #endif
  616. #if defined(HAVE_ECC) || \
  617. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  618. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  619. #ifndef WOLFSSL_AEAD_ONLY
  620. #define BUILD_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
  621. #endif
  622. #endif
  623. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  624. #define BUILD_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
  625. #endif
  626. #endif
  627. #endif
  628. #if !defined(NO_DES3)
  629. #ifndef NO_SHA
  630. #if !defined(NO_RSA)
  631. #define BUILD_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
  632. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  633. #define BUILD_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
  634. #endif
  635. #endif
  636. #if defined(HAVE_ECC) || \
  637. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  638. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  639. #define BUILD_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
  640. #endif
  641. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  642. #define BUILD_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
  643. #endif
  644. #endif /* NO_SHA */
  645. #endif
  646. #if defined(HAVE_NULL_CIPHER)
  647. #if !defined(NO_SHA)
  648. #if defined(HAVE_ECC) || \
  649. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  650. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  651. #define BUILD_TLS_ECDHE_ECDSA_WITH_NULL_SHA
  652. #endif
  653. #endif
  654. #if !defined(NO_PSK) && !defined(NO_SHA256)
  655. #define BUILD_TLS_ECDHE_PSK_WITH_NULL_SHA256
  656. #endif
  657. #endif
  658. #if !defined(NO_PSK) && !defined(NO_SHA256) && !defined(NO_AES) && \
  659. defined(WOLFSSL_AES_128) && defined(HAVE_AES_CBC)
  660. #define BUILD_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
  661. #endif
  662. #endif
  663. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
  664. #if !defined(NO_OLD_POLY1305)
  665. #if defined(HAVE_ECC) || \
  666. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  667. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  668. #define BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256
  669. #endif
  670. #if !defined(NO_RSA) && defined(HAVE_ECC)
  671. #define BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256
  672. #endif
  673. #if !defined(NO_DH) && !defined(NO_RSA)
  674. #define BUILD_TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256
  675. #endif
  676. #endif /* NO_OLD_POLY1305 */
  677. #if !defined(NO_PSK)
  678. #define BUILD_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256
  679. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || \
  680. defined(HAVE_ED448)
  681. #define BUILD_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256
  682. #endif
  683. #ifndef NO_DH
  684. #define BUILD_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256
  685. #endif
  686. #endif /* !NO_PSK */
  687. #endif
  688. #endif /* !WOLFSSL_MAX_STRENGTH */
  689. #if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
  690. !defined(NO_RSA) && defined(HAVE_AESGCM)
  691. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  692. #define BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
  693. #endif
  694. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  695. #define BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
  696. #endif
  697. #endif
  698. #if !defined(NO_DH) && !defined(NO_PSK) && !defined(NO_TLS)
  699. #ifndef NO_SHA256
  700. #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128)
  701. #define BUILD_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
  702. #endif
  703. #ifdef HAVE_AESCCM
  704. #ifdef WOLFSSL_AES_128
  705. #define BUILD_TLS_DHE_PSK_WITH_AES_128_CCM
  706. #endif
  707. #ifdef WOLFSSL_AES_256
  708. #define BUILD_TLS_DHE_PSK_WITH_AES_256_CCM
  709. #endif
  710. #endif
  711. #endif
  712. #if defined(WOLFSSL_SHA384) && defined(HAVE_AESGCM) && \
  713. defined(WOLFSSL_AES_256)
  714. #define BUILD_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
  715. #endif
  716. #endif
  717. #if (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) \
  718. && !defined(NO_TLS) && !defined(NO_AES)
  719. #ifdef HAVE_AESGCM
  720. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  721. #if defined(HAVE_ECC) || \
  722. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  723. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  724. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
  725. #endif
  726. #ifndef NO_RSA
  727. #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  728. #endif
  729. #endif
  730. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  731. #if defined(HAVE_ECC) || \
  732. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  733. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  734. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
  735. #endif
  736. #ifndef NO_RSA
  737. #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
  738. #endif
  739. #endif
  740. #endif
  741. #if defined(HAVE_AESCCM) && !defined(NO_SHA256)
  742. #if defined(HAVE_ECC) || \
  743. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  744. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  745. #ifdef WOLFSSL_AES_128
  746. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM
  747. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
  748. #endif
  749. #ifdef WOLFSSL_AES_256
  750. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8
  751. #endif
  752. #endif
  753. #endif
  754. #endif
  755. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
  756. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  757. #if defined(HAVE_ECC) || \
  758. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  759. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  760. #define BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
  761. #endif
  762. #ifndef NO_RSA
  763. #define BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
  764. #endif
  765. #endif
  766. #if !defined(NO_DH) && !defined(NO_RSA)
  767. #define BUILD_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256
  768. #endif
  769. #endif
  770. #endif
  771. #if defined(WOLFSSL_TLS13)
  772. #ifdef HAVE_AESGCM
  773. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  774. #define BUILD_TLS_AES_128_GCM_SHA256
  775. #endif
  776. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  777. #define BUILD_TLS_AES_256_GCM_SHA384
  778. #endif
  779. #endif
  780. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  781. #ifndef NO_SHA256
  782. #define BUILD_TLS_CHACHA20_POLY1305_SHA256
  783. #endif
  784. #endif
  785. #ifdef HAVE_AESCCM
  786. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  787. #define BUILD_TLS_AES_128_CCM_SHA256
  788. #define BUILD_TLS_AES_128_CCM_8_SHA256
  789. #endif
  790. #endif
  791. #ifdef HAVE_NULL_CIPHER
  792. #ifndef NO_SHA256
  793. #define BUILD_TLS_SHA256_SHA256
  794. #endif
  795. #ifdef WOLFSSL_SHA384
  796. #define BUILD_TLS_SHA384_SHA384
  797. #endif
  798. #endif
  799. #endif
  800. #ifdef WOLFSSL_MULTICAST
  801. #if defined(HAVE_NULL_CIPHER) && !defined(NO_SHA256)
  802. #define BUILD_WDM_WITH_NULL_SHA256
  803. #endif
  804. #endif
  805. #if defined(BUILD_SSL_RSA_WITH_RC4_128_SHA) || \
  806. defined(BUILD_SSL_RSA_WITH_RC4_128_MD5)
  807. #define BUILD_ARC4
  808. #endif
  809. #if defined(BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA)
  810. #define BUILD_DES3
  811. #endif
  812. #if defined(BUILD_TLS_RSA_WITH_AES_128_CBC_SHA) || \
  813. defined(BUILD_TLS_RSA_WITH_AES_256_CBC_SHA) || \
  814. defined(BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256) || \
  815. defined(BUILD_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256)
  816. #undef BUILD_AES
  817. #define BUILD_AES
  818. #endif
  819. #if defined(BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256) || \
  820. defined(BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256) || \
  821. defined(BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) || \
  822. defined(BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256) || \
  823. defined(BUILD_TLS_PSK_WITH_AES_128_GCM_SHA256) || \
  824. defined(BUILD_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256) || \
  825. defined(BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384) || \
  826. defined(BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384) || \
  827. defined(BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) || \
  828. defined(BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384) || \
  829. defined(BUILD_TLS_PSK_WITH_AES_256_GCM_SHA384) || \
  830. defined(BUILD_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384) || \
  831. defined(BUILD_TLS_AES_128_GCM_SHA256) || \
  832. defined(BUILD_TLS_AES_256_GCM_SHA384)
  833. #define BUILD_AESGCM
  834. #else
  835. /* No AES-GCM cipher suites available with build */
  836. #define NO_AESGCM_AEAD
  837. #endif
  838. #if defined(BUILD_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256) || \
  839. defined(BUILD_TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256) || \
  840. defined(BUILD_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256) || \
  841. defined(BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256) || \
  842. defined(BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256) || \
  843. defined(BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256) || \
  844. defined(BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256) || \
  845. defined(BUILD_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256) || \
  846. defined(BUILD_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256) || \
  847. defined(BUILD_TLS_CHACHA20_POLY1305_SHA256)
  848. /* Have an available ChaCha Poly cipher suite */
  849. #else
  850. /* No ChaCha Poly cipher suites available with build */
  851. #define NO_CHAPOL_AEAD
  852. #endif
  853. #if defined(BUILD_TLS_RSA_WITH_HC_128_SHA) || \
  854. defined(BUILD_TLS_RSA_WITH_HC_128_MD5)
  855. #define BUILD_HC128
  856. #endif
  857. #if defined(BUILD_TLS_RSA_WITH_RABBIT_SHA)
  858. #define BUILD_RABBIT
  859. #endif
  860. #ifdef NO_DES3
  861. #define DES_BLOCK_SIZE 8
  862. #else
  863. #undef BUILD_DES3
  864. #define BUILD_DES3
  865. #endif
  866. #if defined(NO_AES) || !defined(HAVE_AES_DECRYPT)
  867. #define AES_BLOCK_SIZE 16
  868. #undef BUILD_AES
  869. #else
  870. #undef BUILD_AES
  871. #define BUILD_AES
  872. #endif
  873. #ifndef NO_RC4
  874. #undef BUILD_ARC4
  875. #define BUILD_ARC4
  876. #endif
  877. #ifdef HAVE_CHACHA
  878. #define CHACHA20_BLOCK_SIZE 16
  879. #endif
  880. #if defined(WOLFSSL_MAX_STRENGTH) || \
  881. (defined(HAVE_AESGCM) && !defined(NO_AESGCM_AEAD)) || \
  882. defined(HAVE_AESCCM) || \
  883. (defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && \
  884. !defined(NO_CHAPOL_AEAD)) || \
  885. (defined(WOLFSSL_TLS13) && defined(HAVE_NULL_CIPHER))
  886. #define HAVE_AEAD
  887. #endif
  888. #if defined(WOLFSSL_MAX_STRENGTH) || \
  889. defined(HAVE_ECC) || !defined(NO_DH)
  890. #define HAVE_PFS
  891. #endif
  892. #if defined(BUILD_SSL_RSA_WITH_IDEA_CBC_SHA)
  893. #define BUILD_IDEA
  894. #endif
  895. /* actual cipher values, 2nd byte */
  896. enum {
  897. TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA = 0x16,
  898. TLS_DHE_RSA_WITH_AES_256_CBC_SHA = 0x39,
  899. TLS_DHE_RSA_WITH_AES_128_CBC_SHA = 0x33,
  900. TLS_DH_anon_WITH_AES_128_CBC_SHA = 0x34,
  901. TLS_RSA_WITH_AES_256_CBC_SHA = 0x35,
  902. TLS_RSA_WITH_AES_128_CBC_SHA = 0x2F,
  903. TLS_RSA_WITH_NULL_MD5 = 0x01,
  904. TLS_RSA_WITH_NULL_SHA = 0x02,
  905. TLS_PSK_WITH_AES_256_CBC_SHA = 0x8d,
  906. TLS_PSK_WITH_AES_128_CBC_SHA256 = 0xae,
  907. TLS_PSK_WITH_AES_256_CBC_SHA384 = 0xaf,
  908. TLS_PSK_WITH_AES_128_CBC_SHA = 0x8c,
  909. TLS_PSK_WITH_NULL_SHA256 = 0xb0,
  910. TLS_PSK_WITH_NULL_SHA384 = 0xb1,
  911. TLS_PSK_WITH_NULL_SHA = 0x2c,
  912. SSL_RSA_WITH_RC4_128_SHA = 0x05,
  913. SSL_RSA_WITH_RC4_128_MD5 = 0x04,
  914. SSL_RSA_WITH_3DES_EDE_CBC_SHA = 0x0A,
  915. SSL_RSA_WITH_IDEA_CBC_SHA = 0x07,
  916. /* ECC suites, first byte is 0xC0 (ECC_BYTE) */
  917. TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0x14,
  918. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = 0x13,
  919. TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 0x0A,
  920. TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 0x09,
  921. TLS_ECDHE_RSA_WITH_RC4_128_SHA = 0x11,
  922. TLS_ECDHE_ECDSA_WITH_RC4_128_SHA = 0x07,
  923. TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA = 0x12,
  924. TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA = 0x08,
  925. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 = 0x27,
  926. TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 = 0x23,
  927. TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 = 0x28,
  928. TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 = 0x24,
  929. TLS_ECDHE_ECDSA_WITH_NULL_SHA = 0x06,
  930. TLS_ECDHE_PSK_WITH_NULL_SHA256 = 0x3a,
  931. TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 = 0x37,
  932. /* static ECDH, first byte is 0xC0 (ECC_BYTE) */
  933. TLS_ECDH_RSA_WITH_AES_256_CBC_SHA = 0x0F,
  934. TLS_ECDH_RSA_WITH_AES_128_CBC_SHA = 0x0E,
  935. TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA = 0x05,
  936. TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA = 0x04,
  937. TLS_ECDH_RSA_WITH_RC4_128_SHA = 0x0C,
  938. TLS_ECDH_ECDSA_WITH_RC4_128_SHA = 0x02,
  939. TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA = 0x0D,
  940. TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA = 0x03,
  941. TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 = 0x29,
  942. TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 = 0x25,
  943. TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 = 0x2A,
  944. TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 = 0x26,
  945. /* wolfSSL extension - eSTREAM */
  946. TLS_RSA_WITH_HC_128_MD5 = 0xFB,
  947. TLS_RSA_WITH_HC_128_SHA = 0xFC,
  948. TLS_RSA_WITH_RABBIT_SHA = 0xFD,
  949. WDM_WITH_NULL_SHA256 = 0xFE, /* wolfSSL DTLS Multicast */
  950. /* wolfSSL extension - NTRU */
  951. TLS_NTRU_RSA_WITH_RC4_128_SHA = 0xe5,
  952. TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA = 0xe6,
  953. TLS_NTRU_RSA_WITH_AES_128_CBC_SHA = 0xe7, /* clashes w/official SHA-256 */
  954. TLS_NTRU_RSA_WITH_AES_256_CBC_SHA = 0xe8,
  955. /* wolfSSL extension - NTRU , Quantum-safe Handshake
  956. first byte is 0xD0 (QSH_BYTE) */
  957. TLS_QSH = 0x01,
  958. /* SHA256 */
  959. TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 = 0x6b,
  960. TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 = 0x67,
  961. TLS_RSA_WITH_AES_256_CBC_SHA256 = 0x3d,
  962. TLS_RSA_WITH_AES_128_CBC_SHA256 = 0x3c,
  963. TLS_RSA_WITH_NULL_SHA256 = 0x3b,
  964. TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 = 0xb2,
  965. TLS_DHE_PSK_WITH_NULL_SHA256 = 0xb4,
  966. /* SHA384 */
  967. TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 = 0xb3,
  968. TLS_DHE_PSK_WITH_NULL_SHA384 = 0xb5,
  969. /* AES-GCM */
  970. TLS_RSA_WITH_AES_128_GCM_SHA256 = 0x9c,
  971. TLS_RSA_WITH_AES_256_GCM_SHA384 = 0x9d,
  972. TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 = 0x9e,
  973. TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 = 0x9f,
  974. TLS_DH_anon_WITH_AES_256_GCM_SHA384 = 0xa7,
  975. TLS_PSK_WITH_AES_128_GCM_SHA256 = 0xa8,
  976. TLS_PSK_WITH_AES_256_GCM_SHA384 = 0xa9,
  977. TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 = 0xaa,
  978. TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 = 0xab,
  979. /* ECC AES-GCM, first byte is 0xC0 (ECC_BYTE) */
  980. TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0x2b,
  981. TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 0x2c,
  982. TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 = 0x2d,
  983. TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 = 0x2e,
  984. TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0x2f,
  985. TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0x30,
  986. TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 = 0x31,
  987. TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 = 0x32,
  988. /* AES-CCM, first byte is 0xC0 but isn't ECC,
  989. * also, in some of the other AES-CCM suites
  990. * there will be second byte number conflicts
  991. * with non-ECC AES-GCM */
  992. TLS_RSA_WITH_AES_128_CCM_8 = 0xa0,
  993. TLS_RSA_WITH_AES_256_CCM_8 = 0xa1,
  994. TLS_ECDHE_ECDSA_WITH_AES_128_CCM = 0xac,
  995. TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 = 0xae,
  996. TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 = 0xaf,
  997. TLS_PSK_WITH_AES_128_CCM = 0xa4,
  998. TLS_PSK_WITH_AES_256_CCM = 0xa5,
  999. TLS_PSK_WITH_AES_128_CCM_8 = 0xa8,
  1000. TLS_PSK_WITH_AES_256_CCM_8 = 0xa9,
  1001. TLS_DHE_PSK_WITH_AES_128_CCM = 0xa6,
  1002. TLS_DHE_PSK_WITH_AES_256_CCM = 0xa7,
  1003. /* Camellia */
  1004. TLS_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x41,
  1005. TLS_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x84,
  1006. TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xba,
  1007. TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0xc0,
  1008. TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x45,
  1009. TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x88,
  1010. TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xbe,
  1011. TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0xc4,
  1012. /* chacha20-poly1305 suites first byte is 0xCC (CHACHA_BYTE) */
  1013. TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xa8,
  1014. TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = 0xa9,
  1015. TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xaa,
  1016. TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xac,
  1017. TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xab,
  1018. TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xad,
  1019. /* chacha20-poly1305 earlier version of nonce and padding (CHACHA_BYTE) */
  1020. TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 = 0x13,
  1021. TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256 = 0x14,
  1022. TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 = 0x15,
  1023. /* TLS v1.3 cipher suites */
  1024. TLS_AES_128_GCM_SHA256 = 0x01,
  1025. TLS_AES_256_GCM_SHA384 = 0x02,
  1026. TLS_CHACHA20_POLY1305_SHA256 = 0x03,
  1027. TLS_AES_128_CCM_SHA256 = 0x04,
  1028. TLS_AES_128_CCM_8_SHA256 = 0x05,
  1029. /* TLS v1.3 Integity only cipher suites - 0xC0 (ECC) first byte */
  1030. TLS_SHA256_SHA256 = 0xB4,
  1031. TLS_SHA384_SHA384 = 0xB5,
  1032. /* Fallback SCSV (Signaling Cipher Suite Value) */
  1033. TLS_FALLBACK_SCSV = 0x56,
  1034. /* Renegotiation Indication Extension Special Suite */
  1035. TLS_EMPTY_RENEGOTIATION_INFO_SCSV = 0xff
  1036. };
  1037. #ifndef WOLFSSL_SESSION_TIMEOUT
  1038. #define WOLFSSL_SESSION_TIMEOUT 500
  1039. /* default session resumption cache timeout in seconds */
  1040. #endif
  1041. #ifndef WOLFSSL_DTLS_WINDOW_WORDS
  1042. #define WOLFSSL_DTLS_WINDOW_WORDS 2
  1043. #endif /* WOLFSSL_DTLS_WINDOW_WORDS */
  1044. #define DTLS_WORD_BITS (sizeof(word32) * CHAR_BIT)
  1045. #define DTLS_SEQ_BITS (WOLFSSL_DTLS_WINDOW_WORDS * DTLS_WORD_BITS)
  1046. #define DTLS_SEQ_SZ (sizeof(word32) * WOLFSSL_DTLS_WINDOW_WORDS)
  1047. #ifndef WOLFSSL_MULTICAST
  1048. #define WOLFSSL_DTLS_PEERSEQ_SZ 1
  1049. #else
  1050. #ifndef WOLFSSL_MULTICAST_PEERS
  1051. /* max allowed multicast group peers */
  1052. #define WOLFSSL_MULTICAST_PEERS 100
  1053. #endif
  1054. #define WOLFSSL_DTLS_PEERSEQ_SZ WOLFSSL_MULTICAST_PEERS
  1055. #endif /* WOLFSSL_MULTICAST */
  1056. #ifndef WOLFSSL_MAX_MTU
  1057. #define WOLFSSL_MAX_MTU 1500
  1058. #endif /* WOLFSSL_MAX_MTU */
  1059. /* set minimum DH key size allowed */
  1060. #ifndef WOLFSSL_MIN_DHKEY_BITS
  1061. #ifdef WOLFSSL_MAX_STRENGTH
  1062. #define WOLFSSL_MIN_DHKEY_BITS 2048
  1063. #else
  1064. #define WOLFSSL_MIN_DHKEY_BITS 1024
  1065. #endif
  1066. #endif
  1067. #if (WOLFSSL_MIN_DHKEY_BITS % 8)
  1068. #error DH minimum bit size must be multiple of 8
  1069. #endif
  1070. #if (WOLFSSL_MIN_DHKEY_BITS > 16000)
  1071. #error DH minimum bit size must not be greater than 16000
  1072. #endif
  1073. #define MIN_DHKEY_SZ (WOLFSSL_MIN_DHKEY_BITS / 8)
  1074. /* set maximum DH key size allowed */
  1075. #ifndef WOLFSSL_MAX_DHKEY_BITS
  1076. #if (defined(USE_FAST_MATH) && defined(FP_MAX_BITS) && FP_MAX_BITS >= 16384)
  1077. #define WOLFSSL_MAX_DHKEY_BITS (FP_MAX_BITS / 2)
  1078. #else
  1079. #define WOLFSSL_MAX_DHKEY_BITS 4096
  1080. #endif
  1081. #endif
  1082. #if (WOLFSSL_MAX_DHKEY_BITS % 8)
  1083. #error DH maximum bit size must be multiple of 8
  1084. #endif
  1085. #if (WOLFSSL_MAX_DHKEY_BITS > 16000)
  1086. #error DH maximum bit size must not be greater than 16000
  1087. #endif
  1088. #define MAX_DHKEY_SZ (WOLFSSL_MAX_DHKEY_BITS / 8)
  1089. #ifndef MAX_PSK_ID_LEN
  1090. /* max psk identity/hint supported */
  1091. #if defined(WOLFSSL_TLS13)
  1092. /* OpenSSL has a 1472 byte sessiont ticket */
  1093. #define MAX_PSK_ID_LEN 1536
  1094. #else
  1095. #define MAX_PSK_ID_LEN 128
  1096. #endif
  1097. #endif
  1098. #ifndef MAX_EARLY_DATA_SZ
  1099. /* maximum early data size */
  1100. #define MAX_EARLY_DATA_SZ 4096
  1101. #endif
  1102. #ifndef WOLFSSL_MAX_RSA_BITS
  1103. #if (defined(USE_FAST_MATH) && defined(FP_MAX_BITS) && FP_MAX_BITS >= 16384)
  1104. #define WOLFSSL_MAX_RSA_BITS (FP_MAX_BITS / 2)
  1105. #else
  1106. #define WOLFSSL_MAX_RSA_BITS 4096
  1107. #endif
  1108. #endif
  1109. #if (WOLFSSL_MAX_RSA_BITS % 8)
  1110. #error RSA maximum bit size must be multiple of 8
  1111. #endif
  1112. enum Misc {
  1113. CIPHER_BYTE = 0x00, /* Default ciphers */
  1114. ECC_BYTE = 0xC0, /* ECC first cipher suite byte */
  1115. QSH_BYTE = 0xD0, /* Quantum-safe Handshake cipher suite */
  1116. CHACHA_BYTE = 0xCC, /* ChaCha first cipher suite */
  1117. TLS13_BYTE = 0x13, /* TLS v1.3 first byte of cipher suite */
  1118. SEND_CERT = 1,
  1119. SEND_BLANK_CERT = 2,
  1120. DTLS_MAJOR = 0xfe, /* DTLS major version number */
  1121. DTLS_MINOR = 0xff, /* DTLS minor version number */
  1122. DTLSv1_2_MINOR = 0xfd, /* DTLS minor version number */
  1123. SSLv3_MAJOR = 3, /* SSLv3 and TLSv1+ major version number */
  1124. SSLv3_MINOR = 0, /* TLSv1 minor version number */
  1125. TLSv1_MINOR = 1, /* TLSv1 minor version number */
  1126. TLSv1_1_MINOR = 2, /* TLSv1_1 minor version number */
  1127. TLSv1_2_MINOR = 3, /* TLSv1_2 minor version number */
  1128. TLSv1_3_MINOR = 4, /* TLSv1_3 minor version number */
  1129. TLS_DRAFT_MAJOR = 0x7f, /* Draft TLS major version number */
  1130. OLD_HELLO_ID = 0x01, /* SSLv2 Client Hello Indicator */
  1131. INVALID_BYTE = 0xff, /* Used to initialize cipher specs values */
  1132. NO_COMPRESSION = 0,
  1133. ZLIB_COMPRESSION = 221, /* wolfSSL zlib compression */
  1134. HELLO_EXT_SIG_ALGO = 13, /* ID for the sig_algo hello extension */
  1135. HELLO_EXT_EXTMS = 0x0017, /* ID for the extended master secret ext */
  1136. SECRET_LEN = WOLFSSL_MAX_MASTER_KEY_LENGTH,
  1137. /* pre RSA and all master */
  1138. #if defined(WOLFSSL_MYSQL_COMPATIBLE) || \
  1139. (defined(USE_FAST_MATH) && defined(FP_MAX_BITS) && FP_MAX_BITS >= 16384)
  1140. #ifndef NO_PSK
  1141. ENCRYPT_LEN = (FP_MAX_BITS / 2 / 8) + MAX_PSK_ID_LEN + 2,
  1142. #else
  1143. ENCRYPT_LEN = 1024, /* allow 8192 bit static buffer */
  1144. #endif
  1145. #else
  1146. #ifndef NO_PSK
  1147. ENCRYPT_LEN = 512 + MAX_PSK_ID_LEN + 2, /* 4096 bit static buffer */
  1148. #else
  1149. ENCRYPT_LEN = 512, /* allow 4096 bit static buffer */
  1150. #endif
  1151. #endif
  1152. SIZEOF_SENDER = 4, /* clnt or srvr */
  1153. FINISHED_SZ = 36, /* WC_MD5_DIGEST_SIZE + WC_SHA_DIGEST_SIZE */
  1154. MAX_RECORD_SIZE = 16384, /* 2^14, max size by standard */
  1155. MAX_PLAINTEXT_SZ = (1 << 14), /* Max plaintext sz */
  1156. MAX_TLS_CIPHER_SZ = (1 << 14) + 2048, /* Max TLS encrypted data sz */
  1157. #ifdef WOLFSSL_TLS13
  1158. MAX_TLS13_PLAIN_SZ = (1 << 14) + 1, /* Max unencrypted data sz */
  1159. MAX_TLS13_ENC_SZ = (1 << 14) + 256, /* Max encrypted data sz */
  1160. #endif
  1161. MAX_MSG_EXTRA = 38 + WC_MAX_DIGEST_SIZE,
  1162. /* max added to msg, mac + pad from */
  1163. /* RECORD_HEADER_SZ + BLOCK_SZ (pad) + Max
  1164. digest sz + BLOC_SZ (iv) + pad byte (1) */
  1165. MAX_COMP_EXTRA = 1024, /* max compression extra */
  1166. MAX_MTU = WOLFSSL_MAX_MTU, /* max expected MTU */
  1167. MAX_UDP_SIZE = 8192 - 100, /* was MAX_MTU - 100 */
  1168. MAX_DH_SZ = (MAX_DHKEY_SZ * 3) + 12, /* DH_P, DH_G and DH_Pub */
  1169. /* 4096 p, pub, g + 2 byte size for each */
  1170. MAX_STR_VERSION = 8, /* string rep of protocol version */
  1171. PAD_MD5 = 48, /* pad length for finished */
  1172. PAD_SHA = 40, /* pad length for finished */
  1173. MAX_PAD_SIZE = 256, /* maximum length of padding */
  1174. LENGTH_SZ = 2, /* length field for HMAC, data only */
  1175. VERSION_SZ = 2, /* length of proctocol version */
  1176. SEQ_SZ = 8, /* 64 bit sequence number */
  1177. ALERT_SIZE = 2, /* level + description */
  1178. VERIFY_HEADER = 2, /* always use 2 bytes */
  1179. EXTS_SZ = 2, /* always use 2 bytes */
  1180. EXT_ID_SZ = 2, /* always use 2 bytes */
  1181. MAX_DH_SIZE = MAX_DHKEY_SZ+1,
  1182. /* Max size plus possible leading 0 */
  1183. NAMED_DH_MASK = 0x100, /* Named group mask for DH parameters */
  1184. MIN_FFHDE_GROUP = 0x100, /* Named group minimum for FFDHE parameters */
  1185. MAX_FFHDE_GROUP = 0x1FF, /* Named group maximum for FFDHE parameters */
  1186. SESSION_HINT_SZ = 4, /* session timeout hint */
  1187. SESSION_ADD_SZ = 4, /* session age add */
  1188. TICKET_NONCE_LEN_SZ = 1, /* Ticket nonce length size */
  1189. DEF_TICKET_NONCE_SZ = 1, /* Default ticket nonce size */
  1190. MAX_TICKET_NONCE_SZ = 8, /* maximum ticket nonce size */
  1191. MAX_LIFETIME = 604800, /* maximum ticket lifetime */
  1192. RAN_LEN = 32, /* random length */
  1193. SEED_LEN = RAN_LEN * 2, /* tls prf seed length */
  1194. ID_LEN = 32, /* session id length */
  1195. COOKIE_SECRET_SZ = 14, /* dtls cookie secret size */
  1196. MAX_COOKIE_LEN = 32, /* max dtls cookie size */
  1197. COOKIE_SZ = 20, /* use a 20 byte cookie */
  1198. SUITE_LEN = 2, /* cipher suite sz length */
  1199. ENUM_LEN = 1, /* always a byte */
  1200. OPAQUE8_LEN = 1, /* 1 byte */
  1201. OPAQUE16_LEN = 2, /* 2 bytes */
  1202. OPAQUE24_LEN = 3, /* 3 bytes */
  1203. OPAQUE32_LEN = 4, /* 4 bytes */
  1204. OPAQUE64_LEN = 8, /* 8 bytes */
  1205. COMP_LEN = 1, /* compression length */
  1206. CURVE_LEN = 2, /* ecc named curve length */
  1207. KE_GROUP_LEN = 2, /* key exchange group length */
  1208. SERVER_ID_LEN = 20, /* server session id length */
  1209. HANDSHAKE_HEADER_SZ = 4, /* type + length(3) */
  1210. RECORD_HEADER_SZ = 5, /* type + version + len(2) */
  1211. CERT_HEADER_SZ = 3, /* always 3 bytes */
  1212. REQ_HEADER_SZ = 2, /* cert request header sz */
  1213. HINT_LEN_SZ = 2, /* length of hint size field */
  1214. TRUNCATED_HMAC_SZ = 10, /* length of hmac w/ truncated hmac extension */
  1215. HELLO_EXT_SZ = 4, /* base length of a hello extension */
  1216. HELLO_EXT_TYPE_SZ = 2, /* length of a hello extension type */
  1217. HELLO_EXT_SZ_SZ = 2, /* length of a hello extension size */
  1218. HELLO_EXT_SIGALGO_SZ = 2, /* length of number of items in sigalgo list */
  1219. DTLS_HANDSHAKE_HEADER_SZ = 12, /* normal + seq(2) + offset(3) + length(3) */
  1220. DTLS_RECORD_HEADER_SZ = 13, /* normal + epoch(2) + seq_num(6) */
  1221. DTLS_HANDSHAKE_EXTRA = 8, /* diff from normal */
  1222. DTLS_RECORD_EXTRA = 8, /* diff from normal */
  1223. DTLS_HANDSHAKE_SEQ_SZ = 2, /* handshake header sequence number */
  1224. DTLS_HANDSHAKE_FRAG_SZ = 3, /* fragment offset and length are 24 bit */
  1225. DTLS_POOL_SZ = 255,/* allowed number of list items in TX pool */
  1226. DTLS_EXPORT_PRO = 165,/* wolfSSL protocol for serialized session */
  1227. DTLS_EXPORT_STATE_PRO = 166,/* wolfSSL protocol for serialized state */
  1228. DTLS_EXPORT_VERSION = 4, /* wolfSSL version for serialized session */
  1229. DTLS_EXPORT_OPT_SZ = 60, /* amount of bytes used from Options */
  1230. DTLS_EXPORT_VERSION_3 = 3, /* wolfSSL version before TLS 1.3 addition */
  1231. DTLS_EXPORT_OPT_SZ_3 = 59, /* amount of bytes used from Options */
  1232. DTLS_EXPORT_KEY_SZ = 325 + (DTLS_SEQ_SZ * 2),
  1233. /* max amount of bytes used from Keys */
  1234. DTLS_EXPORT_MIN_KEY_SZ = 85 + (DTLS_SEQ_SZ * 2),
  1235. /* min amount of bytes used from Keys */
  1236. DTLS_EXPORT_SPC_SZ = 16, /* amount of bytes used from CipherSpecs */
  1237. DTLS_EXPORT_LEN = 2, /* 2 bytes for length and protocol */
  1238. DTLS_EXPORT_IP = 46, /* max ip size IPv4 mapped IPv6 */
  1239. MAX_EXPORT_BUFFER = 514, /* max size of buffer for exporting */
  1240. MAX_EXPORT_STATE_BUFFER = (DTLS_EXPORT_MIN_KEY_SZ) + (3 * DTLS_EXPORT_LEN),
  1241. /* max size of buffer for exporting state */
  1242. FINISHED_LABEL_SZ = 15, /* TLS finished label size */
  1243. TLS_FINISHED_SZ = 12, /* TLS has a shorter size */
  1244. EXT_MASTER_LABEL_SZ = 22, /* TLS extended master secret label sz */
  1245. MASTER_LABEL_SZ = 13, /* TLS master secret label sz */
  1246. KEY_LABEL_SZ = 13, /* TLS key block expansion sz */
  1247. PROTOCOL_LABEL_SZ = 9, /* Length of the protocol label */
  1248. MAX_LABEL_SZ = 34, /* Maximum length of a label */
  1249. MAX_HKDF_LABEL_SZ = OPAQUE16_LEN +
  1250. OPAQUE8_LEN + PROTOCOL_LABEL_SZ + MAX_LABEL_SZ +
  1251. OPAQUE8_LEN + WC_MAX_DIGEST_SIZE,
  1252. MAX_REQUEST_SZ = 256, /* Maximum cert req len (no auth yet */
  1253. SESSION_FLUSH_COUNT = 256, /* Flush session cache unless user turns off */
  1254. TLS_MAX_PAD_SZ = 255, /* Max padding in TLS */
  1255. #if defined(HAVE_FIPS) && \
  1256. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
  1257. MAX_SYM_KEY_SIZE = AES_256_KEY_SIZE,
  1258. #else
  1259. #if defined(HAVE_NULL_CIPHER) && defined(WOLFSSL_TLS13)
  1260. #if defined(WOLFSSL_SHA384) && WC_MAX_SYM_KEY_SIZE < 48
  1261. MAX_SYM_KEY_SIZE = WC_SHA384_DIGEST_SIZE,
  1262. #elif !defined(NO_SHA256) && WC_MAX_SYM_KEY_SIZE < 32
  1263. MAX_SYM_KEY_SIZE = WC_SHA256_DIGEST_SIZE,
  1264. #else
  1265. MAX_SYM_KEY_SIZE = WC_MAX_SYM_KEY_SIZE,
  1266. #endif
  1267. #else
  1268. MAX_SYM_KEY_SIZE = WC_MAX_SYM_KEY_SIZE,
  1269. #endif
  1270. #endif
  1271. #if defined(HAVE_SELFTEST) && \
  1272. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  1273. #ifndef WOLFSSL_AES_KEY_SIZE_ENUM
  1274. #define WOLFSSL_AES_KEY_SIZE_ENUM
  1275. AES_IV_SIZE = 16,
  1276. AES_128_KEY_SIZE = 16,
  1277. AES_192_KEY_SIZE = 24,
  1278. AES_256_KEY_SIZE = 32,
  1279. #endif
  1280. #endif
  1281. MAX_IV_SZ = AES_BLOCK_SIZE,
  1282. AEAD_SEQ_OFFSET = 4, /* Auth Data: Sequence number */
  1283. AEAD_TYPE_OFFSET = 8, /* Auth Data: Type */
  1284. AEAD_VMAJ_OFFSET = 9, /* Auth Data: Major Version */
  1285. AEAD_VMIN_OFFSET = 10, /* Auth Data: Minor Version */
  1286. AEAD_LEN_OFFSET = 11, /* Auth Data: Length */
  1287. AEAD_AUTH_DATA_SZ = 13, /* Size of the data to authenticate */
  1288. AEAD_NONCE_SZ = 12,
  1289. AESGCM_IMP_IV_SZ = 4, /* Size of GCM/CCM AEAD implicit IV */
  1290. AESGCM_EXP_IV_SZ = 8, /* Size of GCM/CCM AEAD explicit IV */
  1291. AESGCM_NONCE_SZ = AESGCM_EXP_IV_SZ + AESGCM_IMP_IV_SZ,
  1292. CHACHA20_IMP_IV_SZ = 12, /* Size of ChaCha20 AEAD implicit IV */
  1293. CHACHA20_NONCE_SZ = 12, /* Size of ChacCha20 nonce */
  1294. CHACHA20_OLD_OFFSET = 4, /* Offset for seq # in old poly1305 */
  1295. /* For any new implicit/explicit IV size adjust AEAD_MAX_***_SZ */
  1296. AES_GCM_AUTH_SZ = 16, /* AES-GCM Auth Tag length */
  1297. AES_CCM_16_AUTH_SZ = 16, /* AES-CCM-16 Auth Tag length */
  1298. AES_CCM_8_AUTH_SZ = 8, /* AES-CCM-8 Auth Tag Length */
  1299. AESCCM_NONCE_SZ = 12,
  1300. CAMELLIA_128_KEY_SIZE = 16, /* for 128 bit */
  1301. CAMELLIA_192_KEY_SIZE = 24, /* for 192 bit */
  1302. CAMELLIA_256_KEY_SIZE = 32, /* for 256 bit */
  1303. CAMELLIA_IV_SIZE = 16, /* always block size */
  1304. CHACHA20_256_KEY_SIZE = 32, /* for 256 bit */
  1305. CHACHA20_128_KEY_SIZE = 16, /* for 128 bit */
  1306. CHACHA20_IV_SIZE = 12, /* 96 bits for iv */
  1307. POLY1305_AUTH_SZ = 16, /* 128 bits */
  1308. HMAC_NONCE_SZ = 12, /* Size of HMAC nonce */
  1309. HC_128_KEY_SIZE = 16, /* 128 bits */
  1310. HC_128_IV_SIZE = 16, /* also 128 bits */
  1311. RABBIT_KEY_SIZE = 16, /* 128 bits */
  1312. RABBIT_IV_SIZE = 8, /* 64 bits for iv */
  1313. EVP_SALT_SIZE = 8, /* evp salt size 64 bits */
  1314. #ifndef ECDHE_SIZE /* allow this to be overridden at compile-time */
  1315. ECDHE_SIZE = 32, /* ECHDE server size defaults to 256 bit */
  1316. #endif
  1317. MAX_EXPORT_ECC_SZ = 256, /* Export ANS X9.62 max future size */
  1318. MAX_CURVE_NAME_SZ = 16, /* Maximum size of curve name string */
  1319. NEW_SA_MAJOR = 8, /* Most significant byte used with new sig algos */
  1320. ED25519_SA_MAJOR = 8, /* Most significant byte for ED25519 */
  1321. ED25519_SA_MINOR = 7, /* Least significant byte for ED25519 */
  1322. ED448_SA_MAJOR = 8, /* Most significant byte for ED448 */
  1323. ED448_SA_MINOR = 8, /* Least significant byte for ED448 */
  1324. MIN_RSA_SHA512_PSS_BITS = 512 * 2 + 8 * 8, /* Min key size */
  1325. MIN_RSA_SHA384_PSS_BITS = 384 * 2 + 8 * 8, /* Min key size */
  1326. #ifndef NO_RSA
  1327. MAX_CERT_VERIFY_SZ = WOLFSSL_MAX_RSA_BITS / 8, /* max RSA bytes */
  1328. #elif defined(HAVE_ECC)
  1329. MAX_CERT_VERIFY_SZ = ECC_MAX_SIG_SIZE, /* max ECC */
  1330. #elif defined(HAVE_ED448)
  1331. MAX_CERT_VERIFY_SZ = ED448_SIG_SIZE, /* max Ed448 */
  1332. #elif defined(HAVE_ED25519)
  1333. MAX_CERT_VERIFY_SZ = ED25519_SIG_SIZE, /* max Ed25519 */
  1334. #else
  1335. MAX_CERT_VERIFY_SZ = 1024, /* max default */
  1336. #endif
  1337. CLIENT_HELLO_FIRST = 35, /* Protocol + RAN_LEN + sizeof(id_len) */
  1338. MAX_SUITE_NAME = 48, /* maximum length of cipher suite string */
  1339. DTLS_TIMEOUT_INIT = 1, /* default timeout init for DTLS receive */
  1340. DTLS_TIMEOUT_MAX = 64, /* default max timeout for DTLS receive */
  1341. DTLS_TIMEOUT_MULTIPLIER = 2, /* default timeout multiplier for DTLS recv */
  1342. NULL_TERM_LEN = 1, /* length of null '\0' termination character */
  1343. MAX_PSK_KEY_LEN = 64, /* max psk key supported */
  1344. MIN_PSK_ID_LEN = 6, /* min length of identities */
  1345. MIN_PSK_BINDERS_LEN= 33, /* min length of binders */
  1346. MAX_TICKET_AGE_SECS= 10, /* maximum ticket age in seconds */
  1347. #ifndef MAX_WOLFSSL_FILE_SIZE
  1348. MAX_WOLFSSL_FILE_SIZE = 1024ul * 1024ul * 4, /* 4 mb file size alloc limit */
  1349. #endif
  1350. MAX_X509_SIZE = 2048, /* max static x509 buffer size */
  1351. CERT_MIN_SIZE = 256, /* min PEM cert size with header/footer */
  1352. MAX_NTRU_PUB_KEY_SZ = 1027, /* NTRU max for now */
  1353. MAX_NTRU_ENCRYPT_SZ = 1027, /* NTRU max for now */
  1354. MAX_NTRU_BITS = 256, /* max symmetric bit strength */
  1355. NO_SNIFF = 0, /* not sniffing */
  1356. SNIFF = 1, /* currently sniffing */
  1357. HASH_SIG_SIZE = 2, /* default SHA1 RSA */
  1358. NO_COPY = 0, /* should we copy static buffer for write */
  1359. COPY = 1, /* should we copy static buffer for write */
  1360. INVALID_PEER_ID = 0xFFFF, /* Initialize value for peer ID. */
  1361. PREV_ORDER = -1, /* Sequence number is in previous epoch. */
  1362. PEER_ORDER = 1, /* Peer sequence number for verify. */
  1363. CUR_ORDER = 0, /* Current sequence number. */
  1364. WRITE_PROTO = 1, /* writing a protocol message */
  1365. READ_PROTO = 0 /* reading a protocol message */
  1366. };
  1367. /* minimum Downgrade Minor version */
  1368. #ifndef WOLFSSL_MIN_DOWNGRADE
  1369. #ifndef NO_OLD_TLS
  1370. #define WOLFSSL_MIN_DOWNGRADE TLSv1_MINOR
  1371. #else
  1372. #define WOLFSSL_MIN_DOWNGRADE TLSv1_2_MINOR
  1373. #endif
  1374. #endif
  1375. /* Set max implicit IV size for AEAD cipher suites */
  1376. #define AEAD_MAX_IMP_SZ 12
  1377. /* Set max explicit IV size for AEAD cipher suites */
  1378. #define AEAD_MAX_EXP_SZ 8
  1379. #ifndef WOLFSSL_MAX_SUITE_SZ
  1380. #define WOLFSSL_MAX_SUITE_SZ 300
  1381. /* 150 suites for now! */
  1382. #endif
  1383. /* number of items in the signature algo list */
  1384. #ifndef WOLFSSL_MAX_SIGALGO
  1385. #define WOLFSSL_MAX_SIGALGO 36
  1386. #endif
  1387. /* set minimum ECC key size allowed */
  1388. #ifndef WOLFSSL_MIN_ECC_BITS
  1389. #ifdef WOLFSSL_MAX_STRENGTH
  1390. #define WOLFSSL_MIN_ECC_BITS 256
  1391. #else
  1392. #define WOLFSSL_MIN_ECC_BITS 224
  1393. #endif
  1394. #endif /* WOLFSSL_MIN_ECC_BITS */
  1395. #if (WOLFSSL_MIN_ECC_BITS % 8)
  1396. /* Some ECC keys are not divisible by 8 such as prime239v1 or sect131r1.
  1397. In these cases round down to the nearest value divisible by 8. The
  1398. restriction of being divisible by 8 is in place to match wc_ecc_size
  1399. function from wolfSSL.
  1400. */
  1401. #error ECC minimum bit size must be a multiple of 8
  1402. #endif
  1403. #define MIN_ECCKEY_SZ (WOLFSSL_MIN_ECC_BITS / 8)
  1404. /* set minimum RSA key size allowed */
  1405. #ifndef WOLFSSL_MIN_RSA_BITS
  1406. #ifdef WOLFSSL_MAX_STRENGTH
  1407. #define WOLFSSL_MIN_RSA_BITS 2048
  1408. #else
  1409. #define WOLFSSL_MIN_RSA_BITS 1024
  1410. #endif
  1411. #endif /* WOLFSSL_MIN_RSA_BITS */
  1412. #if (WOLFSSL_MIN_RSA_BITS % 8)
  1413. /* This is to account for the example case of a min size of 2050 bits but
  1414. still allows 2049 bit key. So we need the measurement to be in bytes. */
  1415. #error RSA minimum bit size must be a multiple of 8
  1416. #endif
  1417. #define MIN_RSAKEY_SZ (WOLFSSL_MIN_RSA_BITS / 8)
  1418. #ifdef SESSION_INDEX
  1419. /* Shift values for making a session index */
  1420. #define SESSIDX_ROW_SHIFT 4
  1421. #define SESSIDX_IDX_MASK 0x0F
  1422. #endif
  1423. /* max cert chain peer depth */
  1424. #ifndef MAX_CHAIN_DEPTH
  1425. #define MAX_CHAIN_DEPTH 9
  1426. #endif
  1427. /* max size of a certificate message payload */
  1428. /* assumes MAX_CHAIN_DEPTH number of certificates at 2kb per certificate */
  1429. #ifndef MAX_CERTIFICATE_SZ
  1430. #define MAX_CERTIFICATE_SZ \
  1431. CERT_HEADER_SZ + \
  1432. (MAX_X509_SIZE + CERT_HEADER_SZ) * MAX_CHAIN_DEPTH
  1433. #endif
  1434. /* max size of a handshake message, currently set to the certificate */
  1435. #ifndef MAX_HANDSHAKE_SZ
  1436. #define MAX_HANDSHAKE_SZ MAX_CERTIFICATE_SZ
  1437. #endif
  1438. #ifndef SESSION_TICKET_LEN
  1439. #define SESSION_TICKET_LEN 256
  1440. #endif
  1441. #ifndef SESSION_TICKET_HINT_DEFAULT
  1442. #define SESSION_TICKET_HINT_DEFAULT 300
  1443. #endif
  1444. #if !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(WOLFSSL_NO_SERVER)
  1445. /* Check chosen encryption is available. */
  1446. #if !(defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) && \
  1447. defined(WOLFSSL_TICKET_ENC_CHACHA20_POLY1305)
  1448. #error "ChaCha20-Poly1305 not available for default ticket encryption"
  1449. #endif
  1450. #if !defined(HAVE_AESGCM) && (defined(WOLFSSL_TICKET_ENC_AES128_GCM) || \
  1451. defined(WOLFSSL_TICKET_ENC_AES256_GCM))
  1452. #error "AES-GCM not available for default ticket encryption"
  1453. #endif
  1454. #ifndef WOLFSSL_TICKET_KEY_LIFETIME
  1455. /* Default lifetime is 1 hour from issue of first ticket with key. */
  1456. #define WOLFSSL_TICKET_KEY_LIFETIME (60 * 60)
  1457. #endif
  1458. #if WOLFSSL_TICKET_KEY_LIFETIME <= SESSION_TICKET_HINT_DEFAULT
  1459. #error "Ticket Key lifetime must be longer than ticket life hint."
  1460. #endif
  1461. #endif
  1462. /* don't use extra 3/4k stack space unless need to */
  1463. #ifdef HAVE_NTRU
  1464. #define MAX_ENCRYPT_SZ MAX_NTRU_ENCRYPT_SZ
  1465. #else
  1466. #define MAX_ENCRYPT_SZ ENCRYPT_LEN
  1467. #endif
  1468. /* states */
  1469. enum states {
  1470. NULL_STATE = 0,
  1471. SERVER_HELLOVERIFYREQUEST_COMPLETE,
  1472. SERVER_HELLO_RETRY_REQUEST_COMPLETE,
  1473. SERVER_HELLO_COMPLETE,
  1474. SERVER_ENCRYPTED_EXTENSIONS_COMPLETE,
  1475. SERVER_CERT_COMPLETE,
  1476. SERVER_CERT_VERIFY_COMPLETE,
  1477. SERVER_KEYEXCHANGE_COMPLETE,
  1478. SERVER_HELLODONE_COMPLETE,
  1479. SERVER_CHANGECIPHERSPEC_COMPLETE,
  1480. SERVER_FINISHED_COMPLETE,
  1481. CLIENT_HELLO_RETRY,
  1482. CLIENT_HELLO_COMPLETE,
  1483. CLIENT_KEYEXCHANGE_COMPLETE,
  1484. CLIENT_CHANGECIPHERSPEC_COMPLETE,
  1485. CLIENT_FINISHED_COMPLETE,
  1486. HANDSHAKE_DONE
  1487. };
  1488. /* SSL Version */
  1489. typedef struct ProtocolVersion {
  1490. byte major;
  1491. byte minor;
  1492. } WOLFSSL_PACK ProtocolVersion;
  1493. WOLFSSL_LOCAL ProtocolVersion MakeSSLv3(void);
  1494. WOLFSSL_LOCAL ProtocolVersion MakeTLSv1(void);
  1495. WOLFSSL_LOCAL ProtocolVersion MakeTLSv1_1(void);
  1496. WOLFSSL_LOCAL ProtocolVersion MakeTLSv1_2(void);
  1497. WOLFSSL_LOCAL ProtocolVersion MakeTLSv1_3(void);
  1498. #ifdef WOLFSSL_DTLS
  1499. WOLFSSL_LOCAL ProtocolVersion MakeDTLSv1(void);
  1500. WOLFSSL_LOCAL ProtocolVersion MakeDTLSv1_2(void);
  1501. #ifdef WOLFSSL_SESSION_EXPORT
  1502. WOLFSSL_LOCAL int wolfSSL_dtls_import_internal(WOLFSSL* ssl, const byte* buf,
  1503. word32 sz);
  1504. WOLFSSL_LOCAL int wolfSSL_dtls_export_internal(WOLFSSL* ssl, byte* buf,
  1505. word32 sz);
  1506. WOLFSSL_LOCAL int wolfSSL_dtls_export_state_internal(WOLFSSL* ssl,
  1507. byte* buf, word32 sz);
  1508. WOLFSSL_LOCAL int wolfSSL_dtls_import_state_internal(WOLFSSL* ssl,
  1509. const byte* buf, word32 sz);
  1510. WOLFSSL_LOCAL int wolfSSL_send_session(WOLFSSL* ssl);
  1511. #endif
  1512. #endif
  1513. struct WOLFSSL_BY_DIR_HASH {
  1514. unsigned long hash_value;
  1515. int last_suffix;
  1516. };
  1517. struct WOLFSSL_BY_DIR_entry {
  1518. char* dir_name;
  1519. int dir_type;
  1520. WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH) *hashes;
  1521. };
  1522. struct WOLFSSL_BY_DIR {
  1523. WOLF_STACK_OF(WOLFSSL_BY_DIR_entry) *dir_entry;
  1524. wolfSSL_Mutex lock; /* dir list lock */
  1525. };
  1526. /* wolfSSL method type */
  1527. struct WOLFSSL_METHOD {
  1528. ProtocolVersion version;
  1529. byte side; /* connection side, server or client */
  1530. byte downgrade; /* whether to downgrade version, default no */
  1531. };
  1532. /* wolfSSL buffer type - internal uses "buffer" type */
  1533. typedef WOLFSSL_BUFFER_INFO buffer;
  1534. typedef struct Suites Suites;
  1535. /* defaults to client */
  1536. WOLFSSL_LOCAL void InitSSL_Method(WOLFSSL_METHOD*, ProtocolVersion);
  1537. WOLFSSL_LOCAL int InitSSL_Suites(WOLFSSL* ssl);
  1538. WOLFSSL_LOCAL int InitSSL_Side(WOLFSSL* ssl, word16 side);
  1539. /* for sniffer */
  1540. WOLFSSL_LOCAL int DoFinished(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
  1541. word32 size, word32 totalSz, int sniff);
  1542. #ifdef WOLFSSL_TLS13
  1543. WOLFSSL_LOCAL int DoTls13Finished(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
  1544. word32 size, word32 totalSz, int sniff);
  1545. #endif
  1546. WOLFSSL_LOCAL int DoApplicationData(WOLFSSL* ssl, byte* input, word32* inOutIdx);
  1547. /* TLS v1.3 needs these */
  1548. WOLFSSL_LOCAL int HandleTlsResumption(WOLFSSL* ssl, int bogusID,
  1549. Suites* clSuites);
  1550. #ifdef WOLFSSL_TLS13
  1551. WOLFSSL_LOCAL int FindSuite(Suites* suites, byte first, byte second);
  1552. #endif
  1553. WOLFSSL_LOCAL int DoClientHello(WOLFSSL* ssl, const byte* input, word32*,
  1554. word32);
  1555. #ifdef WOLFSSL_TLS13
  1556. WOLFSSL_LOCAL int DoTls13ClientHello(WOLFSSL* ssl, const byte* input,
  1557. word32* inOutIdx, word32 helloSz);
  1558. #endif
  1559. WOLFSSL_LOCAL int DoServerHello(WOLFSSL* ssl, const byte* input, word32*,
  1560. word32);
  1561. WOLFSSL_LOCAL int CompleteServerHello(WOLFSSL *ssl);
  1562. WOLFSSL_LOCAL int CheckVersion(WOLFSSL *ssl, ProtocolVersion pv);
  1563. WOLFSSL_LOCAL int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo,
  1564. word32 hashSigAlgoSz);
  1565. #ifdef WOLF_CRYPTO_CB
  1566. WOLFSSL_LOCAL int CreateDevPrivateKey(void** pkey, byte* buffer, word32 length,
  1567. int hsType, int label, int id,
  1568. void* heap, int devId);
  1569. #endif
  1570. WOLFSSL_LOCAL int DecodePrivateKey(WOLFSSL *ssl, word16* length);
  1571. #ifdef HAVE_PK_CALLBACKS
  1572. WOLFSSL_LOCAL int GetPrivateKeySigSize(WOLFSSL* ssl);
  1573. #ifndef NO_ASN
  1574. WOLFSSL_LOCAL int InitSigPkCb(WOLFSSL* ssl, SignatureCtx* sigCtx);
  1575. #endif
  1576. #endif
  1577. WOLFSSL_LOCAL void FreeKeyExchange(WOLFSSL* ssl);
  1578. WOLFSSL_LOCAL void FreeSuites(WOLFSSL* ssl);
  1579. WOLFSSL_LOCAL int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx, word32 size);
  1580. WOLFSSL_LOCAL int MatchDomainName(const char* pattern, int len, const char* str);
  1581. #ifndef NO_CERTS
  1582. WOLFSSL_LOCAL int CheckForAltNames(DecodedCert* dCert, const char* domain, int* checkCN);
  1583. WOLFSSL_LOCAL int CheckIPAddr(DecodedCert* dCert, const char* ipasc);
  1584. #endif
  1585. WOLFSSL_LOCAL int CreateTicket(WOLFSSL* ssl);
  1586. WOLFSSL_LOCAL int HashRaw(WOLFSSL* ssl, const byte* output, int sz);
  1587. WOLFSSL_LOCAL int HashOutput(WOLFSSL* ssl, const byte* output, int sz,
  1588. int ivSz);
  1589. WOLFSSL_LOCAL int HashInput(WOLFSSL* ssl, const byte* input, int sz);
  1590. #ifdef HAVE_SNI
  1591. #ifndef NO_WOLFSSL_SERVER
  1592. WOLFSSL_LOCAL int SNI_Callback(WOLFSSL* ssl);
  1593. #endif
  1594. #endif
  1595. #ifdef WOLFSSL_TLS13
  1596. WOLFSSL_LOCAL int DecryptTls13(WOLFSSL* ssl, byte* output, const byte* input,
  1597. word16 sz, const byte* aad, word16 aadSz);
  1598. WOLFSSL_LOCAL int DoTls13HandShakeMsgType(WOLFSSL* ssl, byte* input,
  1599. word32* inOutIdx, byte type,
  1600. word32 size, word32 totalSz);
  1601. WOLFSSL_LOCAL int DoTls13HandShakeMsg(WOLFSSL* ssl, byte* input,
  1602. word32* inOutIdx, word32 totalSz);
  1603. WOLFSSL_LOCAL int DoTls13ServerHello(WOLFSSL* ssl, const byte* input,
  1604. word32* inOutIdx, word32 helloSz,
  1605. byte* extMsgType);
  1606. WOLFSSL_LOCAL int RestartHandshakeHash(WOLFSSL* ssl);
  1607. #endif
  1608. int TimingPadVerify(WOLFSSL* ssl, const byte* input, int padLen, int t,
  1609. int pLen, int content);
  1610. enum {
  1611. FORCED_FREE = 1,
  1612. NO_FORCED_FREE = 0
  1613. };
  1614. /* only use compression extra if using compression */
  1615. #ifdef HAVE_LIBZ
  1616. #define COMP_EXTRA MAX_COMP_EXTRA
  1617. #else
  1618. #define COMP_EXTRA 0
  1619. #endif
  1620. /* only the sniffer needs space in the buffer for extra MTU record(s) */
  1621. #ifdef WOLFSSL_SNIFFER
  1622. #define MTU_EXTRA MAX_MTU * 3
  1623. #else
  1624. #define MTU_EXTRA 0
  1625. #endif
  1626. /* embedded callbacks require large static buffers, make sure on */
  1627. #ifdef WOLFSSL_CALLBACKS
  1628. #undef LARGE_STATIC_BUFFERS
  1629. #define LARGE_STATIC_BUFFERS
  1630. #endif
  1631. /* give user option to use 16K static buffers */
  1632. #if defined(LARGE_STATIC_BUFFERS)
  1633. #define RECORD_SIZE MAX_RECORD_SIZE
  1634. #else
  1635. #ifdef WOLFSSL_DTLS
  1636. #define RECORD_SIZE MAX_MTU
  1637. #else
  1638. #define RECORD_SIZE 128
  1639. #endif
  1640. #endif
  1641. /* user option to turn off 16K output option */
  1642. /* if using small static buffers (default) and SSL_write tries to write data
  1643. larger than the record we have, dynamically get it, unless user says only
  1644. write in static buffer chunks */
  1645. #ifndef STATIC_CHUNKS_ONLY
  1646. #define OUTPUT_RECORD_SIZE MAX_RECORD_SIZE
  1647. #else
  1648. #define OUTPUT_RECORD_SIZE RECORD_SIZE
  1649. #endif
  1650. /* wolfSSL input buffer
  1651. RFC 2246:
  1652. length
  1653. The length (in bytes) of the following TLSPlaintext.fragment.
  1654. The length should not exceed 2^14.
  1655. */
  1656. #if defined(LARGE_STATIC_BUFFERS)
  1657. #define STATIC_BUFFER_LEN RECORD_HEADER_SZ + RECORD_SIZE + COMP_EXTRA + \
  1658. MTU_EXTRA + MAX_MSG_EXTRA
  1659. #else
  1660. /* don't fragment memory from the record header */
  1661. #define STATIC_BUFFER_LEN RECORD_HEADER_SZ
  1662. #endif
  1663. typedef struct {
  1664. ALIGN16 byte staticBuffer[STATIC_BUFFER_LEN];
  1665. byte* buffer; /* place holder for static or dynamic buffer */
  1666. word32 length; /* total buffer length used */
  1667. word32 idx; /* idx to part of length already consumed */
  1668. word32 bufferSize; /* current buffer size */
  1669. byte dynamicFlag; /* dynamic memory currently in use */
  1670. byte offset; /* alignment offset attempt */
  1671. } bufferStatic;
  1672. /* Cipher Suites holder */
  1673. struct Suites {
  1674. word16 suiteSz; /* suite length in bytes */
  1675. word16 hashSigAlgoSz; /* SigAlgo extension length in bytes */
  1676. byte suites[WOLFSSL_MAX_SUITE_SZ];
  1677. byte hashSigAlgo[WOLFSSL_MAX_SIGALGO]; /* sig/algo to offer */
  1678. byte setSuites; /* user set suites from default */
  1679. byte hashAlgo; /* selected hash algorithm */
  1680. byte sigAlgo; /* selected sig algorithm */
  1681. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
  1682. WOLF_STACK_OF(WOLFSSL_CIPHER)* stack; /* stack of available cipher suites */
  1683. #endif
  1684. };
  1685. WOLFSSL_LOCAL void InitSuitesHashSigAlgo(Suites* suites, int haveECDSAsig,
  1686. int haveRSAsig, int haveAnon,
  1687. int tls1_2, int keySz);
  1688. WOLFSSL_LOCAL void InitSuites(Suites*, ProtocolVersion, int, word16, word16,
  1689. word16, word16, word16, word16, word16, word16, int);
  1690. WOLFSSL_LOCAL int MatchSuite(WOLFSSL* ssl, Suites* peerSuites);
  1691. WOLFSSL_LOCAL int SetCipherList(WOLFSSL_CTX*, Suites*, const char* list);
  1692. #ifndef PSK_TYPES_DEFINED
  1693. typedef unsigned int (*wc_psk_client_callback)(WOLFSSL*, const char*, char*,
  1694. unsigned int, unsigned char*, unsigned int);
  1695. typedef unsigned int (*wc_psk_server_callback)(WOLFSSL*, const char*,
  1696. unsigned char*, unsigned int);
  1697. #ifdef WOLFSSL_TLS13
  1698. typedef unsigned int (*wc_psk_client_tls13_callback)(WOLFSSL*, const char*,
  1699. char*, unsigned int, unsigned char*, unsigned int,
  1700. const char**);
  1701. typedef unsigned int (*wc_psk_server_tls13_callback)(WOLFSSL*, const char*,
  1702. unsigned char*, unsigned int, const char**);
  1703. #endif
  1704. #endif /* PSK_TYPES_DEFINED */
  1705. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  1706. !defined(WOLFSSL_DTLS_EXPORT_TYPES)
  1707. typedef int (*wc_dtls_export)(WOLFSSL* ssl,
  1708. unsigned char* exportBuffer, unsigned int sz, void* userCtx);
  1709. #define WOLFSSL_DTLS_EXPORT_TYPES
  1710. #endif /* WOLFSSL_DTLS_EXPORT_TYPES */
  1711. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  1712. #define MAX_DESCRIPTION_SZ 255
  1713. #endif
  1714. struct WOLFSSL_CIPHER {
  1715. byte cipherSuite0;
  1716. byte cipherSuite;
  1717. const WOLFSSL* ssl;
  1718. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  1719. char description[MAX_DESCRIPTION_SZ];
  1720. unsigned long offset;
  1721. unsigned int in_stack; /* TRUE if added to stack in wolfSSL_get_ciphers_compat */
  1722. int bits;
  1723. #endif
  1724. };
  1725. #ifdef NO_ASN
  1726. /* no_asn won't have */
  1727. typedef struct CertStatus CertStatus;
  1728. #endif
  1729. #ifndef HAVE_OCSP
  1730. typedef struct WOLFSSL_OCSP WOLFSSL_OCSP;
  1731. #endif
  1732. /* wolfSSL OCSP controller */
  1733. #ifdef HAVE_OCSP
  1734. struct WOLFSSL_OCSP {
  1735. WOLFSSL_CERT_MANAGER* cm; /* pointer back to cert manager */
  1736. OcspEntry* ocspList; /* OCSP response list */
  1737. wolfSSL_Mutex ocspLock; /* OCSP list lock */
  1738. int error;
  1739. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
  1740. defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
  1741. int(*statusCb)(WOLFSSL*, void*);
  1742. #endif
  1743. };
  1744. #endif
  1745. #ifndef MAX_DATE_SIZE
  1746. #define MAX_DATE_SIZE 32
  1747. #endif
  1748. typedef struct CRL_Entry CRL_Entry;
  1749. #ifdef NO_SHA
  1750. #define CRL_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
  1751. #else
  1752. #define CRL_DIGEST_SIZE WC_SHA_DIGEST_SIZE
  1753. #endif
  1754. #ifdef NO_ASN
  1755. typedef struct RevokedCert RevokedCert;
  1756. #endif
  1757. /* Complete CRL */
  1758. struct CRL_Entry {
  1759. CRL_Entry* next; /* next entry */
  1760. byte issuerHash[CRL_DIGEST_SIZE]; /* issuer hash */
  1761. /* byte crlHash[CRL_DIGEST_SIZE]; raw crl data hash */
  1762. /* restore the hash here if needed for optimized comparisons */
  1763. byte lastDate[MAX_DATE_SIZE]; /* last date updated */
  1764. byte nextDate[MAX_DATE_SIZE]; /* next update date */
  1765. byte lastDateFormat; /* last date format */
  1766. byte nextDateFormat; /* next date format */
  1767. RevokedCert* certs; /* revoked cert list */
  1768. int totalCerts; /* number on list */
  1769. int verified;
  1770. byte* toBeSigned;
  1771. word32 tbsSz;
  1772. byte* signature;
  1773. word32 signatureSz;
  1774. word32 signatureOID;
  1775. #if !defined(NO_SKID) && !defined(NO_ASN)
  1776. byte extAuthKeyIdSet;
  1777. byte extAuthKeyId[KEYID_SIZE];
  1778. #endif
  1779. };
  1780. typedef struct CRL_Monitor CRL_Monitor;
  1781. /* CRL directory monitor */
  1782. struct CRL_Monitor {
  1783. char* path; /* full dir path, if valid pointer we're using */
  1784. int type; /* PEM or ASN1 type */
  1785. };
  1786. #if defined(HAVE_CRL) && defined(NO_FILESYSTEM)
  1787. #undef HAVE_CRL_MONITOR
  1788. #endif
  1789. /* wolfSSL CRL controller */
  1790. struct WOLFSSL_CRL {
  1791. WOLFSSL_CERT_MANAGER* cm; /* pointer back to cert manager */
  1792. CRL_Entry* crlList; /* our CRL list */
  1793. #ifdef HAVE_CRL_IO
  1794. CbCrlIO crlIOCb;
  1795. #endif
  1796. wolfSSL_Mutex crlLock; /* CRL list lock */
  1797. CRL_Monitor monitors[2]; /* PEM and DER possible */
  1798. #ifdef HAVE_CRL_MONITOR
  1799. pthread_cond_t cond; /* condition to signal setup */
  1800. pthread_t tid; /* monitoring thread */
  1801. int mfd; /* monitor fd, -1 if no init yet */
  1802. int setup; /* thread is setup predicate */
  1803. #endif
  1804. void* heap; /* heap hint for dynamic memory */
  1805. };
  1806. #ifdef NO_ASN
  1807. typedef struct Signer Signer;
  1808. #ifdef WOLFSSL_TRUST_PEER_CERT
  1809. typedef struct TrustedPeerCert TrustedPeerCert;
  1810. #endif
  1811. #endif
  1812. #ifndef CA_TABLE_SIZE
  1813. #define CA_TABLE_SIZE 11
  1814. #endif
  1815. #ifdef WOLFSSL_TRUST_PEER_CERT
  1816. #define TP_TABLE_SIZE 11
  1817. #endif
  1818. /* wolfSSL Certificate Manager */
  1819. struct WOLFSSL_CERT_MANAGER {
  1820. Signer* caTable[CA_TABLE_SIZE]; /* the CA signer table */
  1821. void* heap; /* heap helper */
  1822. #ifdef WOLFSSL_TRUST_PEER_CERT
  1823. TrustedPeerCert* tpTable[TP_TABLE_SIZE]; /* table of trusted peer certs */
  1824. wolfSSL_Mutex tpLock; /* trusted peer list lock */
  1825. #endif
  1826. WOLFSSL_CRL* crl; /* CRL checker */
  1827. WOLFSSL_OCSP* ocsp; /* OCSP checker */
  1828. #if !defined(NO_WOLFSSL_SERVER) && (defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  1829. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2))
  1830. WOLFSSL_OCSP* ocsp_stapling; /* OCSP checker for OCSP stapling */
  1831. #endif
  1832. char* ocspOverrideURL; /* use this responder */
  1833. void* ocspIOCtx; /* I/O callback CTX */
  1834. #ifndef NO_WOLFSSL_CM_VERIFY
  1835. VerifyCallback verifyCallback; /* Verify callback */
  1836. #endif
  1837. CallbackCACache caCacheCallback; /* CA cache addition callback */
  1838. CbMissingCRL cbMissingCRL; /* notify thru cb of missing crl */
  1839. CbOCSPIO ocspIOCb; /* I/O callback for OCSP lookup */
  1840. CbOCSPRespFree ocspRespFreeCb; /* Frees OCSP Response from IO Cb */
  1841. wolfSSL_Mutex caLock; /* CA list lock */
  1842. byte crlEnabled:1; /* is CRL on ? */
  1843. byte crlCheckAll:1; /* always leaf, but all ? */
  1844. byte ocspEnabled:1; /* is OCSP on ? */
  1845. byte ocspCheckAll:1; /* always leaf, but all ? */
  1846. byte ocspSendNonce:1; /* send the OCSP nonce ? */
  1847. byte ocspUseOverrideURL:1; /* ignore cert responder, override */
  1848. byte ocspStaplingEnabled:1; /* is OCSP Stapling on ? */
  1849. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  1850. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  1851. byte ocspMustStaple:1; /* server must respond with staple */
  1852. #endif
  1853. #ifndef NO_RSA
  1854. short minRsaKeySz; /* minimum allowed RSA key size */
  1855. #endif
  1856. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
  1857. short minEccKeySz; /* minimum allowed ECC key size */
  1858. #endif
  1859. #if defined(OPENSSL_EXTRA)
  1860. WOLFSSL_X509_STORE *x509_store_p; /* a pointer back to CTX x509 store */
  1861. /* CTX has ownership and free this */
  1862. /* with CTX free. */
  1863. #endif
  1864. wolfSSL_Mutex refMutex; /* reference count mutex */
  1865. int refCount; /* reference count */
  1866. };
  1867. WOLFSSL_LOCAL int CM_SaveCertCache(WOLFSSL_CERT_MANAGER*, const char*);
  1868. WOLFSSL_LOCAL int CM_RestoreCertCache(WOLFSSL_CERT_MANAGER*, const char*);
  1869. WOLFSSL_LOCAL int CM_MemSaveCertCache(WOLFSSL_CERT_MANAGER*, void*, int, int*);
  1870. WOLFSSL_LOCAL int CM_MemRestoreCertCache(WOLFSSL_CERT_MANAGER*, const void*, int);
  1871. WOLFSSL_LOCAL int CM_GetCertCacheMemSize(WOLFSSL_CERT_MANAGER*);
  1872. WOLFSSL_LOCAL int CM_VerifyBuffer_ex(WOLFSSL_CERT_MANAGER* cm, const byte* buff,
  1873. long sz, int format, int err_val);
  1874. #ifndef NO_CERTS
  1875. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  1876. typedef struct ProcPeerCertArgs {
  1877. buffer* certs;
  1878. #ifdef WOLFSSL_TLS13
  1879. buffer* exts; /* extensions */
  1880. #endif
  1881. DecodedCert* dCert;
  1882. word32 idx;
  1883. word32 begin;
  1884. int totalCerts; /* number of certs in certs buffer */
  1885. int count;
  1886. int certIdx;
  1887. int lastErr;
  1888. #ifdef WOLFSSL_TLS13
  1889. byte ctxSz;
  1890. #endif
  1891. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  1892. char untrustedDepth;
  1893. #endif
  1894. word16 fatal:1;
  1895. word16 verifyErr:1;
  1896. word16 dCertInit:1;
  1897. #ifdef WOLFSSL_TRUST_PEER_CERT
  1898. word16 haveTrustPeer:1; /* was cert verified by loaded trusted peer cert */
  1899. #endif
  1900. } ProcPeerCertArgs;
  1901. WOLFSSL_LOCAL int DoVerifyCallback(WOLFSSL_CERT_MANAGER* cm, WOLFSSL* ssl,
  1902. int ret, ProcPeerCertArgs* args);
  1903. #endif /* !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH) */
  1904. #endif /* !defined NO_CERTS */
  1905. /* wolfSSL Sock Addr */
  1906. struct WOLFSSL_SOCKADDR {
  1907. unsigned int sz; /* sockaddr size */
  1908. void* sa; /* pointer to the sockaddr_in or sockaddr_in6 */
  1909. };
  1910. typedef struct WOLFSSL_DTLS_CTX {
  1911. WOLFSSL_SOCKADDR peer;
  1912. int rfd;
  1913. int wfd;
  1914. } WOLFSSL_DTLS_CTX;
  1915. typedef struct WOLFSSL_DTLS_PEERSEQ {
  1916. word32 window[WOLFSSL_DTLS_WINDOW_WORDS];
  1917. /* Sliding window for current epoch */
  1918. word16 nextEpoch; /* Expected epoch in next record */
  1919. word16 nextSeq_hi; /* Expected sequence in next record */
  1920. word32 nextSeq_lo;
  1921. word32 prevWindow[WOLFSSL_DTLS_WINDOW_WORDS];
  1922. /* Sliding window for old epoch */
  1923. word32 prevSeq_lo;
  1924. word16 prevSeq_hi; /* Next sequence in allowed old epoch */
  1925. #ifdef WOLFSSL_MULTICAST
  1926. word16 peerId;
  1927. word32 highwaterMark;
  1928. #endif
  1929. } WOLFSSL_DTLS_PEERSEQ;
  1930. #define MAX_WRITE_IV_SZ 16 /* max size of client/server write_IV */
  1931. /* keys and secrets
  1932. * keep as a constant size (no additional ifdefs) for session export */
  1933. typedef struct Keys {
  1934. #if !defined(WOLFSSL_AEAD_ONLY) || defined(WOLFSSL_TLS13)
  1935. byte client_write_MAC_secret[WC_MAX_DIGEST_SIZE]; /* max sizes */
  1936. byte server_write_MAC_secret[WC_MAX_DIGEST_SIZE];
  1937. #endif
  1938. byte client_write_key[MAX_SYM_KEY_SIZE]; /* max sizes */
  1939. byte server_write_key[MAX_SYM_KEY_SIZE];
  1940. byte client_write_IV[MAX_WRITE_IV_SZ]; /* max sizes */
  1941. byte server_write_IV[MAX_WRITE_IV_SZ];
  1942. #if defined(HAVE_AEAD) || defined(WOLFSSL_SESSION_EXPORT)
  1943. byte aead_exp_IV[AEAD_MAX_EXP_SZ];
  1944. byte aead_enc_imp_IV[AEAD_MAX_IMP_SZ];
  1945. byte aead_dec_imp_IV[AEAD_MAX_IMP_SZ];
  1946. #endif
  1947. word32 peer_sequence_number_hi;
  1948. word32 peer_sequence_number_lo;
  1949. word32 sequence_number_hi;
  1950. word32 sequence_number_lo;
  1951. #ifdef WOLFSSL_DTLS
  1952. word16 curEpoch; /* Received epoch in current record */
  1953. word16 curSeq_hi; /* Received sequence in current record */
  1954. word32 curSeq_lo;
  1955. #ifdef WOLFSSL_MULTICAST
  1956. byte curPeerId; /* Received peer group ID in current record */
  1957. #endif
  1958. WOLFSSL_DTLS_PEERSEQ peerSeq[WOLFSSL_DTLS_PEERSEQ_SZ];
  1959. word16 dtls_peer_handshake_number;
  1960. word16 dtls_expected_peer_handshake_number;
  1961. word16 dtls_epoch; /* Current epoch */
  1962. word16 dtls_sequence_number_hi; /* Current epoch */
  1963. word32 dtls_sequence_number_lo;
  1964. word16 dtls_prev_sequence_number_hi; /* Previous epoch */
  1965. word32 dtls_prev_sequence_number_lo;
  1966. word16 dtls_handshake_number; /* Current tx handshake seq */
  1967. #endif
  1968. word32 encryptSz; /* last size of encrypted data */
  1969. word32 padSz; /* how much to advance after decrypt part */
  1970. byte encryptionOn; /* true after change cipher spec */
  1971. byte decryptedCur; /* only decrypt current record once */
  1972. #ifdef WOLFSSL_TLS13
  1973. byte updateResponseReq:1; /* KeyUpdate response from peer required. */
  1974. byte keyUpdateRespond:1; /* KeyUpdate is to be responded to. */
  1975. #endif
  1976. #ifdef WOLFSSL_RENESAS_TSIP_TLS
  1977. tsip_hmac_sha_key_index_t tsip_client_write_MAC_secret;
  1978. tsip_hmac_sha_key_index_t tsip_server_write_MAC_secret;
  1979. #endif
  1980. } Keys;
  1981. /** TLS Extensions - RFC 6066 */
  1982. #ifdef HAVE_TLS_EXTENSIONS
  1983. typedef enum {
  1984. #ifdef HAVE_SNI
  1985. TLSX_SERVER_NAME = 0x0000, /* a.k.a. SNI */
  1986. #endif
  1987. TLSX_MAX_FRAGMENT_LENGTH = 0x0001,
  1988. TLSX_TRUSTED_CA_KEYS = 0x0003,
  1989. TLSX_TRUNCATED_HMAC = 0x0004,
  1990. TLSX_STATUS_REQUEST = 0x0005, /* a.k.a. OCSP stapling */
  1991. TLSX_SUPPORTED_GROUPS = 0x000a, /* a.k.a. Supported Curves */
  1992. TLSX_EC_POINT_FORMATS = 0x000b,
  1993. #if !defined(NO_CERTS) && !defined(WOLFSSL_NO_SIGALG)
  1994. TLSX_SIGNATURE_ALGORITHMS = 0x000d, /* HELLO_EXT_SIG_ALGO */
  1995. #endif
  1996. TLSX_APPLICATION_LAYER_PROTOCOL = 0x0010, /* a.k.a. ALPN */
  1997. TLSX_STATUS_REQUEST_V2 = 0x0011, /* a.k.a. OCSP stapling v2 */
  1998. #if defined(HAVE_ENCRYPT_THEN_MAC) && !defined(WOLFSSL_AEAD_ONLY)
  1999. TLSX_ENCRYPT_THEN_MAC = 0x0016, /* RFC 7366 */
  2000. #endif
  2001. TLSX_EXTENDED_MASTER_SECRET = 0x0017, /* HELLO_EXT_EXTMS */
  2002. TLSX_QUANTUM_SAFE_HYBRID = 0x0018, /* a.k.a. QSH */
  2003. TLSX_SESSION_TICKET = 0x0023,
  2004. #ifdef WOLFSSL_TLS13
  2005. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  2006. TLSX_PRE_SHARED_KEY = 0x0029,
  2007. #endif
  2008. #ifdef WOLFSSL_EARLY_DATA
  2009. TLSX_EARLY_DATA = 0x002a,
  2010. #endif
  2011. TLSX_SUPPORTED_VERSIONS = 0x002b,
  2012. #ifdef WOLFSSL_SEND_HRR_COOKIE
  2013. TLSX_COOKIE = 0x002c,
  2014. #endif
  2015. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  2016. TLSX_PSK_KEY_EXCHANGE_MODES = 0x002d,
  2017. #endif
  2018. #ifdef WOLFSSL_POST_HANDSHAKE_AUTH
  2019. TLSX_POST_HANDSHAKE_AUTH = 0x0031,
  2020. #endif
  2021. #if !defined(NO_CERTS) && !defined(WOLFSSL_NO_SIGALG)
  2022. TLSX_SIGNATURE_ALGORITHMS_CERT = 0x0032,
  2023. #endif
  2024. TLSX_KEY_SHARE = 0x0033,
  2025. #endif
  2026. TLSX_RENEGOTIATION_INFO = 0xff01
  2027. } TLSX_Type;
  2028. typedef struct TLSX {
  2029. TLSX_Type type; /* Extension Type */
  2030. void* data; /* Extension Data */
  2031. word32 val; /* Extension Value */
  2032. byte resp; /* IsResponse Flag */
  2033. struct TLSX* next; /* List Behavior */
  2034. } TLSX;
  2035. WOLFSSL_LOCAL TLSX* TLSX_Find(TLSX* list, TLSX_Type type);
  2036. WOLFSSL_LOCAL void TLSX_Remove(TLSX** list, TLSX_Type type, void* heap);
  2037. WOLFSSL_LOCAL void TLSX_FreeAll(TLSX* list, void* heap);
  2038. WOLFSSL_LOCAL int TLSX_SupportExtensions(WOLFSSL* ssl);
  2039. WOLFSSL_LOCAL int TLSX_PopulateExtensions(WOLFSSL* ssl, byte isRequest);
  2040. #if defined(WOLFSSL_TLS13) || !defined(NO_WOLFSSL_CLIENT)
  2041. WOLFSSL_LOCAL int TLSX_GetRequestSize(WOLFSSL* ssl, byte msgType,
  2042. word16* pLength);
  2043. WOLFSSL_LOCAL int TLSX_WriteRequest(WOLFSSL* ssl, byte* output,
  2044. byte msgType, word16* pOffset);
  2045. #endif
  2046. #if defined(WOLFSSL_TLS13) || !defined(NO_WOLFSSL_SERVER)
  2047. /* TLS 1.3 Certificate messages have extensions. */
  2048. WOLFSSL_LOCAL int TLSX_GetResponseSize(WOLFSSL* ssl, byte msgType,
  2049. word16* pLength);
  2050. WOLFSSL_LOCAL int TLSX_WriteResponse(WOLFSSL *ssl, byte* output, byte msgType,
  2051. word16* pOffset);
  2052. #endif
  2053. WOLFSSL_LOCAL int TLSX_ParseVersion(WOLFSSL* ssl, const byte* input,
  2054. word16 length, byte msgType, int* found);
  2055. WOLFSSL_LOCAL int TLSX_Parse(WOLFSSL* ssl, const byte* input, word16 length,
  2056. byte msgType, Suites *suites);
  2057. #elif defined(HAVE_SNI) \
  2058. || defined(HAVE_MAX_FRAGMENT) \
  2059. || defined(HAVE_TRUSTED_CA) \
  2060. || defined(HAVE_TRUNCATED_HMAC) \
  2061. || defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  2062. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) \
  2063. || defined(HAVE_SUPPORTED_CURVES) \
  2064. || defined(HAVE_ALPN) \
  2065. || defined(HAVE_QSH) \
  2066. || defined(HAVE_SESSION_TICKET) \
  2067. || defined(HAVE_SECURE_RENEGOTIATION) \
  2068. || defined(HAVE_SERVER_RENEGOTIATION_INFO)
  2069. #error Using TLS extensions requires HAVE_TLS_EXTENSIONS to be defined.
  2070. #endif /* HAVE_TLS_EXTENSIONS */
  2071. /** Server Name Indication - RFC 6066 (session 3) */
  2072. #ifdef HAVE_SNI
  2073. typedef struct SNI {
  2074. byte type; /* SNI Type */
  2075. union { char* host_name; } data; /* SNI Data */
  2076. struct SNI* next; /* List Behavior */
  2077. byte status; /* Matching result */
  2078. #ifndef NO_WOLFSSL_SERVER
  2079. byte options; /* Behavior options */
  2080. #endif
  2081. } SNI;
  2082. WOLFSSL_LOCAL int TLSX_UseSNI(TLSX** extensions, byte type, const void* data,
  2083. word16 size, void* heap);
  2084. WOLFSSL_LOCAL byte TLSX_SNI_Status(TLSX* extensions, byte type);
  2085. WOLFSSL_LOCAL word16 TLSX_SNI_GetRequest(TLSX* extensions, byte type,
  2086. void** data);
  2087. #ifndef NO_WOLFSSL_SERVER
  2088. WOLFSSL_LOCAL void TLSX_SNI_SetOptions(TLSX* extensions, byte type,
  2089. byte options);
  2090. WOLFSSL_LOCAL int TLSX_SNI_GetFromBuffer(const byte* buffer, word32 bufferSz,
  2091. byte type, byte* sni, word32* inOutSz);
  2092. #endif
  2093. #endif /* HAVE_SNI */
  2094. /* Trusted CA Key Indication - RFC 6066 (section 6) */
  2095. #ifdef HAVE_TRUSTED_CA
  2096. typedef struct TCA {
  2097. byte type; /* TCA Type */
  2098. byte* id; /* TCA identifier */
  2099. word16 idSz; /* TCA identifier size */
  2100. struct TCA* next; /* List Behavior */
  2101. } TCA;
  2102. WOLFSSL_LOCAL int TLSX_UseTrustedCA(TLSX** extensions, byte type,
  2103. const byte* id, word16 idSz, void* heap);
  2104. #endif /* HAVE_TRUSTED_CA */
  2105. /* Application-Layer Protocol Negotiation - RFC 7301 */
  2106. #ifdef HAVE_ALPN
  2107. typedef struct ALPN {
  2108. char* protocol_name; /* ALPN protocol name */
  2109. struct ALPN* next; /* List Behavior */
  2110. byte options; /* Behavior options */
  2111. byte negotiated; /* ALPN protocol negotiated or not */
  2112. } ALPN;
  2113. WOLFSSL_LOCAL int TLSX_ALPN_GetRequest(TLSX* extensions,
  2114. void** data, word16 *dataSz);
  2115. WOLFSSL_LOCAL int TLSX_UseALPN(TLSX** extensions, const void* data,
  2116. word16 size, byte options, void* heap);
  2117. WOLFSSL_LOCAL int TLSX_ALPN_SetOptions(TLSX** extensions, const byte option);
  2118. #endif /* HAVE_ALPN */
  2119. /** Maximum Fragment Length Negotiation - RFC 6066 (session 4) */
  2120. #ifdef HAVE_MAX_FRAGMENT
  2121. WOLFSSL_LOCAL int TLSX_UseMaxFragment(TLSX** extensions, byte mfl, void* heap);
  2122. #endif /* HAVE_MAX_FRAGMENT */
  2123. /** Truncated HMAC - RFC 6066 (session 7) */
  2124. #ifdef HAVE_TRUNCATED_HMAC
  2125. WOLFSSL_LOCAL int TLSX_UseTruncatedHMAC(TLSX** extensions, void* heap);
  2126. #endif /* HAVE_TRUNCATED_HMAC */
  2127. /** Certificate Status Request - RFC 6066 (session 8) */
  2128. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  2129. typedef struct {
  2130. byte status_type;
  2131. byte options;
  2132. WOLFSSL* ssl;
  2133. union {
  2134. OcspRequest ocsp;
  2135. } request;
  2136. #if defined(WOLFSSL_TLS13)
  2137. buffer response;
  2138. #endif
  2139. } CertificateStatusRequest;
  2140. WOLFSSL_LOCAL int TLSX_UseCertificateStatusRequest(TLSX** extensions,
  2141. byte status_type, byte options, WOLFSSL* ssl, void* heap, int devId);
  2142. #ifndef NO_CERTS
  2143. WOLFSSL_LOCAL int TLSX_CSR_InitRequest(TLSX* extensions, DecodedCert* cert,
  2144. void* heap);
  2145. #endif
  2146. WOLFSSL_LOCAL void* TLSX_CSR_GetRequest(TLSX* extensions);
  2147. WOLFSSL_LOCAL int TLSX_CSR_ForceRequest(WOLFSSL* ssl);
  2148. #endif
  2149. /** Certificate Status Request v2 - RFC 6961 */
  2150. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  2151. typedef struct CSRIv2 {
  2152. byte status_type;
  2153. byte options;
  2154. word16 requests;
  2155. union {
  2156. OcspRequest ocsp[1 + MAX_CHAIN_DEPTH];
  2157. } request;
  2158. struct CSRIv2* next;
  2159. } CertificateStatusRequestItemV2;
  2160. WOLFSSL_LOCAL int TLSX_UseCertificateStatusRequestV2(TLSX** extensions,
  2161. byte status_type, byte options, void* heap, int devId);
  2162. #ifndef NO_CERTS
  2163. WOLFSSL_LOCAL int TLSX_CSR2_InitRequests(TLSX* extensions, DecodedCert* cert,
  2164. byte isPeer, void* heap);
  2165. #endif
  2166. WOLFSSL_LOCAL void* TLSX_CSR2_GetRequest(TLSX* extensions, byte status_type,
  2167. byte index);
  2168. WOLFSSL_LOCAL int TLSX_CSR2_ForceRequest(WOLFSSL* ssl);
  2169. #endif
  2170. /** Supported Elliptic Curves - RFC 4492 (session 4) */
  2171. #ifdef HAVE_SUPPORTED_CURVES
  2172. typedef struct SupportedCurve {
  2173. word16 name; /* Curve Names */
  2174. struct SupportedCurve* next; /* List Behavior */
  2175. } SupportedCurve;
  2176. typedef struct PointFormat {
  2177. byte format; /* PointFormat */
  2178. struct PointFormat* next; /* List Behavior */
  2179. } PointFormat;
  2180. WOLFSSL_LOCAL int TLSX_UseSupportedCurve(TLSX** extensions, word16 name,
  2181. void* heap);
  2182. WOLFSSL_LOCAL int TLSX_UsePointFormat(TLSX** extensions, byte point,
  2183. void* heap);
  2184. #ifndef NO_WOLFSSL_SERVER
  2185. WOLFSSL_LOCAL int TLSX_ValidateSupportedCurves(WOLFSSL* ssl, byte first,
  2186. byte second);
  2187. WOLFSSL_LOCAL int TLSX_SupportedCurve_CheckPriority(WOLFSSL* ssl);
  2188. WOLFSSL_LOCAL int TLSX_SupportedFFDHE_Set(WOLFSSL* ssl);
  2189. #endif
  2190. WOLFSSL_LOCAL int TLSX_SupportedCurve_Preferred(WOLFSSL* ssl,
  2191. int checkSupported);
  2192. #endif /* HAVE_SUPPORTED_CURVES */
  2193. /** Renegotiation Indication - RFC 5746 */
  2194. #if defined(HAVE_SECURE_RENEGOTIATION) \
  2195. || defined(HAVE_SERVER_RENEGOTIATION_INFO)
  2196. enum key_cache_state {
  2197. SCR_CACHE_NULL = 0, /* empty / begin state */
  2198. SCR_CACHE_NEEDED, /* need to cache keys */
  2199. SCR_CACHE_COPY, /* we have a cached copy */
  2200. SCR_CACHE_PARTIAL, /* partial restore to real keys */
  2201. SCR_CACHE_COMPLETE /* complete restore to real keys */
  2202. };
  2203. /* Additional Connection State according to rfc5746 section 3.1 */
  2204. typedef struct SecureRenegotiation {
  2205. byte enabled; /* secure_renegotiation flag in rfc */
  2206. byte verifySet;
  2207. byte startScr; /* server requested client to start scr */
  2208. enum key_cache_state cache_status; /* track key cache state */
  2209. byte client_verify_data[TLS_FINISHED_SZ]; /* cached */
  2210. byte server_verify_data[TLS_FINISHED_SZ]; /* cached */
  2211. byte subject_hash_set; /* if peer cert hash is set */
  2212. byte subject_hash[KEYID_SIZE]; /* peer cert hash */
  2213. Keys tmp_keys; /* can't overwrite real keys yet */
  2214. } SecureRenegotiation;
  2215. WOLFSSL_LOCAL int TLSX_UseSecureRenegotiation(TLSX** extensions, void* heap);
  2216. #ifdef HAVE_SERVER_RENEGOTIATION_INFO
  2217. WOLFSSL_LOCAL int TLSX_AddEmptyRenegotiationInfo(TLSX** extensions, void* heap);
  2218. #endif
  2219. #endif /* HAVE_SECURE_RENEGOTIATION */
  2220. /** Session Ticket - RFC 5077 (session 3.2) */
  2221. #ifdef HAVE_SESSION_TICKET
  2222. typedef struct SessionTicket {
  2223. word32 lifetime;
  2224. #ifdef WOLFSSL_TLS13
  2225. word64 seen;
  2226. word32 ageAdd;
  2227. #endif
  2228. byte* data;
  2229. word16 size;
  2230. } SessionTicket;
  2231. #if !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(WOLFSSL_NO_SERVER)
  2232. /* Data passed to default SessionTicket enc/dec callback. */
  2233. typedef struct TicketEncCbCtx {
  2234. /* Name for this context. */
  2235. byte name[WOLFSSL_TICKET_NAME_SZ];
  2236. /* Current keys - current and next. */
  2237. byte key[2][WOLFSSL_TICKET_KEY_SZ];
  2238. /* Expirary date of keys. */
  2239. word32 expirary[2];
  2240. /* Random number generator to use for generating name, keys and IV. */
  2241. WC_RNG rng;
  2242. #ifndef SINGLE_THREADED
  2243. /* Mutex for access to changing keys. */
  2244. wolfSSL_Mutex mutex;
  2245. #endif
  2246. /* Pointer back to SSL_CTX. */
  2247. WOLFSSL_CTX* ctx;
  2248. } TicketEncCbCtx;
  2249. #endif /* !WOLFSSL_NO_DEF_TICKET_ENC_CB && !WOLFSSL_NO_SERVER */
  2250. WOLFSSL_LOCAL int TLSX_UseSessionTicket(TLSX** extensions,
  2251. SessionTicket* ticket, void* heap);
  2252. WOLFSSL_LOCAL SessionTicket* TLSX_SessionTicket_Create(word32 lifetime,
  2253. byte* data, word16 size, void* heap);
  2254. WOLFSSL_LOCAL void TLSX_SessionTicket_Free(SessionTicket* ticket, void* heap);
  2255. #endif /* HAVE_SESSION_TICKET */
  2256. /** Quantum-Safe-Hybrid - draft-whyte-qsh-tls12-00 */
  2257. #ifdef HAVE_QSH
  2258. typedef struct QSHScheme {
  2259. struct QSHScheme* next; /* List Behavior */
  2260. byte* PK;
  2261. word16 name; /* QSHScheme Names */
  2262. word16 PKLen;
  2263. } QSHScheme;
  2264. typedef struct QSHkey {
  2265. struct QSHKey* next;
  2266. word16 name;
  2267. buffer pub;
  2268. buffer pri;
  2269. } QSHKey;
  2270. typedef struct QSHSecret {
  2271. QSHScheme* list;
  2272. buffer* SerSi;
  2273. buffer* CliSi;
  2274. } QSHSecret;
  2275. /* used in key exchange during handshake */
  2276. WOLFSSL_LOCAL int TLSX_QSHCipher_Parse(WOLFSSL* ssl, const byte* input,
  2277. word16 length, byte isServer);
  2278. WOLFSSL_LOCAL word16 TLSX_QSHPK_Write(QSHScheme* list, byte* output);
  2279. WOLFSSL_LOCAL word16 TLSX_QSH_GetSize(QSHScheme* list, byte isRequest);
  2280. /* used by api for setting a specific QSH scheme */
  2281. WOLFSSL_LOCAL int TLSX_UseQSHScheme(TLSX** extensions, word16 name,
  2282. byte* pKey, word16 pKeySz, void* heap);
  2283. /* used when parsing in QSHCipher structs */
  2284. WOLFSSL_LOCAL int QSH_Decrypt(QSHKey* key, byte* in, word32 szIn,
  2285. byte* out, word16* szOut);
  2286. #ifndef NO_WOLFSSL_SERVER
  2287. WOLFSSL_LOCAL int TLSX_ValidateQSHScheme(TLSX** extensions, word16 name);
  2288. #endif
  2289. #endif /* HAVE_QSH */
  2290. #ifdef WOLFSSL_TLS13
  2291. /* Cookie extension information - cookie data. */
  2292. typedef struct Cookie {
  2293. word16 len;
  2294. byte data;
  2295. } Cookie;
  2296. WOLFSSL_LOCAL int TLSX_Cookie_Use(WOLFSSL* ssl, const byte* data, word16 len,
  2297. byte* mac, byte macSz, int resp);
  2298. /* Key Share - TLS v1.3 Specification */
  2299. /* The KeyShare extension information - entry in a linked list. */
  2300. typedef struct KeyShareEntry {
  2301. word16 group; /* NamedGroup */
  2302. byte* ke; /* Key exchange data */
  2303. word32 keLen; /* Key exchange data length */
  2304. void* key; /* Private key */
  2305. word32 keyLen; /* Private key length */
  2306. byte* pubKey; /* Public key */
  2307. word32 pubKeyLen; /* Public key length */
  2308. struct KeyShareEntry* next; /* List pointer */
  2309. } KeyShareEntry;
  2310. WOLFSSL_LOCAL int TLSX_KeyShare_Use(WOLFSSL* ssl, word16 group, word16 len,
  2311. byte* data, KeyShareEntry **kse);
  2312. WOLFSSL_LOCAL int TLSX_KeyShare_Empty(WOLFSSL* ssl);
  2313. WOLFSSL_LOCAL int TLSX_KeyShare_Establish(WOLFSSL* ssl);
  2314. WOLFSSL_LOCAL int TLSX_KeyShare_DeriveSecret(WOLFSSL* ssl);
  2315. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  2316. /* Ticket nonce - for deriving PSK.
  2317. * Length allowed to be: 1..255. Only support 4 bytes.
  2318. */
  2319. typedef struct TicketNonce {
  2320. byte len;
  2321. byte data[MAX_TICKET_NONCE_SZ];
  2322. } TicketNonce;
  2323. /* The PreSharedKey extension information - entry in a linked list. */
  2324. typedef struct PreSharedKey {
  2325. word16 identityLen; /* Length of identity */
  2326. byte* identity; /* PSK identity */
  2327. word32 ticketAge; /* Age of the ticket */
  2328. byte cipherSuite0; /* Cipher Suite */
  2329. byte cipherSuite; /* Cipher Suite */
  2330. word32 binderLen; /* Length of HMAC */
  2331. byte binder[WC_MAX_DIGEST_SIZE]; /* HMAC of handshake */
  2332. byte hmac; /* HMAC algorithm */
  2333. byte resumption:1; /* Resumption PSK */
  2334. byte chosen:1; /* Server's choice */
  2335. struct PreSharedKey* next; /* List pointer */
  2336. } PreSharedKey;
  2337. WOLFSSL_LOCAL int TLSX_PreSharedKey_WriteBinders(PreSharedKey* list,
  2338. byte* output, byte msgType,
  2339. word16* pSz);
  2340. WOLFSSL_LOCAL int TLSX_PreSharedKey_GetSizeBinders(PreSharedKey* list,
  2341. byte msgType, word16* pSz);
  2342. WOLFSSL_LOCAL int TLSX_PreSharedKey_Use(WOLFSSL* ssl, const byte* identity,
  2343. word16 len, word32 age, byte hmac,
  2344. byte cipherSuite0, byte cipherSuite,
  2345. byte resumption,
  2346. PreSharedKey **preSharedKey);
  2347. /* The possible Pre-Shared Key key exchange modes. */
  2348. enum PskKeyExchangeMode {
  2349. PSK_KE,
  2350. PSK_DHE_KE
  2351. };
  2352. /* User can define this. */
  2353. #ifndef WOLFSSL_DEF_PSK_CIPHER
  2354. #define WOLFSSL_DEF_PSK_CIPHER TLS_AES_128_GCM_SHA256
  2355. #endif
  2356. WOLFSSL_LOCAL int TLSX_PskKeModes_Use(WOLFSSL* ssl, byte modes);
  2357. #ifdef WOLFSSL_EARLY_DATA
  2358. WOLFSSL_LOCAL int TLSX_EarlyData_Use(WOLFSSL* ssl, word32 max);
  2359. #endif
  2360. #endif /* HAVE_SESSION_TICKET || !NO_PSK */
  2361. /* The types of keys to derive for. */
  2362. enum DeriveKeyType {
  2363. no_key,
  2364. early_data_key,
  2365. handshake_key,
  2366. traffic_key,
  2367. update_traffic_key
  2368. };
  2369. WOLFSSL_LOCAL int DeriveEarlySecret(WOLFSSL* ssl);
  2370. WOLFSSL_LOCAL int DeriveHandshakeSecret(WOLFSSL* ssl);
  2371. WOLFSSL_LOCAL int DeriveTls13Keys(WOLFSSL* ssl, int secret, int side, int store);
  2372. WOLFSSL_LOCAL int DeriveMasterSecret(WOLFSSL* ssl);
  2373. WOLFSSL_LOCAL int DeriveResumptionPSK(WOLFSSL* ssl, byte* nonce, byte nonceLen, byte* secret);
  2374. WOLFSSL_LOCAL int DeriveResumptionSecret(WOLFSSL* ssl, byte* key);
  2375. WOLFSSL_LOCAL int Tls13_Exporter(WOLFSSL* ssl, unsigned char *out, size_t outLen,
  2376. const char *label, size_t labelLen,
  2377. const unsigned char *context, size_t contextLen);
  2378. /* The key update request values for KeyUpdate message. */
  2379. enum KeyUpdateRequest {
  2380. update_not_requested,
  2381. update_requested
  2382. };
  2383. #endif /* WOLFSSL_TLS13 */
  2384. #ifdef OPENSSL_EXTRA
  2385. enum SetCBIO {
  2386. WOLFSSL_CBIO_NONE = 0,
  2387. WOLFSSL_CBIO_RECV = 0x1,
  2388. WOLFSSL_CBIO_SEND = 0x2,
  2389. };
  2390. #endif
  2391. #ifdef WOLFSSL_STATIC_EPHEMERAL
  2392. /* contains static ephemeral keys */
  2393. typedef struct {
  2394. #ifndef NO_DH
  2395. DerBuffer* dhKey;
  2396. #endif
  2397. #ifdef HAVE_ECC
  2398. DerBuffer* ecKey;
  2399. #endif
  2400. } StaticKeyExchangeInfo_t;
  2401. #endif
  2402. /* wolfSSL context type */
  2403. struct WOLFSSL_CTX {
  2404. WOLFSSL_METHOD* method;
  2405. #ifdef SINGLE_THREADED
  2406. WC_RNG* rng; /* to be shared with WOLFSSL w/o locking */
  2407. #endif
  2408. wolfSSL_Mutex countMutex; /* reference count mutex */
  2409. int refCount; /* reference count */
  2410. int err; /* error code in case of mutex not created */
  2411. #ifndef NO_DH
  2412. buffer serverDH_P;
  2413. buffer serverDH_G;
  2414. #endif
  2415. #ifndef NO_CERTS
  2416. DerBuffer* certificate;
  2417. DerBuffer* certChain;
  2418. /* chain after self, in DER, with leading size for each cert */
  2419. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA) || defined(HAVE_LIGHTY)
  2420. WOLF_STACK_OF(WOLFSSL_X509_NAME)* ca_names;
  2421. #endif
  2422. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
  2423. defined(WOLFSSL_NGINX) || defined (WOLFSSL_HAPROXY)
  2424. WOLF_STACK_OF(WOLFSSL_X509)* x509Chain;
  2425. client_cert_cb CBClientCert; /* client certificate callback */
  2426. #endif
  2427. #ifdef WOLFSSL_TLS13
  2428. int certChainCnt;
  2429. #endif
  2430. DerBuffer* privateKey;
  2431. byte privateKeyType:6;
  2432. byte privateKeyId:1;
  2433. byte privateKeyLabel:1;
  2434. int privateKeySz;
  2435. int privateKeyDevId;
  2436. WOLFSSL_CERT_MANAGER* cm; /* our cert manager, ctx owns SSL will use */
  2437. #endif
  2438. #ifdef KEEP_OUR_CERT
  2439. WOLFSSL_X509* ourCert; /* keep alive a X509 struct of cert */
  2440. int ownOurCert; /* Dispose of certificate if we own */
  2441. #endif
  2442. Suites* suites; /* make dynamic, user may not need/set */
  2443. void* heap; /* for user memory overrides */
  2444. byte verifyDepth;
  2445. byte verifyPeer:1;
  2446. byte verifyNone:1;
  2447. byte failNoCert:1;
  2448. byte failNoCertxPSK:1; /* fail if no cert with the exception of PSK*/
  2449. byte sessionCacheOff:1;
  2450. byte sessionCacheFlushOff:1;
  2451. #ifdef HAVE_EXT_CACHE
  2452. byte internalCacheOff:1;
  2453. #endif
  2454. byte sendVerify:2; /* for client side (can not be single bit) */
  2455. byte haveRSA:1; /* RSA available */
  2456. byte haveECC:1; /* ECC available */
  2457. byte haveDH:1; /* server DH parms set by user */
  2458. byte haveNTRU:1; /* server private NTRU key loaded */
  2459. byte haveECDSAsig:1; /* server cert signed w/ ECDSA */
  2460. byte haveStaticECC:1; /* static server ECC private key */
  2461. byte partialWrite:1; /* only one msg per write call */
  2462. byte quietShutdown:1; /* don't send close notify */
  2463. byte groupMessages:1; /* group handshake messages before sending */
  2464. byte minDowngrade; /* minimum downgrade version */
  2465. byte haveEMS:1; /* have extended master secret extension */
  2466. byte useClientOrder:1; /* Use client's cipher preference order */
  2467. #if defined(HAVE_SESSION_TICKET)
  2468. byte noTicketTls12:1; /* TLS 1.2 server won't send ticket */
  2469. #endif
  2470. #ifdef WOLFSSL_TLS13
  2471. byte noTicketTls13:1; /* TLS 1.3 Server won't create new Ticket */
  2472. byte noPskDheKe:1; /* Don't use (EC)DHE with PSK */
  2473. #endif
  2474. byte mutualAuth:1; /* Mutual authentication required */
  2475. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  2476. byte postHandshakeAuth:1; /* Post-handshake auth supported. */
  2477. #endif
  2478. #ifndef NO_DH
  2479. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  2480. !defined(HAVE_SELFTEST)
  2481. byte dhKeyTested:1; /* Set when key has been tested. */
  2482. #endif
  2483. #endif
  2484. #ifdef HAVE_SECURE_RENEGOTIATION
  2485. byte useSecureReneg:1; /* when set will set WOLFSSL objects generated to enable */
  2486. #endif
  2487. #ifdef HAVE_ENCRYPT_THEN_MAC
  2488. byte disallowEncThenMac:1; /* Don't do Encrypt-Then-MAC */
  2489. #endif
  2490. #ifdef WOLFSSL_STATIC_MEMORY
  2491. byte onHeap:1; /* whether the ctx/method is put on heap hint */
  2492. #endif
  2493. #ifdef WOLFSSL_MULTICAST
  2494. byte haveMcast; /* multicast requested */
  2495. byte mcastID; /* multicast group ID */
  2496. #endif
  2497. #if defined(WOLFSSL_SCTP) && defined(WOLFSSL_DTLS)
  2498. byte dtlsSctp; /* DTLS-over-SCTP mode */
  2499. #endif
  2500. #if (defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU)) && \
  2501. defined(WOLFSSL_DTLS)
  2502. word16 dtlsMtuSz; /* DTLS MTU size */
  2503. #endif
  2504. #ifndef NO_DH
  2505. word16 minDhKeySz; /* minimum DH key size */
  2506. word16 maxDhKeySz; /* maximum DH key size */
  2507. #endif
  2508. #ifndef NO_RSA
  2509. short minRsaKeySz; /* minimum RSA key size */
  2510. #endif
  2511. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
  2512. short minEccKeySz; /* minimum ECC key size */
  2513. #endif
  2514. unsigned long mask; /* store SSL_OP_ flags */
  2515. #ifdef OPENSSL_EXTRA
  2516. byte sessionCtx[ID_LEN]; /* app session context ID */
  2517. word32 disabledCurves; /* curves disabled by user */
  2518. const unsigned char *alpn_cli_protos;/* ALPN client protocol list */
  2519. unsigned int alpn_cli_protos_len;
  2520. byte sessionCtxSz;
  2521. byte cbioFlag; /* WOLFSSL_CBIO_RECV/SEND: CBIORecv/Send is set */
  2522. CallbackInfoState* CBIS; /* used to get info about SSL state */
  2523. WOLFSSL_X509_VERIFY_PARAM* param; /* verification parameters*/
  2524. #endif
  2525. CallbackIORecv CBIORecv;
  2526. CallbackIOSend CBIOSend;
  2527. #ifdef WOLFSSL_DTLS
  2528. CallbackGenCookie CBIOCookie; /* gen cookie callback */
  2529. #ifdef WOLFSSL_SESSION_EXPORT
  2530. wc_dtls_export dtls_export; /* export function for DTLS session */
  2531. CallbackGetPeer CBGetPeer;
  2532. CallbackSetPeer CBSetPeer;
  2533. #endif
  2534. #endif /* WOLFSSL_DTLS */
  2535. VerifyCallback verifyCallback; /* cert verification callback */
  2536. #ifdef OPENSSL_ALL
  2537. CertVerifyCallback verifyCertCb;
  2538. void* verifyCertCbArg;
  2539. #endif /* OPENSSL_ALL */
  2540. word32 timeout; /* session timeout */
  2541. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_ED448)
  2542. word32 ecdhCurveOID; /* curve Ecc_Sum */
  2543. #endif
  2544. #ifdef HAVE_ECC
  2545. word16 eccTempKeySz; /* in octets 20 - 66 */
  2546. #endif
  2547. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
  2548. word32 pkCurveOID; /* curve Ecc_Sum */
  2549. #endif
  2550. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  2551. byte havePSK; /* psk key set by user */
  2552. wc_psk_client_callback client_psk_cb; /* client callback */
  2553. wc_psk_server_callback server_psk_cb; /* server callback */
  2554. #ifdef WOLFSSL_TLS13
  2555. wc_psk_client_tls13_callback client_psk_tls13_cb; /* client callback */
  2556. wc_psk_server_tls13_callback server_psk_tls13_cb; /* server callback */
  2557. #endif
  2558. void* psk_ctx;
  2559. char server_hint[MAX_PSK_ID_LEN + NULL_TERM_LEN];
  2560. #endif /* HAVE_SESSION_TICKET || !NO_PSK */
  2561. #ifdef WOLFSSL_TLS13
  2562. word16 group[WOLFSSL_MAX_GROUP_COUNT];
  2563. byte numGroups;
  2564. #endif
  2565. #ifdef WOLFSSL_EARLY_DATA
  2566. word32 maxEarlyDataSz;
  2567. #endif
  2568. #ifdef HAVE_ANON
  2569. byte haveAnon; /* User wants to allow Anon suites */
  2570. #endif /* HAVE_ANON */
  2571. #ifdef WOLFSSL_ENCRYPTED_KEYS
  2572. pem_password_cb* passwd_cb;
  2573. void* passwd_userdata;
  2574. #endif
  2575. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || defined(WOLFSSL_WPAS_SMALL)
  2576. WOLFSSL_X509_STORE x509_store; /* points to ctx->cm */
  2577. WOLFSSL_X509_STORE* x509_store_pt; /* take ownership of external store */
  2578. byte readAhead;
  2579. void* userPRFArg; /* passed to prf callback */
  2580. #endif
  2581. #ifdef HAVE_EX_DATA
  2582. WOLFSSL_CRYPTO_EX_DATA ex_data;
  2583. #endif
  2584. #if defined(HAVE_ALPN) && (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY))
  2585. CallbackALPNSelect alpnSelect;
  2586. void* alpnSelectArg;
  2587. #endif
  2588. #ifdef HAVE_SNI
  2589. CallbackSniRecv sniRecvCb;
  2590. void* sniRecvCbArg;
  2591. #endif
  2592. #if defined(WOLFSSL_MULTICAST) && defined(WOLFSSL_DTLS)
  2593. CallbackMcastHighwater mcastHwCb; /* Sequence number highwater callback */
  2594. word32 mcastFirstSeq; /* first trigger level */
  2595. word32 mcastSecondSeq; /* second trigger level */
  2596. word32 mcastMaxSeq; /* max level */
  2597. #endif
  2598. #ifdef HAVE_OCSP
  2599. WOLFSSL_OCSP ocsp;
  2600. #endif
  2601. int devId; /* async device id to use */
  2602. #ifdef HAVE_TLS_EXTENSIONS
  2603. TLSX* extensions; /* RFC 6066 TLS Extensions data */
  2604. #ifndef NO_WOLFSSL_SERVER
  2605. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  2606. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2607. OcspRequest* certOcspRequest;
  2608. #endif
  2609. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2610. OcspRequest* chainOcspRequest[MAX_CHAIN_DEPTH];
  2611. #endif
  2612. #endif
  2613. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER)
  2614. SessionTicketEncCb ticketEncCb; /* enc/dec session ticket Cb */
  2615. void* ticketEncCtx; /* session encrypt context */
  2616. int ticketHint; /* ticket hint in seconds */
  2617. #ifndef WOLFSSL_NO_DEF_TICKET_ENC_CB
  2618. TicketEncCbCtx ticketKeyCtx;
  2619. #endif
  2620. #endif
  2621. #endif
  2622. #ifdef HAVE_SUPPORTED_CURVES
  2623. byte userCurves; /* indicates user called wolfSSL_CTX_UseSupportedCurve */
  2624. #endif
  2625. #ifdef ATOMIC_USER
  2626. CallbackMacEncrypt MacEncryptCb; /* Atomic User Mac/Encrypt Cb */
  2627. CallbackDecryptVerify DecryptVerifyCb; /* Atomic User Decrypt/Verify Cb */
  2628. #ifdef HAVE_ENCRYPT_THEN_MAC
  2629. CallbackEncryptMac EncryptMacCb; /* Atomic User Mac/Enc Cb */
  2630. CallbackVerifyDecrypt VerifyDecryptCb; /* Atomic User Dec/Verify Cb */
  2631. #endif
  2632. #endif
  2633. #ifdef HAVE_PK_CALLBACKS
  2634. #ifdef HAVE_ECC
  2635. CallbackEccKeyGen EccKeyGenCb; /* User EccKeyGen Callback Handler */
  2636. CallbackEccSign EccSignCb; /* User EccSign Callback handler */
  2637. CallbackEccVerify EccVerifyCb; /* User EccVerify Callback handler */
  2638. CallbackEccSharedSecret EccSharedSecretCb; /* User EccVerify Callback handler */
  2639. #ifdef HAVE_ED25519
  2640. /* User Ed25519Sign Callback handler */
  2641. CallbackEd25519Sign Ed25519SignCb;
  2642. /* User Ed25519Verify Callback handler */
  2643. CallbackEd25519Verify Ed25519VerifyCb;
  2644. #endif
  2645. #ifdef HAVE_CURVE25519
  2646. /* User X25519 KeyGen Callback Handler */
  2647. CallbackX25519KeyGen X25519KeyGenCb;
  2648. /* User X25519 SharedSecret Callback handler */
  2649. CallbackX25519SharedSecret X25519SharedSecretCb;
  2650. #endif
  2651. #ifdef HAVE_ED448
  2652. /* User Ed448Sign Callback handler */
  2653. CallbackEd448Sign Ed448SignCb;
  2654. /* User Ed448Verify Callback handler */
  2655. CallbackEd448Verify Ed448VerifyCb;
  2656. #endif
  2657. #ifdef HAVE_CURVE448
  2658. /* User X448 KeyGen Callback Handler */
  2659. CallbackX448KeyGen X448KeyGenCb;
  2660. /* User X448 SharedSecret Callback handler */
  2661. CallbackX448SharedSecret X448SharedSecretCb;
  2662. #endif
  2663. #endif /* HAVE_ECC */
  2664. #ifndef NO_DH
  2665. CallbackDhAgree DhAgreeCb; /* User DH Agree Callback handler */
  2666. #endif
  2667. #ifndef NO_RSA
  2668. CallbackRsaSign RsaSignCb; /* User RsaSign Callback handler (priv key) */
  2669. CallbackRsaVerify RsaVerifyCb; /* User RsaVerify Callback handler (pub key) */
  2670. CallbackRsaVerify RsaSignCheckCb; /* User VerifyRsaSign Callback handler (priv key) */
  2671. #ifdef WC_RSA_PSS
  2672. CallbackRsaPssSign RsaPssSignCb; /* User RsaSign (priv key) */
  2673. CallbackRsaPssVerify RsaPssVerifyCb; /* User RsaVerify (pub key) */
  2674. CallbackRsaPssVerify RsaPssSignCheckCb; /* User VerifyRsaSign (priv key) */
  2675. #endif
  2676. CallbackRsaEnc RsaEncCb; /* User Rsa Public Encrypt handler */
  2677. CallbackRsaDec RsaDecCb; /* User Rsa Private Decrypt handler */
  2678. #endif /* NO_RSA */
  2679. #endif /* HAVE_PK_CALLBACKS */
  2680. #ifdef HAVE_WOLF_EVENT
  2681. WOLF_EVENT_QUEUE event_queue;
  2682. #endif /* HAVE_WOLF_EVENT */
  2683. #ifdef HAVE_EXT_CACHE
  2684. WOLFSSL_SESSION*(*get_sess_cb)(WOLFSSL*, unsigned char*, int, int*);
  2685. int (*new_sess_cb)(WOLFSSL*, WOLFSSL_SESSION*);
  2686. void (*rem_sess_cb)(WOLFSSL_CTX*, WOLFSSL_SESSION*);
  2687. #endif
  2688. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && !defined(NO_SHA256)
  2689. Srp* srp; /* TLS Secure Remote Password Protocol*/
  2690. byte* srp_password;
  2691. #endif
  2692. #ifdef WOLFSSL_STATIC_EPHEMERAL
  2693. StaticKeyExchangeInfo_t staticKE;
  2694. #endif
  2695. };
  2696. WOLFSSL_LOCAL
  2697. int InitSSL_Ctx(WOLFSSL_CTX*, WOLFSSL_METHOD*, void* heap);
  2698. WOLFSSL_LOCAL
  2699. void FreeSSL_Ctx(WOLFSSL_CTX*);
  2700. WOLFSSL_LOCAL
  2701. void SSL_CtxResourceFree(WOLFSSL_CTX*);
  2702. WOLFSSL_LOCAL
  2703. int DeriveTlsKeys(WOLFSSL* ssl);
  2704. WOLFSSL_LOCAL
  2705. int ProcessOldClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
  2706. word32 inSz, word16 sz);
  2707. #ifndef NO_CERTS
  2708. WOLFSSL_LOCAL
  2709. int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify);
  2710. WOLFSSL_LOCAL
  2711. int AlreadySigner(WOLFSSL_CERT_MANAGER* cm, byte* hash);
  2712. #ifdef WOLFSSL_TRUST_PEER_CERT
  2713. WOLFSSL_LOCAL
  2714. int AddTrustedPeer(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int verify);
  2715. WOLFSSL_LOCAL
  2716. int AlreadyTrustedPeer(WOLFSSL_CERT_MANAGER* cm, byte* hash);
  2717. #endif
  2718. #endif
  2719. /* All cipher suite related info
  2720. * Keep as a constant size (no ifdefs) for session export */
  2721. typedef struct CipherSpecs {
  2722. word16 key_size;
  2723. word16 iv_size;
  2724. word16 block_size;
  2725. word16 aead_mac_size;
  2726. byte bulk_cipher_algorithm;
  2727. byte cipher_type; /* block, stream, or aead */
  2728. byte mac_algorithm;
  2729. byte kea; /* key exchange algo */
  2730. byte sig_algo;
  2731. byte hash_size;
  2732. byte pad_size;
  2733. byte static_ecdh;
  2734. } CipherSpecs;
  2735. void InitCipherSpecs(CipherSpecs* cs);
  2736. /* Supported Key Exchange Protocols */
  2737. enum KeyExchangeAlgorithm {
  2738. no_kea,
  2739. rsa_kea,
  2740. diffie_hellman_kea,
  2741. fortezza_kea,
  2742. psk_kea,
  2743. dhe_psk_kea,
  2744. ecdhe_psk_kea,
  2745. ntru_kea,
  2746. ecc_diffie_hellman_kea,
  2747. ecc_static_diffie_hellman_kea /* for verify suite only */
  2748. };
  2749. /* Supported Authentication Schemes */
  2750. enum SignatureAlgorithm {
  2751. anonymous_sa_algo = 0,
  2752. rsa_sa_algo = 1,
  2753. dsa_sa_algo = 2,
  2754. ecc_dsa_sa_algo = 3,
  2755. rsa_pss_sa_algo = 8,
  2756. ed25519_sa_algo = 9,
  2757. rsa_pss_pss_algo = 10,
  2758. ed448_sa_algo = 11
  2759. };
  2760. #define PSS_RSAE_TO_PSS_PSS(macAlgo) \
  2761. (macAlgo + (pss_sha256 - sha256_mac))
  2762. #define PSS_PSS_HASH_TO_MAC(macAlgo) \
  2763. (macAlgo - (pss_sha256 - sha256_mac))
  2764. enum SigAlgRsaPss {
  2765. pss_sha256 = 0x09,
  2766. pss_sha384 = 0x0a,
  2767. pss_sha512 = 0x0b,
  2768. };
  2769. /* Supprted ECC Curve Types */
  2770. enum EccCurves {
  2771. named_curve = 3
  2772. };
  2773. /* Valid client certificate request types from page 27 */
  2774. enum ClientCertificateType {
  2775. rsa_sign = 1,
  2776. dss_sign = 2,
  2777. rsa_fixed_dh = 3,
  2778. dss_fixed_dh = 4,
  2779. rsa_ephemeral_dh = 5,
  2780. dss_ephemeral_dh = 6,
  2781. fortezza_kea_cert = 20,
  2782. ecdsa_sign = 64,
  2783. rsa_fixed_ecdh = 65,
  2784. ecdsa_fixed_ecdh = 66
  2785. };
  2786. #ifndef WOLFSSL_AEAD_ONLY
  2787. enum CipherType { stream, block, aead };
  2788. #else
  2789. enum CipherType { aead };
  2790. #endif
  2791. #if defined(BUILD_AES) || defined(BUILD_AESGCM) || (defined(HAVE_CHACHA) && \
  2792. defined(HAVE_POLY1305)) || defined(WOLFSSL_TLS13)
  2793. #define CIPHER_NONCE
  2794. #endif
  2795. #if defined(WOLFSSL_DTLS) && defined(HAVE_SECURE_RENEGOTIATION)
  2796. enum CipherSrc {
  2797. KEYS_NOT_SET = 0,
  2798. KEYS, /* keys from ssl->keys are loaded */
  2799. SCR /* keys from ssl->secure_renegotiation->tmp_keys are loaded */
  2800. };
  2801. #endif
  2802. /* cipher for now */
  2803. typedef struct Ciphers {
  2804. #ifdef BUILD_ARC4
  2805. Arc4* arc4;
  2806. #endif
  2807. #ifdef BUILD_DES3
  2808. Des3* des3;
  2809. #endif
  2810. #if defined(BUILD_AES) || defined(BUILD_AESGCM)
  2811. Aes* aes;
  2812. #if (defined(BUILD_AESGCM) || defined(HAVE_AESCCM)) && \
  2813. !defined(WOLFSSL_NO_TLS12)
  2814. byte* additional;
  2815. #endif
  2816. #endif
  2817. #ifdef CIPHER_NONCE
  2818. byte* nonce;
  2819. #endif
  2820. #ifdef HAVE_CAMELLIA
  2821. Camellia* cam;
  2822. #endif
  2823. #ifdef HAVE_CHACHA
  2824. ChaCha* chacha;
  2825. #endif
  2826. #ifdef HAVE_HC128
  2827. HC128* hc128;
  2828. #endif
  2829. #ifdef BUILD_RABBIT
  2830. Rabbit* rabbit;
  2831. #endif
  2832. #ifdef HAVE_IDEA
  2833. Idea* idea;
  2834. #endif
  2835. #if defined(WOLFSSL_TLS13) && defined(HAVE_NULL_CIPHER)
  2836. Hmac* hmac;
  2837. #endif
  2838. byte state;
  2839. byte setup; /* have we set it up flag for detection */
  2840. #if defined(WOLFSSL_DTLS) && defined(HAVE_SECURE_RENEGOTIATION)
  2841. enum CipherSrc src; /* DTLS uses this to determine which keys
  2842. * are currently loaded */
  2843. #endif
  2844. } Ciphers;
  2845. #ifdef HAVE_ONE_TIME_AUTH
  2846. /* Ciphers for one time authentication such as poly1305 */
  2847. typedef struct OneTimeAuth {
  2848. #ifdef HAVE_POLY1305
  2849. Poly1305* poly1305;
  2850. #endif
  2851. byte setup; /* flag for if a cipher has been set */
  2852. } OneTimeAuth;
  2853. #endif
  2854. WOLFSSL_LOCAL void InitCiphers(WOLFSSL* ssl);
  2855. WOLFSSL_LOCAL void FreeCiphers(WOLFSSL* ssl);
  2856. /* hashes type */
  2857. typedef struct Hashes {
  2858. #if !defined(NO_MD5) && !defined(NO_OLD_TLS)
  2859. byte md5[WC_MD5_DIGEST_SIZE];
  2860. #endif
  2861. #if !defined(NO_SHA)
  2862. byte sha[WC_SHA_DIGEST_SIZE];
  2863. #endif
  2864. #ifndef NO_SHA256
  2865. byte sha256[WC_SHA256_DIGEST_SIZE];
  2866. #endif
  2867. #ifdef WOLFSSL_SHA384
  2868. byte sha384[WC_SHA384_DIGEST_SIZE];
  2869. #endif
  2870. #ifdef WOLFSSL_SHA512
  2871. byte sha512[WC_SHA512_DIGEST_SIZE];
  2872. #endif
  2873. } Hashes;
  2874. WOLFSSL_LOCAL int BuildCertHashes(WOLFSSL* ssl, Hashes* hashes);
  2875. #ifdef WOLFSSL_TLS13
  2876. typedef union Digest {
  2877. #ifndef NO_WOLFSSL_SHA256
  2878. wc_Sha256 sha256;
  2879. #endif
  2880. #ifdef WOLFSSL_SHA384
  2881. wc_Sha384 sha384;
  2882. #endif
  2883. #ifdef WOLFSSL_SHA512
  2884. wc_Sha512 sha512;
  2885. #endif
  2886. } Digest;
  2887. #endif
  2888. /* Static x509 buffer */
  2889. typedef struct x509_buffer {
  2890. int length; /* actual size */
  2891. byte buffer[MAX_X509_SIZE]; /* max static cert size */
  2892. } x509_buffer;
  2893. /* wolfSSL X509_CHAIN, for no dynamic memory SESSION_CACHE */
  2894. struct WOLFSSL_X509_CHAIN {
  2895. int count; /* total number in chain */
  2896. x509_buffer certs[MAX_CHAIN_DEPTH]; /* only allow max depth 4 for now */
  2897. };
  2898. /* wolfSSL session type */
  2899. struct WOLFSSL_SESSION {
  2900. word32 bornOn; /* create time in seconds */
  2901. word32 timeout; /* timeout in seconds */
  2902. byte sessionID[ID_LEN]; /* id for protocol */
  2903. byte sessionIDSz;
  2904. byte masterSecret[SECRET_LEN]; /* stored secret */
  2905. word16 haveEMS; /* ext master secret flag */
  2906. #ifdef SESSION_CERTS
  2907. #ifdef OPENSSL_EXTRA
  2908. WOLFSSL_X509* peer; /* peer cert */
  2909. #endif
  2910. WOLFSSL_X509_CHAIN chain; /* peer cert chain, static */
  2911. #ifdef WOLFSSL_ALT_CERT_CHAINS
  2912. WOLFSSL_X509_CHAIN altChain; /* peer alt cert chain, static */
  2913. #endif
  2914. #endif
  2915. #if defined(SESSION_CERTS) || (defined(WOLFSSL_TLS13) && \
  2916. defined(HAVE_SESSION_TICKET))
  2917. ProtocolVersion version; /* which version was used */
  2918. #endif
  2919. #if defined(SESSION_CERTS) || !defined(NO_RESUME_SUITE_CHECK) || \
  2920. (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET))
  2921. byte cipherSuite0; /* first byte, normally 0 */
  2922. byte cipherSuite; /* 2nd byte, actual suite */
  2923. #endif
  2924. #ifndef NO_CLIENT_CACHE
  2925. word16 idLen; /* serverID length */
  2926. byte serverID[SERVER_ID_LEN]; /* for easier client lookup */
  2927. #endif
  2928. #ifdef OPENSSL_EXTRA
  2929. byte sessionCtxSz; /* sessionCtx length */
  2930. byte sessionCtx[ID_LEN]; /* app specific context id */
  2931. wolfSSL_Mutex refMutex; /* ref count mutex */
  2932. int refCount; /* reference count */
  2933. #endif
  2934. #ifdef WOLFSSL_TLS13
  2935. word16 namedGroup;
  2936. #endif
  2937. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  2938. #ifdef WOLFSSL_TLS13
  2939. word32 ticketSeen; /* Time ticket seen (ms) */
  2940. word32 ticketAdd; /* Added by client */
  2941. TicketNonce ticketNonce; /* Nonce used to derive PSK */
  2942. #endif
  2943. #ifdef WOLFSSL_EARLY_DATA
  2944. word32 maxEarlyDataSz;
  2945. #endif
  2946. #endif
  2947. #ifdef HAVE_SESSION_TICKET
  2948. byte* ticket;
  2949. word16 ticketLen;
  2950. byte staticTicket[SESSION_TICKET_LEN];
  2951. byte isDynamic;
  2952. #endif
  2953. #if defined(HAVE_EXT_CACHE) || defined(OPENSSL_EXTRA)
  2954. byte isAlloced;
  2955. #endif
  2956. #ifdef HAVE_EX_DATA
  2957. WOLFSSL_CRYPTO_EX_DATA ex_data;
  2958. #endif
  2959. byte side; /* Either WOLFSSL_CLIENT_END or
  2960. WOLFSSL_SERVER_END */
  2961. };
  2962. WOLFSSL_LOCAL WOLFSSL_SESSION* GetSession(WOLFSSL*, byte*, byte);
  2963. WOLFSSL_LOCAL int SetSession(WOLFSSL*, WOLFSSL_SESSION*);
  2964. WOLFSSL_LOCAL void FreeSession(WOLFSSL_SESSION*, int);
  2965. typedef int (*hmacfp) (WOLFSSL*, byte*, const byte*, word32, int, int, int, int);
  2966. #ifndef NO_CLIENT_CACHE
  2967. WOLFSSL_LOCAL
  2968. WOLFSSL_SESSION* GetSessionClient(WOLFSSL*, const byte*, int);
  2969. #endif
  2970. /* client connect state for nonblocking restart */
  2971. enum ConnectState {
  2972. CONNECT_BEGIN = 0,
  2973. CLIENT_HELLO_SENT,
  2974. HELLO_AGAIN, /* HELLO_AGAIN s for DTLS case */
  2975. HELLO_AGAIN_REPLY,
  2976. FIRST_REPLY_DONE,
  2977. FIRST_REPLY_FIRST,
  2978. FIRST_REPLY_SECOND,
  2979. FIRST_REPLY_THIRD,
  2980. FIRST_REPLY_FOURTH,
  2981. FINISHED_DONE,
  2982. SECOND_REPLY_DONE
  2983. };
  2984. /* server accept state for nonblocking restart */
  2985. enum AcceptState {
  2986. ACCEPT_BEGIN = 0,
  2987. ACCEPT_BEGIN_RENEG,
  2988. ACCEPT_CLIENT_HELLO_DONE,
  2989. ACCEPT_HELLO_RETRY_REQUEST_DONE,
  2990. ACCEPT_FIRST_REPLY_DONE,
  2991. SERVER_HELLO_SENT,
  2992. SERVER_EXTENSIONS_SENT,
  2993. CERT_SENT,
  2994. CERT_VERIFY_SENT,
  2995. CERT_STATUS_SENT,
  2996. KEY_EXCHANGE_SENT,
  2997. CERT_REQ_SENT,
  2998. SERVER_HELLO_DONE,
  2999. ACCEPT_SECOND_REPLY_DONE,
  3000. TICKET_SENT,
  3001. CHANGE_CIPHER_SENT,
  3002. ACCEPT_FINISHED_DONE,
  3003. ACCEPT_THIRD_REPLY_DONE
  3004. };
  3005. /* TLS 1.3 server accept state for nonblocking restart */
  3006. enum AcceptStateTls13 {
  3007. TLS13_ACCEPT_BEGIN = 0,
  3008. TLS13_ACCEPT_BEGIN_RENEG,
  3009. TLS13_ACCEPT_CLIENT_HELLO_DONE,
  3010. TLS13_ACCEPT_HELLO_RETRY_REQUEST_DONE,
  3011. TLS13_ACCEPT_FIRST_REPLY_DONE,
  3012. TLS13_ACCEPT_SECOND_REPLY_DONE,
  3013. TLS13_SERVER_HELLO_SENT,
  3014. TLS13_ACCEPT_THIRD_REPLY_DONE,
  3015. TLS13_SERVER_EXTENSIONS_SENT,
  3016. TLS13_CERT_REQ_SENT,
  3017. TLS13_CERT_SENT,
  3018. TLS13_CERT_VERIFY_SENT,
  3019. TLS13_ACCEPT_FINISHED_SENT,
  3020. TLS13_PRE_TICKET_SENT,
  3021. TLS13_ACCEPT_FINISHED_DONE,
  3022. TLS13_TICKET_SENT
  3023. };
  3024. /* buffers for struct WOLFSSL */
  3025. typedef struct Buffers {
  3026. bufferStatic inputBuffer;
  3027. bufferStatic outputBuffer;
  3028. buffer domainName; /* for client check */
  3029. buffer clearOutputBuffer;
  3030. buffer sig; /* signature data */
  3031. buffer digest; /* digest data */
  3032. int prevSent; /* previous plain text bytes sent
  3033. when got WANT_WRITE */
  3034. int plainSz; /* plain text bytes in buffer to send
  3035. when got WANT_WRITE */
  3036. byte weOwnCert; /* SSL own cert flag */
  3037. byte weOwnCertChain; /* SSL own cert chain flag */
  3038. byte weOwnKey; /* SSL own key flag */
  3039. byte weOwnDH; /* SSL own dh (p,g) flag */
  3040. #ifndef NO_DH
  3041. buffer serverDH_P; /* WOLFSSL_CTX owns, unless we own */
  3042. buffer serverDH_G; /* WOLFSSL_CTX owns, unless we own */
  3043. buffer serverDH_Pub;
  3044. buffer serverDH_Priv;
  3045. DhKey* serverDH_Key;
  3046. #endif
  3047. #ifndef NO_CERTS
  3048. DerBuffer* certificate; /* WOLFSSL_CTX owns, unless we own */
  3049. DerBuffer* key; /* WOLFSSL_CTX owns, unless we own */
  3050. byte keyType:6; /* Type of key: RSA, ECC, Ed25519 */
  3051. byte keyId:1; /* Key data is an id not data */
  3052. byte keyLabel:1; /* Key data is a label not data */
  3053. int keySz; /* Size of RSA key */
  3054. int keyDevId; /* Device Id for key */
  3055. DerBuffer* certChain; /* WOLFSSL_CTX owns, unless we own */
  3056. /* chain after self, in DER, with leading size for each cert */
  3057. #ifdef WOLFSSL_TLS13
  3058. int certChainCnt;
  3059. DerBuffer* certExts;
  3060. #endif
  3061. #endif
  3062. #ifdef WOLFSSL_SEND_HRR_COOKIE
  3063. buffer tls13CookieSecret; /* HRR cookie secret */
  3064. #endif
  3065. #ifdef WOLFSSL_DTLS
  3066. WOLFSSL_DTLS_CTX dtlsCtx; /* DTLS connection context */
  3067. #ifndef NO_WOLFSSL_SERVER
  3068. buffer dtlsCookieSecret; /* DTLS cookie secret */
  3069. #endif /* NO_WOLFSSL_SERVER */
  3070. #endif
  3071. #ifdef HAVE_PK_CALLBACKS
  3072. #ifdef HAVE_ECC
  3073. buffer peerEccDsaKey; /* we own for Ecc Verify Callbacks */
  3074. #endif /* HAVE_ECC */
  3075. #ifdef HAVE_ED25519
  3076. buffer peerEd25519Key; /* for Ed25519 Verify Callbacks */
  3077. #endif /* HAVE_ED25519 */
  3078. #ifdef HAVE_ED448
  3079. buffer peerEd448Key; /* for Ed448 Verify Callbacks */
  3080. #endif /* HAVE_ED448 */
  3081. #ifndef NO_RSA
  3082. buffer peerRsaKey; /* we own for Rsa Verify Callbacks */
  3083. #endif /* NO_RSA */
  3084. #endif /* HAVE_PK_CALLBACKS */
  3085. } Buffers;
  3086. /* sub-states for send/do key share (key exchange) */
  3087. enum asyncState {
  3088. TLS_ASYNC_BEGIN = 0,
  3089. TLS_ASYNC_BUILD,
  3090. TLS_ASYNC_DO,
  3091. TLS_ASYNC_VERIFY,
  3092. TLS_ASYNC_FINALIZE,
  3093. TLS_ASYNC_END
  3094. };
  3095. /* sub-states for build message */
  3096. enum buildMsgState {
  3097. BUILD_MSG_BEGIN = 0,
  3098. BUILD_MSG_SIZE,
  3099. BUILD_MSG_HASH,
  3100. BUILD_MSG_VERIFY_MAC,
  3101. BUILD_MSG_ENCRYPT,
  3102. BUILD_MSG_ENCRYPTED_VERIFY_MAC,
  3103. };
  3104. /* sub-states for cipher operations */
  3105. enum cipherState {
  3106. CIPHER_STATE_BEGIN = 0,
  3107. CIPHER_STATE_DO,
  3108. CIPHER_STATE_END,
  3109. };
  3110. typedef struct Options {
  3111. #ifndef NO_PSK
  3112. wc_psk_client_callback client_psk_cb;
  3113. wc_psk_server_callback server_psk_cb;
  3114. #ifdef WOLFSSL_TLS13
  3115. wc_psk_client_tls13_callback client_psk_tls13_cb; /* client callback */
  3116. wc_psk_server_tls13_callback server_psk_tls13_cb; /* server callback */
  3117. #endif
  3118. void* psk_ctx;
  3119. #endif /* NO_PSK */
  3120. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || defined(WOLFSSL_WPAS_SMALL)
  3121. unsigned long mask; /* store SSL_OP_ flags */
  3122. #endif
  3123. /* on/off or small bit flags, optimize layout */
  3124. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  3125. word16 havePSK:1; /* psk key set by user */
  3126. #endif /* HAVE_SESSION_TICKET || !NO_PSK */
  3127. word16 sendVerify:2; /* false = 0, true = 1, sendBlank = 2 */
  3128. word16 sessionCacheOff:1;
  3129. word16 sessionCacheFlushOff:1;
  3130. #ifdef HAVE_EXT_CACHE
  3131. word16 internalCacheOff:1;
  3132. #endif
  3133. word16 side:2; /* client, server or neither end */
  3134. word16 verifyPeer:1;
  3135. word16 verifyNone:1;
  3136. word16 failNoCert:1;
  3137. word16 failNoCertxPSK:1; /* fail for no cert except with PSK */
  3138. word16 downgrade:1; /* allow downgrade of versions */
  3139. word16 resuming:1;
  3140. word16 haveSessionId:1; /* server may not send */
  3141. word16 tls:1; /* using TLS ? */
  3142. word16 tls1_1:1; /* using TLSv1.1+ ? */
  3143. word16 tls1_3:1; /* using TLSv1.3+ ? */
  3144. word16 dtls:1; /* using datagrams ? */
  3145. word16 connReset:1; /* has the peer reset */
  3146. word16 isClosed:1; /* if we consider conn closed */
  3147. word16 closeNotify:1; /* we've received a close notify */
  3148. word16 sentNotify:1; /* we've sent a close notify */
  3149. word16 usingCompression:1; /* are we using compression */
  3150. word16 haveRSA:1; /* RSA available */
  3151. word16 haveECC:1; /* ECC available */
  3152. word16 haveDH:1; /* server DH parms set by user */
  3153. word16 haveNTRU:1; /* server NTRU private key loaded */
  3154. word16 haveQSH:1; /* have QSH ability */
  3155. word16 haveECDSAsig:1; /* server ECDSA signed cert */
  3156. word16 haveStaticECC:1; /* static server ECC private key */
  3157. word16 havePeerCert:1; /* do we have peer's cert */
  3158. word16 havePeerVerify:1; /* and peer's cert verify */
  3159. word16 usingPSK_cipher:1; /* are using psk as cipher */
  3160. word16 usingAnon_cipher:1; /* are we using an anon cipher */
  3161. word16 noPskDheKe:1; /* Don't use (EC)DHE with PSK */
  3162. word16 sendAlertState:1; /* nonblocking resume */
  3163. word16 partialWrite:1; /* only one msg per write call */
  3164. word16 quietShutdown:1; /* don't send close notify */
  3165. word16 certOnly:1; /* stop once we get cert */
  3166. word16 groupMessages:1; /* group handshake messages */
  3167. word16 saveArrays:1; /* save array Memory for user get keys
  3168. or psk */
  3169. word16 weOwnRng:1; /* will be true unless CTX owns */
  3170. word16 haveEMS:1; /* using extended master secret */
  3171. #ifdef HAVE_POLY1305
  3172. word16 oldPoly:1; /* set when to use old rfc way of poly*/
  3173. #endif
  3174. word16 haveAnon:1; /* User wants to allow Anon suites */
  3175. #ifdef HAVE_SESSION_TICKET
  3176. word16 createTicket:1; /* Server to create new Ticket */
  3177. word16 useTicket:1; /* Use Ticket not session cache */
  3178. word16 rejectTicket:1; /* Callback rejected ticket */
  3179. word16 noTicketTls12:1; /* TLS 1.2 server won't send ticket */
  3180. #ifdef WOLFSSL_TLS13
  3181. word16 noTicketTls13:1; /* Server won't create new Ticket */
  3182. #endif
  3183. #endif
  3184. #ifdef WOLFSSL_DTLS
  3185. word16 dtlsUseNonblock:1; /* are we using nonblocking socket */
  3186. word16 dtlsHsRetain:1; /* DTLS retaining HS data */
  3187. word16 haveMcast:1; /* using multicast ? */
  3188. #ifdef WOLFSSL_SCTP
  3189. word16 dtlsSctp:1; /* DTLS-over-SCTP mode */
  3190. #endif
  3191. #endif
  3192. #if defined(HAVE_TLS_EXTENSIONS) && defined(HAVE_SUPPORTED_CURVES)
  3193. word16 userCurves:1; /* indicates user called wolfSSL_UseSupportedCurve */
  3194. #endif
  3195. word16 keepResources:1; /* Keep resources after handshake */
  3196. word16 useClientOrder:1; /* Use client's cipher order */
  3197. word16 mutualAuth:1; /* Mutual authentication is rquired */
  3198. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  3199. word16 postHandshakeAuth:1;/* Client send post_handshake_auth
  3200. * extension */
  3201. #endif
  3202. #if defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_SERVER)
  3203. word16 sendCookie:1; /* Server creates a Cookie in HRR */
  3204. #endif
  3205. #ifdef WOLFSSL_ALT_CERT_CHAINS
  3206. word16 usingAltCertChain:1;/* Alternate cert chain was used */
  3207. #endif
  3208. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)
  3209. word16 sentChangeCipher:1; /* Change Cipher Spec sent */
  3210. #endif
  3211. #if !defined(WOLFSSL_NO_CLIENT_AUTH) && \
  3212. ((defined(HAVE_ED25519) && !defined(NO_ED25519_CLIENT_AUTH)) || \
  3213. (defined(HAVE_ED448) && !defined(NO_ED448_CLIENT_AUTH)))
  3214. word16 cacheMessages:1; /* Cache messages for sign/verify */
  3215. #endif
  3216. #ifndef NO_DH
  3217. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && \
  3218. !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  3219. word16 dhDoKeyTest:1; /* Need to do the DH Key prime test */
  3220. word16 dhKeyTested:1; /* Set when key has been tested. */
  3221. #endif
  3222. #endif
  3223. #ifdef SINGLE_THREADED
  3224. word16 ownSuites:1; /* if suites are malloced in ssl object */
  3225. #endif
  3226. #ifdef HAVE_ENCRYPT_THEN_MAC
  3227. word16 disallowEncThenMac:1; /* Don't do Encrypt-Then-MAC */
  3228. word16 encThenMac:1; /* Doing Encrypt-Then-MAC */
  3229. word16 startedETMRead:1; /* Doing Encrypt-Then-MAC read */
  3230. word16 startedETMWrite:1; /* Doing Encrypt-Then-MAC write */
  3231. #endif
  3232. /* need full byte values for this section */
  3233. byte processReply; /* nonblocking resume */
  3234. byte cipherSuite0; /* first byte, normally 0 */
  3235. byte cipherSuite; /* second byte, actual suite */
  3236. byte serverState;
  3237. byte clientState;
  3238. byte handShakeState;
  3239. byte handShakeDone; /* at least one handshake complete */
  3240. byte minDowngrade; /* minimum downgrade version */
  3241. byte connectState; /* nonblocking resume */
  3242. byte acceptState; /* nonblocking resume */
  3243. byte asyncState; /* sub-state for enum asyncState */
  3244. byte buildMsgState; /* sub-state for enum buildMsgState */
  3245. byte alertCount; /* detect warning dos attempt */
  3246. #ifdef WOLFSSL_MULTICAST
  3247. word16 mcastID; /* Multicast group ID */
  3248. #endif
  3249. #ifndef NO_DH
  3250. word16 minDhKeySz; /* minimum DH key size */
  3251. word16 maxDhKeySz; /* minimum DH key size */
  3252. word16 dhKeySz; /* actual DH key size */
  3253. #endif
  3254. #ifndef NO_RSA
  3255. short minRsaKeySz; /* minimum RSA key size */
  3256. #endif
  3257. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
  3258. short minEccKeySz; /* minimum ECC key size */
  3259. #endif
  3260. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  3261. byte verifyDepth; /* maximum verification depth */
  3262. #endif
  3263. #ifdef WOLFSSL_EARLY_DATA
  3264. word16 pskIdIndex;
  3265. word32 maxEarlyDataSz;
  3266. #endif
  3267. #ifdef WOLFSSL_TLS13
  3268. byte oldMinor; /* client preferred version < TLS 1.3 */
  3269. #endif
  3270. } Options;
  3271. typedef struct Arrays {
  3272. byte* pendingMsg; /* defrag buffer */
  3273. byte* preMasterSecret;
  3274. word32 preMasterSz; /* differs for DH, actual size */
  3275. word32 pendingMsgSz; /* defrag buffer size */
  3276. word32 pendingMsgOffset; /* current offset into defrag buffer */
  3277. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  3278. word32 psk_keySz; /* actual size */
  3279. char client_identity[MAX_PSK_ID_LEN + NULL_TERM_LEN];
  3280. char server_hint[MAX_PSK_ID_LEN + NULL_TERM_LEN];
  3281. byte psk_key[MAX_PSK_KEY_LEN];
  3282. #endif
  3283. byte clientRandom[RAN_LEN];
  3284. byte serverRandom[RAN_LEN];
  3285. byte sessionID[ID_LEN];
  3286. byte sessionIDSz;
  3287. #ifdef WOLFSSL_TLS13
  3288. byte secret[SECRET_LEN];
  3289. #endif
  3290. #ifdef HAVE_KEYING_MATERIAL
  3291. byte exporterSecret[WC_MAX_DIGEST_SIZE];
  3292. #endif
  3293. byte masterSecret[SECRET_LEN];
  3294. #if defined(WOLFSSL_RENESAS_TSIP_TLS) && \
  3295. !defined(NO_WOLFSSL_RENESAS_TSIP_TLS_SESSION)
  3296. byte tsip_masterSecret[TSIP_TLS_MASTERSECRET_SIZE];
  3297. #endif
  3298. #ifdef WOLFSSL_DTLS
  3299. byte cookie[MAX_COOKIE_LEN];
  3300. byte cookieSz;
  3301. #endif
  3302. byte pendingMsgType; /* defrag buffer message type */
  3303. } Arrays;
  3304. #ifndef ASN_NAME_MAX
  3305. #define ASN_NAME_MAX 256
  3306. #endif
  3307. #ifndef MAX_DATE_SZ
  3308. #define MAX_DATE_SZ 32
  3309. #endif
  3310. #define STACK_TYPE_X509 0
  3311. #define STACK_TYPE_GEN_NAME 1
  3312. #define STACK_TYPE_BIO 2
  3313. #define STACK_TYPE_OBJ 3
  3314. #define STACK_TYPE_STRING 4
  3315. #define STACK_TYPE_CIPHER 5
  3316. #define STACK_TYPE_ACCESS_DESCRIPTION 6
  3317. #define STACK_TYPE_X509_EXT 7
  3318. #define STACK_TYPE_NULL 8
  3319. #define STACK_TYPE_X509_NAME 9
  3320. #define STACK_TYPE_CONF_VALUE 10
  3321. #define STACK_TYPE_X509_INFO 11
  3322. #define STACK_TYPE_BY_DIR_entry 12
  3323. #define STACK_TYPE_BY_DIR_hash 13
  3324. struct WOLFSSL_STACK {
  3325. unsigned long num; /* number of nodes in stack
  3326. * (safety measure for freeing and shortcut for count) */
  3327. #if defined(OPENSSL_ALL)
  3328. wolf_sk_compare_cb comp;
  3329. wolf_sk_hash_cb hash_fn;
  3330. unsigned long hash;
  3331. #endif
  3332. union {
  3333. WOLFSSL_X509* x509;
  3334. WOLFSSL_X509_NAME* name;
  3335. WOLFSSL_X509_INFO* info;
  3336. WOLFSSL_BIO* bio;
  3337. WOLFSSL_ASN1_OBJECT* obj;
  3338. WOLFSSL_CIPHER cipher;
  3339. WOLFSSL_ACCESS_DESCRIPTION* access;
  3340. WOLFSSL_X509_EXTENSION* ext;
  3341. #ifdef OPENSSL_EXTRA
  3342. WOLFSSL_CONF_VALUE* conf;
  3343. #endif
  3344. void* generic;
  3345. char* string;
  3346. WOLFSSL_GENERAL_NAME* gn;
  3347. WOLFSSL_BY_DIR_entry* dir_entry;
  3348. WOLFSSL_BY_DIR_HASH* dir_hash;
  3349. } data;
  3350. void* heap; /* memory heap hint */
  3351. WOLFSSL_STACK* next;
  3352. byte type; /* Identifies type of stack. */
  3353. };
  3354. struct WOLFSSL_X509_NAME {
  3355. char *name;
  3356. int dynamicName;
  3357. int sz;
  3358. char staticName[ASN_NAME_MAX];
  3359. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  3360. !defined(NO_ASN)
  3361. int entrySz; /* number of entries */
  3362. WOLFSSL_X509_NAME_ENTRY entry[MAX_NAME_ENTRIES]; /* all entries i.e. CN */
  3363. WOLFSSL_X509* x509; /* x509 that struct belongs to */
  3364. #endif /* OPENSSL_EXTRA */
  3365. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(HAVE_LIGHTY)
  3366. byte raw[ASN_NAME_MAX];
  3367. int rawLen;
  3368. #endif
  3369. void* heap;
  3370. };
  3371. #ifndef EXTERNAL_SERIAL_SIZE
  3372. #define EXTERNAL_SERIAL_SIZE 32
  3373. #endif
  3374. #ifdef NO_ASN
  3375. typedef struct DNS_entry DNS_entry;
  3376. #endif
  3377. struct WOLFSSL_X509 {
  3378. int version;
  3379. int serialSz;
  3380. #ifdef WOLFSSL_SEP
  3381. int deviceTypeSz;
  3382. int hwTypeSz;
  3383. byte deviceType[EXTERNAL_SERIAL_SIZE];
  3384. byte hwType[EXTERNAL_SERIAL_SIZE];
  3385. int hwSerialNumSz;
  3386. byte hwSerialNum[EXTERNAL_SERIAL_SIZE];
  3387. #endif /* WOLFSSL_SEP */
  3388. #if (defined(WOLFSSL_SEP) || defined(WOLFSSL_QT) || defined (OPENSSL_ALL)) && \
  3389. (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL))
  3390. byte certPolicySet;
  3391. byte certPolicyCrit;
  3392. #endif /* (WOLFSSL_SEP || WOLFSSL_QT) && (OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL) */
  3393. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL)
  3394. WOLFSSL_STACK* ext_sk; /* Store X509_EXTENSIONS from wolfSSL_X509_get_ext */
  3395. WOLFSSL_STACK* ext_sk_full; /* Store X509_EXTENSIONS from wolfSSL_X509_get0_extensions */
  3396. WOLFSSL_STACK* ext_d2i;/* Store d2i extensions from wolfSSL_X509_get_ext_d2i */
  3397. #endif /* WOLFSSL_QT || OPENSSL_ALL */
  3398. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)
  3399. WOLFSSL_ASN1_INTEGER* serialNumber; /* Stores SN from wolfSSL_X509_get_serialNumber */
  3400. #endif
  3401. WOLFSSL_ASN1_TIME notBefore;
  3402. WOLFSSL_ASN1_TIME notAfter;
  3403. buffer sig;
  3404. int sigOID;
  3405. DNS_entry* altNames; /* alt names list */
  3406. buffer pubKey;
  3407. int pubKeyOID;
  3408. DNS_entry* altNamesNext; /* hint for retrieval */
  3409. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
  3410. word32 pkCurveOID;
  3411. #endif /* HAVE_ECC */
  3412. #ifndef NO_CERTS
  3413. DerBuffer* derCert; /* may need */
  3414. #endif
  3415. void* heap; /* heap hint */
  3416. byte dynamicMemory; /* dynamic memory flag */
  3417. byte isCa:1;
  3418. #ifdef WOLFSSL_CERT_EXT
  3419. char certPolicies[MAX_CERTPOL_NB][MAX_CERTPOL_SZ];
  3420. int certPoliciesNb;
  3421. #endif /* WOLFSSL_CERT_EXT */
  3422. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  3423. wolfSSL_Mutex refMutex; /* ref count mutex */
  3424. int refCount; /* reference count */
  3425. #endif
  3426. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  3427. #ifdef HAVE_EX_DATA
  3428. WOLFSSL_CRYPTO_EX_DATA ex_data;
  3429. #endif
  3430. byte* authKeyId;
  3431. byte* subjKeyId;
  3432. byte* extKeyUsageSrc;
  3433. const byte* CRLInfo;
  3434. byte* authInfo;
  3435. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  3436. byte* authInfoCaIssuer;
  3437. int authInfoCaIssuerSz;
  3438. #endif
  3439. word32 pathLength;
  3440. word16 keyUsage;
  3441. int CRLInfoSz;
  3442. int authInfoSz;
  3443. word32 authKeyIdSz;
  3444. word32 subjKeyIdSz;
  3445. word32 extKeyUsageSz;
  3446. word32 extKeyUsageCount;
  3447. byte CRLdistSet:1;
  3448. byte CRLdistCrit:1;
  3449. byte authInfoSet:1;
  3450. byte authInfoCrit:1;
  3451. byte keyUsageSet:1;
  3452. byte keyUsageCrit:1;
  3453. byte extKeyUsageCrit:1;
  3454. byte subjKeyIdSet:1;
  3455. byte subjKeyIdCrit:1;
  3456. byte basicConstSet:1;
  3457. byte basicConstCrit:1;
  3458. byte basicConstPlSet:1;
  3459. byte subjAltNameSet:1;
  3460. byte subjAltNameCrit:1;
  3461. byte authKeyIdSet:1;
  3462. byte authKeyIdCrit:1;
  3463. byte issuerSet:1;
  3464. #endif /* OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL */
  3465. #ifdef WOLFSSL_CERT_REQ
  3466. byte isCSR:1;
  3467. #endif
  3468. byte serial[EXTERNAL_SERIAL_SIZE];
  3469. char subjectCN[ASN_NAME_MAX]; /* common name short cut */
  3470. #ifdef WOLFSSL_CERT_REQ
  3471. #ifdef OPENSSL_ALL
  3472. WOLFSSL_X509_ATTRIBUTE* challengePwAttr;
  3473. #endif
  3474. char challengePw[CTC_NAME_SIZE]; /* for REQ certs */
  3475. #endif
  3476. WOLFSSL_X509_NAME issuer;
  3477. WOLFSSL_X509_NAME subject;
  3478. #if defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_WPAS)
  3479. WOLFSSL_X509_ALGOR algor;
  3480. WOLFSSL_X509_PUBKEY key;
  3481. #endif
  3482. #if defined(OPENSSL_ALL) || defined(KEEP_OUR_CERT) || defined(KEEP_PEER_CERT) || \
  3483. defined(SESSION_CERTS)
  3484. byte notBeforeData[CTC_DATE_SIZE];
  3485. byte notAfterData[CTC_DATE_SIZE];
  3486. #endif
  3487. };
  3488. /* record layer header for PlainText, Compressed, and CipherText */
  3489. typedef struct RecordLayerHeader {
  3490. byte type;
  3491. byte pvMajor;
  3492. byte pvMinor;
  3493. byte length[2];
  3494. } RecordLayerHeader;
  3495. /* record layer header for DTLS PlainText, Compressed, and CipherText */
  3496. typedef struct DtlsRecordLayerHeader {
  3497. byte type;
  3498. byte pvMajor;
  3499. byte pvMinor;
  3500. byte sequence_number[8]; /* per record */
  3501. byte length[2];
  3502. } DtlsRecordLayerHeader;
  3503. typedef struct DtlsFrag {
  3504. word32 begin;
  3505. word32 end;
  3506. struct DtlsFrag* next;
  3507. } DtlsFrag;
  3508. typedef struct DtlsMsg {
  3509. struct DtlsMsg* next;
  3510. byte* buf;
  3511. byte* msg;
  3512. DtlsFrag* fragList;
  3513. word32 fragSz; /* Length of fragments received */
  3514. word16 epoch; /* Epoch that this message belongs to */
  3515. word32 seq; /* Handshake sequence number */
  3516. word32 sz; /* Length of whole message */
  3517. byte type;
  3518. } DtlsMsg;
  3519. #ifdef HAVE_NETX
  3520. /* NETX I/O Callback default */
  3521. typedef struct NetX_Ctx {
  3522. NX_TCP_SOCKET* nxSocket; /* send/recv socket handle */
  3523. NX_PACKET* nxPacket; /* incoming packet handle for short reads */
  3524. ULONG nxOffset; /* offset already read from nxPacket */
  3525. ULONG nxWait; /* wait option flag */
  3526. } NetX_Ctx;
  3527. #endif
  3528. /* Handshake messages received from peer (plus change cipher */
  3529. typedef struct MsgsReceived {
  3530. word16 got_hello_request:1;
  3531. word16 got_client_hello:2;
  3532. word16 got_server_hello:2;
  3533. word16 got_hello_verify_request:1;
  3534. word16 got_session_ticket:1;
  3535. word16 got_end_of_early_data:1;
  3536. word16 got_hello_retry_request:1;
  3537. word16 got_encrypted_extensions:1;
  3538. word16 got_certificate:1;
  3539. word16 got_certificate_status:1;
  3540. word16 got_server_key_exchange:1;
  3541. word16 got_certificate_request:1;
  3542. word16 got_server_hello_done:1;
  3543. word16 got_certificate_verify:1;
  3544. word16 got_client_key_exchange:1;
  3545. word16 got_finished:1;
  3546. word16 got_key_update:1;
  3547. word16 got_change_cipher:1;
  3548. } MsgsReceived;
  3549. /* Handshake hashes */
  3550. typedef struct HS_Hashes {
  3551. Hashes verifyHashes;
  3552. Hashes certHashes; /* for cert verify */
  3553. #ifndef NO_SHA
  3554. wc_Sha hashSha; /* sha hash of handshake msgs */
  3555. #endif
  3556. #if !defined(NO_MD5) && !defined(NO_OLD_TLS)
  3557. wc_Md5 hashMd5; /* md5 hash of handshake msgs */
  3558. #endif
  3559. #ifndef NO_SHA256
  3560. wc_Sha256 hashSha256; /* sha256 hash of handshake msgs */
  3561. #endif
  3562. #ifdef WOLFSSL_SHA384
  3563. wc_Sha384 hashSha384; /* sha384 hash of handshake msgs */
  3564. #endif
  3565. #ifdef WOLFSSL_SHA512
  3566. wc_Sha512 hashSha512; /* sha512 hash of handshake msgs */
  3567. #endif
  3568. #if (defined(HAVE_ED25519) || defined(HAVE_ED448)) && \
  3569. !defined(WOLFSSL_NO_CLIENT_AUTH)
  3570. byte* messages; /* handshake messages */
  3571. int length; /* length of handshake messages' data */
  3572. int prevLen; /* length of messages but last */
  3573. #endif
  3574. } HS_Hashes;
  3575. #ifndef WOLFSSL_NO_TLS12
  3576. /* Persistable BuildMessage arguments */
  3577. typedef struct BuildMsgArgs {
  3578. word32 digestSz;
  3579. word32 sz;
  3580. word32 pad;
  3581. word32 idx;
  3582. word32 headerSz;
  3583. word16 size;
  3584. word32 ivSz; /* TLSv1.1 IV */
  3585. byte* iv;
  3586. } BuildMsgArgs;
  3587. #endif
  3588. #ifdef WOLFSSL_ASYNC_CRYPT
  3589. #define MAX_ASYNC_ARGS 18
  3590. typedef void (*FreeArgsCb)(struct WOLFSSL* ssl, void* pArgs);
  3591. struct WOLFSSL_ASYNC {
  3592. WC_ASYNC_DEV* dev;
  3593. FreeArgsCb freeArgs; /* function pointer to cleanup args */
  3594. word32 args[MAX_ASYNC_ARGS]; /* holder for current args */
  3595. BuildMsgArgs buildArgs; /* holder for current BuildMessage args */
  3596. };
  3597. #endif
  3598. #ifdef HAVE_WRITE_DUP
  3599. #define WRITE_DUP_SIDE 1
  3600. #define READ_DUP_SIDE 2
  3601. typedef struct WriteDup {
  3602. wolfSSL_Mutex dupMutex; /* reference count mutex */
  3603. int dupCount; /* reference count */
  3604. int dupErr; /* under dupMutex, pass to other side */
  3605. } WriteDup;
  3606. WOLFSSL_LOCAL void FreeWriteDup(WOLFSSL* ssl);
  3607. WOLFSSL_LOCAL int NotifyWriteSide(WOLFSSL* ssl, int err);
  3608. #endif /* HAVE_WRITE_DUP */
  3609. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  3610. typedef struct CertReqCtx CertReqCtx;
  3611. struct CertReqCtx {
  3612. CertReqCtx* next;
  3613. byte len;
  3614. byte ctx;
  3615. };
  3616. #endif
  3617. #ifdef WOLFSSL_EARLY_DATA
  3618. typedef enum EarlyDataState {
  3619. no_early_data,
  3620. early_data_ext,
  3621. expecting_early_data,
  3622. process_early_data,
  3623. done_early_data
  3624. } EarlyDataState;
  3625. #endif
  3626. /* wolfSSL ssl type */
  3627. struct WOLFSSL {
  3628. WOLFSSL_CTX* ctx;
  3629. Suites* suites; /* only need during handshake */
  3630. Arrays* arrays;
  3631. #ifdef WOLFSSL_TLS13
  3632. byte clientSecret[SECRET_LEN];
  3633. byte serverSecret[SECRET_LEN];
  3634. #endif
  3635. HS_Hashes* hsHashes;
  3636. void* IOCB_ReadCtx;
  3637. void* IOCB_WriteCtx;
  3638. WC_RNG* rng;
  3639. void* verifyCbCtx; /* cert verify callback user ctx*/
  3640. VerifyCallback verifyCallback; /* cert verification callback */
  3641. void* heap; /* for user overrides */
  3642. #ifdef HAVE_WRITE_DUP
  3643. WriteDup* dupWrite; /* valid pointer indicates ON */
  3644. /* side that decrements dupCount to zero frees overall structure */
  3645. byte dupSide; /* write side or read side */
  3646. #endif
  3647. #ifdef OPENSSL_EXTRA
  3648. byte cbioFlag; /* WOLFSSL_CBIO_RECV/SEND: CBIORecv/Send is set */
  3649. #endif
  3650. CallbackIORecv CBIORecv;
  3651. CallbackIOSend CBIOSend;
  3652. #ifdef WOLFSSL_STATIC_MEMORY
  3653. WOLFSSL_HEAP_HINT heap_hint;
  3654. #endif
  3655. #ifndef NO_HANDSHAKE_DONE_CB
  3656. HandShakeDoneCb hsDoneCb; /* notify user handshake done */
  3657. void* hsDoneCtx; /* user handshake cb context */
  3658. #endif
  3659. #ifdef WOLFSSL_ASYNC_CRYPT
  3660. struct WOLFSSL_ASYNC async;
  3661. #elif defined(WOLFSSL_NONBLOCK_OCSP)
  3662. void* nonblockarg; /* dynamic arg for handling non-block resume */
  3663. #endif
  3664. void* hsKey; /* Handshake key (RsaKey or ecc_key) allocated from heap */
  3665. word32 hsType; /* Type of Handshake key (hsKey) */
  3666. WOLFSSL_CIPHER cipher;
  3667. #ifndef WOLFSSL_AEAD_ONLY
  3668. hmacfp hmac;
  3669. #endif
  3670. Ciphers encrypt;
  3671. Ciphers decrypt;
  3672. Buffers buffers;
  3673. WOLFSSL_SESSION session;
  3674. #ifdef HAVE_EXT_CACHE
  3675. WOLFSSL_SESSION* extSession;
  3676. #endif
  3677. WOLFSSL_ALERT_HISTORY alert_history;
  3678. int error;
  3679. int rfd; /* read file descriptor */
  3680. int wfd; /* write file descriptor */
  3681. int rflags; /* user read flags */
  3682. int wflags; /* user write flags */
  3683. word32 timeout; /* session timeout */
  3684. word32 fragOffset; /* fragment offset */
  3685. word16 curSize;
  3686. byte verifyDepth;
  3687. RecordLayerHeader curRL;
  3688. MsgsReceived msgsReceived; /* peer messages received */
  3689. ProtocolVersion version; /* negotiated version */
  3690. ProtocolVersion chVersion; /* client hello version */
  3691. CipherSpecs specs;
  3692. Keys keys;
  3693. Options options;
  3694. #ifdef OPENSSL_EXTRA
  3695. CallbackInfoState* CBIS; /* used to get info about SSL state */
  3696. int cbmode; /* read or write on info callback */
  3697. int cbtype; /* event type in info callback */
  3698. WOLFSSL_BIO* biord; /* socket bio read to free/close */
  3699. WOLFSSL_BIO* biowr; /* socket bio write to free/close */
  3700. byte sessionCtx[ID_LEN]; /* app session context ID */
  3701. WOLFSSL_X509_VERIFY_PARAM* param; /* verification parameters*/
  3702. #endif
  3703. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  3704. unsigned long peerVerifyRet;
  3705. #endif
  3706. #ifdef OPENSSL_EXTRA
  3707. byte readAhead;
  3708. byte sessionCtxSz; /* size of sessionCtx stored */
  3709. #ifdef HAVE_PK_CALLBACKS
  3710. void* loggingCtx; /* logging callback argument */
  3711. #endif
  3712. #endif /* OPENSSL_EXTRA */
  3713. #ifndef NO_RSA
  3714. RsaKey* peerRsaKey;
  3715. #ifdef WOLFSSL_RENESAS_TSIP_TLS
  3716. byte *peerTsipEncRsaKeyIndex;
  3717. #endif
  3718. byte peerRsaKeyPresent;
  3719. #endif
  3720. #ifdef HAVE_QSH
  3721. QSHKey* QSH_Key;
  3722. QSHKey* peerQSHKey;
  3723. QSHSecret* QSH_secret;
  3724. byte isQSH; /* is the handshake a QSH? */
  3725. byte sendQSHKeys; /* flag for if the client should sen
  3726. public keys */
  3727. byte peerQSHKeyPresent;
  3728. byte minRequest;
  3729. byte maxRequest;
  3730. byte user_set_QSHSchemes;
  3731. #endif
  3732. #if defined(WOLFSSL_TLS13) || defined(HAVE_FFDHE)
  3733. word16 namedGroup;
  3734. #endif
  3735. #ifdef WOLFSSL_TLS13
  3736. word16 group[WOLFSSL_MAX_GROUP_COUNT];
  3737. byte numGroups;
  3738. #endif
  3739. word16 pssAlgo;
  3740. #ifdef WOLFSSL_TLS13
  3741. word16 certHashSigAlgoSz; /* SigAlgoCert ext length in bytes */
  3742. byte certHashSigAlgo[WOLFSSL_MAX_SIGALGO]; /* cert sig/algo to
  3743. * offer */
  3744. #endif
  3745. #ifdef HAVE_NTRU
  3746. word16 peerNtruKeyLen;
  3747. byte peerNtruKey[MAX_NTRU_PUB_KEY_SZ];
  3748. byte peerNtruKeyPresent;
  3749. #endif
  3750. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
  3751. int eccVerifyRes;
  3752. #endif
  3753. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  3754. word32 ecdhCurveOID; /* curve Ecc_Sum */
  3755. ecc_key* eccTempKey; /* private ECDHE key */
  3756. byte eccTempKeyPresent; /* also holds type */
  3757. byte peerEccKeyPresent;
  3758. #endif
  3759. #ifdef HAVE_ECC
  3760. ecc_key* peerEccKey; /* peer's ECDHE key */
  3761. ecc_key* peerEccDsaKey; /* peer's ECDSA key */
  3762. word16 eccTempKeySz; /* in octets 20 - 66 */
  3763. byte peerEccDsaKeyPresent;
  3764. #endif
  3765. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_CURVE448)
  3766. word32 pkCurveOID; /* curve Ecc_Sum */
  3767. #endif
  3768. #ifdef HAVE_ED25519
  3769. ed25519_key* peerEd25519Key;
  3770. byte peerEd25519KeyPresent;
  3771. #endif
  3772. #ifdef HAVE_CURVE25519
  3773. curve25519_key* peerX25519Key;
  3774. byte peerX25519KeyPresent;
  3775. #endif
  3776. #ifdef HAVE_ED448
  3777. ed448_key* peerEd448Key;
  3778. byte peerEd448KeyPresent;
  3779. #endif
  3780. #ifdef HAVE_CURVE448
  3781. curve448_key* peerX448Key;
  3782. byte peerX448KeyPresent;
  3783. #endif
  3784. #ifdef HAVE_LIBZ
  3785. z_stream c_stream; /* compression stream */
  3786. z_stream d_stream; /* decompression stream */
  3787. byte didStreamInit; /* for stream init and end */
  3788. #endif
  3789. #ifdef WOLFSSL_DTLS
  3790. int dtls_timeout_init; /* starting timeout value */
  3791. int dtls_timeout_max; /* maximum timeout value */
  3792. int dtls_timeout; /* current timeout value, changes */
  3793. #ifndef NO_ASN_TIME
  3794. word32 dtls_start_timeout;
  3795. #endif /* !NO_ASN_TIME */
  3796. word32 dtls_tx_msg_list_sz;
  3797. word32 dtls_rx_msg_list_sz;
  3798. DtlsMsg* dtls_tx_msg_list;
  3799. DtlsMsg* dtls_tx_msg;
  3800. DtlsMsg* dtls_rx_msg_list;
  3801. void* IOCB_CookieCtx; /* gen cookie ctx */
  3802. word32 dtls_expected_rx;
  3803. #ifdef WOLFSSL_SESSION_EXPORT
  3804. wc_dtls_export dtls_export; /* export function for session */
  3805. #endif
  3806. #if defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU)
  3807. word16 dtlsMtuSz;
  3808. #endif /* WOLFSSL_SCTP || WOLFSSL_DTLS_MTU */
  3809. #ifdef WOLFSSL_MULTICAST
  3810. void* mcastHwCbCtx; /* Multicast highwater callback ctx */
  3811. #endif /* WOLFSSL_MULTICAST */
  3812. #ifdef WOLFSSL_DTLS_DROP_STATS
  3813. word32 macDropCount;
  3814. word32 replayDropCount;
  3815. #endif /* WOLFSSL_DTLS_DROP_STATS */
  3816. #endif /* WOLFSSL_DTLS */
  3817. #ifdef WOLFSSL_CALLBACKS
  3818. TimeoutInfo timeoutInfo; /* info saved during handshake */
  3819. HandShakeInfo handShakeInfo; /* info saved during handshake */
  3820. #endif
  3821. #ifdef OPENSSL_EXTRA
  3822. SSL_Msg_Cb protoMsgCb; /* inspect protocol message callback */
  3823. void* protoMsgCtx; /* user set context with msg callback */
  3824. #endif
  3825. #if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
  3826. byte hsInfoOn; /* track handshake info */
  3827. byte toInfoOn; /* track timeout info */
  3828. #endif
  3829. #ifdef HAVE_FUZZER
  3830. CallbackFuzzer fuzzerCb; /* for testing with using fuzzer */
  3831. void* fuzzerCtx; /* user defined pointer */
  3832. #endif
  3833. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  3834. CertReqCtx* certReqCtx;
  3835. #endif
  3836. #ifdef KEEP_PEER_CERT
  3837. WOLFSSL_X509 peerCert; /* X509 peer cert */
  3838. #endif
  3839. #ifdef KEEP_OUR_CERT
  3840. WOLFSSL_X509* ourCert; /* keep alive a X509 struct of cert.
  3841. points to ctx if not owned (owned
  3842. flag found in buffers.weOwnCert) */
  3843. #endif
  3844. byte keepCert; /* keep certificate after handshake */
  3845. #if defined(HAVE_EX_DATA) || defined(FORTRESS)
  3846. WOLFSSL_CRYPTO_EX_DATA ex_data; /* external data, for Fortress */
  3847. #endif
  3848. int devId; /* async device id to use */
  3849. #ifdef HAVE_ONE_TIME_AUTH
  3850. OneTimeAuth auth;
  3851. #endif
  3852. #ifdef HAVE_TLS_EXTENSIONS
  3853. TLSX* extensions; /* RFC 6066 TLS Extensions data */
  3854. #ifdef HAVE_MAX_FRAGMENT
  3855. word16 max_fragment;
  3856. #endif
  3857. #ifdef HAVE_TRUNCATED_HMAC
  3858. byte truncated_hmac;
  3859. #endif
  3860. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  3861. byte status_request;
  3862. #endif
  3863. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  3864. byte status_request_v2;
  3865. #endif
  3866. #if defined(HAVE_SECURE_RENEGOTIATION) \
  3867. || defined(HAVE_SERVER_RENEGOTIATION_INFO)
  3868. int secure_rene_count; /* how many times */
  3869. SecureRenegotiation* secure_renegotiation; /* valid pointer indicates */
  3870. #endif /* user turned on */
  3871. #ifdef HAVE_ALPN
  3872. char* alpn_client_list; /* keep the client's list */
  3873. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
  3874. CallbackALPNSelect alpnSelect;
  3875. void* alpnSelectArg;
  3876. #endif
  3877. #endif /* of accepted protocols */
  3878. #if !defined(NO_WOLFSSL_CLIENT) && defined(HAVE_SESSION_TICKET)
  3879. CallbackSessionTicket session_ticket_cb;
  3880. void* session_ticket_ctx;
  3881. byte expect_session_ticket;
  3882. #endif
  3883. #endif /* HAVE_TLS_EXTENSIONS */
  3884. #ifdef HAVE_OCSP
  3885. void* ocspIOCtx;
  3886. byte ocspProducedDate[MAX_DATE_SZ];
  3887. int ocspProducedDateFormat;
  3888. #ifdef OPENSSL_EXTRA
  3889. byte* ocspResp;
  3890. int ocspRespSz;
  3891. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
  3892. char* url;
  3893. #endif
  3894. #endif
  3895. #endif
  3896. #ifdef HAVE_NETX
  3897. NetX_Ctx nxCtx; /* NetX IO Context */
  3898. #endif
  3899. #if defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP)
  3900. void* mnCtx; /* mynewt mn_socket IO Context */
  3901. #endif /* defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP) */
  3902. #ifdef WOLFSSL_GNRC
  3903. struct gnrc_wolfssl_ctx *gnrcCtx; /* Riot-OS GNRC UDP/IP context */
  3904. #endif
  3905. #ifdef SESSION_INDEX
  3906. int sessionIndex; /* Session's location in the cache. */
  3907. #endif
  3908. #ifdef ATOMIC_USER
  3909. void* MacEncryptCtx; /* Atomic User Mac/Encrypt Callback Context */
  3910. void* DecryptVerifyCtx; /* Atomic User Decrypt/Verify Callback Context */
  3911. #ifdef HAVE_ENCRYPT_THEN_MAC
  3912. void* EncryptMacCtx; /* Atomic User Encrypt/Mac Callback Ctx */
  3913. void* VerifyDecryptCtx; /* Atomic User Verify/Decrypt Callback Ctx */
  3914. #endif
  3915. #endif
  3916. #ifdef HAVE_PK_CALLBACKS
  3917. #ifdef HAVE_ECC
  3918. void* EccKeyGenCtx; /* EccKeyGen Callback Context */
  3919. void* EccSignCtx; /* Ecc Sign Callback Context */
  3920. void* EccVerifyCtx; /* Ecc Verify Callback Context */
  3921. void* EccSharedSecretCtx; /* Ecc Pms Callback Context */
  3922. #ifdef HAVE_ED25519
  3923. void* Ed25519SignCtx; /* ED25519 Sign Callback Context */
  3924. void* Ed25519VerifyCtx; /* ED25519 Verify Callback Context */
  3925. #endif
  3926. #ifdef HAVE_CURVE25519
  3927. void* X25519KeyGenCtx; /* X25519 KeyGen Callback Context */
  3928. void* X25519SharedSecretCtx; /* X25519 Pms Callback Context */
  3929. #endif
  3930. #ifdef HAVE_ED448
  3931. void* Ed448SignCtx; /* ED448 Sign Callback Context */
  3932. void* Ed448VerifyCtx; /* ED448 Verify Callback Context */
  3933. #endif
  3934. #ifdef HAVE_CURVE448
  3935. void* X448KeyGenCtx; /* X448 KeyGen Callback Context */
  3936. void* X448SharedSecretCtx; /* X448 Pms Callback Context */
  3937. #endif
  3938. #endif /* HAVE_ECC */
  3939. #ifndef NO_DH
  3940. void* DhAgreeCtx; /* DH Pms Callback Context */
  3941. #endif /* !NO_DH */
  3942. #ifndef NO_RSA
  3943. void* RsaSignCtx; /* Rsa Sign Callback Context */
  3944. void* RsaVerifyCtx; /* Rsa Verify Callback Context */
  3945. #ifdef WC_RSA_PSS
  3946. void* RsaPssSignCtx; /* Rsa PSS Sign Callback Context */
  3947. void* RsaPssVerifyCtx; /* Rsa PSS Verify Callback Context */
  3948. #endif
  3949. void* RsaEncCtx; /* Rsa Public Encrypt Callback Context */
  3950. void* RsaDecCtx; /* Rsa Private Decrypt Callback Context */
  3951. #endif /* NO_RSA */
  3952. #endif /* HAVE_PK_CALLBACKS */
  3953. #ifdef HAVE_SECRET_CALLBACK
  3954. SessionSecretCb sessionSecretCb;
  3955. void* sessionSecretCtx;
  3956. #ifdef WOLFSSL_TLS13
  3957. Tls13SecretCb tls13SecretCb;
  3958. void* tls13SecretCtx;
  3959. #endif
  3960. #endif /* HAVE_SECRET_CALLBACK */
  3961. #ifdef WOLFSSL_JNI
  3962. void* jObjectRef; /* reference to WolfSSLSession in JNI wrapper */
  3963. #endif /* WOLFSSL_JNI */
  3964. #ifdef WOLFSSL_EARLY_DATA
  3965. EarlyDataState earlyData;
  3966. word32 earlyDataSz;
  3967. byte earlyDataStatus;
  3968. #endif
  3969. #ifdef OPENSSL_ALL
  3970. long verifyCallbackResult;
  3971. #endif
  3972. #if defined(OPENSSL_EXTRA)
  3973. WOLFSSL_STACK* supportedCiphers; /* Used in wolfSSL_get_ciphers_compat */
  3974. WOLFSSL_STACK* peerCertChain; /* Used in wolfSSL_get_peer_cert_chain */
  3975. #endif
  3976. #ifdef WOLFSSL_STATIC_EPHEMERAL
  3977. StaticKeyExchangeInfo_t staticKE;
  3978. #endif
  3979. #if defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)
  3980. /* Added in libest port: allow applications to get the 'tls-unique' Channel
  3981. * Binding Type (https://tools.ietf.org/html/rfc5929#section-3). This is
  3982. * used in the EST protocol to bind an enrollment to a TLS session through
  3983. * 'proof-of-possession' (https://tools.ietf.org/html/rfc7030#section-3.4
  3984. * and https://tools.ietf.org/html/rfc7030#section-3.5). */
  3985. byte clientFinished[TLS_FINISHED_SZ];
  3986. byte serverFinished[TLS_FINISHED_SZ];
  3987. #endif
  3988. };
  3989. WOLFSSL_LOCAL int SSL_CTX_RefCount(WOLFSSL_CTX* ctx, int incr);
  3990. WOLFSSL_LOCAL int SetSSL_CTX(WOLFSSL*, WOLFSSL_CTX*, int);
  3991. WOLFSSL_LOCAL int InitSSL(WOLFSSL*, WOLFSSL_CTX*, int);
  3992. WOLFSSL_LOCAL void FreeSSL(WOLFSSL*, void* heap);
  3993. WOLFSSL_API void SSL_ResourceFree(WOLFSSL*); /* Micrium uses */
  3994. #ifndef NO_CERTS
  3995. WOLFSSL_LOCAL int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
  3996. long sz, int format, int type, WOLFSSL* ssl,
  3997. long* used, int userChain, int verify);
  3998. WOLFSSL_LOCAL int ProcessFile(WOLFSSL_CTX* ctx, const char* fname, int format,
  3999. int type, WOLFSSL* ssl, int userChain,
  4000. WOLFSSL_CRL* crl, int verify);
  4001. WOLFSSL_LOCAL int CheckHostName(DecodedCert* dCert, const char *domainName,
  4002. size_t domainNameLen);
  4003. #endif
  4004. #if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
  4005. WOLFSSL_LOCAL
  4006. void InitHandShakeInfo(HandShakeInfo*, WOLFSSL*);
  4007. WOLFSSL_LOCAL
  4008. void FinishHandShakeInfo(HandShakeInfo*);
  4009. WOLFSSL_LOCAL
  4010. void AddPacketName(WOLFSSL* ssl, const char* name);
  4011. WOLFSSL_LOCAL
  4012. void InitTimeoutInfo(TimeoutInfo*);
  4013. WOLFSSL_LOCAL
  4014. void FreeTimeoutInfo(TimeoutInfo*, void*);
  4015. WOLFSSL_LOCAL
  4016. void AddPacketInfo(WOLFSSL* ssl, const char* name, int type,
  4017. const byte* data, int sz, int write, void* heap);
  4018. WOLFSSL_LOCAL
  4019. void AddLateName(const char*, TimeoutInfo*);
  4020. WOLFSSL_LOCAL
  4021. void AddLateRecordHeader(const RecordLayerHeader* rl, TimeoutInfo* info);
  4022. #endif
  4023. /* Record Layer Header identifier from page 12 */
  4024. enum ContentType {
  4025. no_type = 0,
  4026. change_cipher_spec = 20,
  4027. alert = 21,
  4028. handshake = 22,
  4029. application_data = 23
  4030. };
  4031. /* handshake header, same for each message type, pgs 20/21 */
  4032. typedef struct HandShakeHeader {
  4033. byte type;
  4034. word24 length;
  4035. } HandShakeHeader;
  4036. /* DTLS handshake header, same for each message type */
  4037. typedef struct DtlsHandShakeHeader {
  4038. byte type;
  4039. word24 length;
  4040. byte message_seq[2]; /* start at 0, retransmit gets same # */
  4041. word24 fragment_offset; /* bytes in previous fragments */
  4042. word24 fragment_length; /* length of this fragment */
  4043. } DtlsHandShakeHeader;
  4044. enum HandShakeType {
  4045. hello_request = 0,
  4046. client_hello = 1,
  4047. server_hello = 2,
  4048. hello_verify_request = 3, /* DTLS addition */
  4049. session_ticket = 4,
  4050. end_of_early_data = 5,
  4051. hello_retry_request = 6,
  4052. encrypted_extensions = 8,
  4053. certificate = 11,
  4054. server_key_exchange = 12,
  4055. certificate_request = 13,
  4056. server_hello_done = 14,
  4057. certificate_verify = 15,
  4058. client_key_exchange = 16,
  4059. finished = 20,
  4060. certificate_status = 22,
  4061. key_update = 24,
  4062. change_cipher_hs = 55, /* simulate unique handshake type for sanity
  4063. checks. record layer change_cipher
  4064. conflicts with handshake finished */
  4065. message_hash = 254, /* synthetic message type for TLS v1.3 */
  4066. no_shake = 255 /* used to initialize the DtlsMsg record */
  4067. };
  4068. enum ProvisionSide {
  4069. PROVISION_CLIENT = 1,
  4070. PROVISION_SERVER = 2,
  4071. PROVISION_CLIENT_SERVER = 3
  4072. };
  4073. static const byte client[SIZEOF_SENDER+1] = { 0x43, 0x4C, 0x4E, 0x54, 0x00 }; /* CLNT */
  4074. static const byte server[SIZEOF_SENDER+1] = { 0x53, 0x52, 0x56, 0x52, 0x00 }; /* SRVR */
  4075. static const byte tls_client[FINISHED_LABEL_SZ + 1] = "client finished";
  4076. static const byte tls_server[FINISHED_LABEL_SZ + 1] = "server finished";
  4077. #ifdef OPENSSL_EXTRA
  4078. typedef struct {
  4079. int name_len;
  4080. const char *name;
  4081. int nid;
  4082. } WOLF_EC_NIST_NAME;
  4083. extern const WOLF_EC_NIST_NAME kNistCurves[];
  4084. /* This is the longest and shortest curve name in the kNistCurves list */
  4085. #define kNistCurves_MIN_NAME_LEN 5
  4086. #define kNistCurves_MAX_NAME_LEN 7
  4087. #endif
  4088. /* internal functions */
  4089. WOLFSSL_LOCAL int SendChangeCipher(WOLFSSL*);
  4090. WOLFSSL_LOCAL int SendTicket(WOLFSSL*);
  4091. WOLFSSL_LOCAL int DoClientTicket(WOLFSSL*, const byte*, word32);
  4092. WOLFSSL_LOCAL int SendData(WOLFSSL*, const void*, int);
  4093. #ifdef WOLFSSL_TLS13
  4094. WOLFSSL_LOCAL int SendTls13ServerHello(WOLFSSL*, byte);
  4095. #endif
  4096. WOLFSSL_LOCAL int SendCertificate(WOLFSSL*);
  4097. WOLFSSL_LOCAL int SendCertificateRequest(WOLFSSL*);
  4098. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  4099. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4100. WOLFSSL_LOCAL int CreateOcspResponse(WOLFSSL*, OcspRequest**, buffer*);
  4101. #endif
  4102. #if defined(HAVE_SECURE_RENEGOTIATION) && \
  4103. defined(HAVE_SERVER_RENEGOTIATION_INFO)
  4104. WOLFSSL_LOCAL int SendHelloRequest(WOLFSSL*);
  4105. #endif
  4106. WOLFSSL_LOCAL int SendCertificateStatus(WOLFSSL*);
  4107. WOLFSSL_LOCAL int SendServerKeyExchange(WOLFSSL*);
  4108. WOLFSSL_LOCAL int SendBuffered(WOLFSSL*);
  4109. WOLFSSL_LOCAL int ReceiveData(WOLFSSL*, byte*, int, int);
  4110. WOLFSSL_LOCAL int SendFinished(WOLFSSL*);
  4111. WOLFSSL_LOCAL int SendAlert(WOLFSSL*, int, int);
  4112. WOLFSSL_LOCAL int ProcessReply(WOLFSSL*);
  4113. WOLFSSL_LOCAL int SetCipherSpecs(WOLFSSL*);
  4114. WOLFSSL_LOCAL int MakeMasterSecret(WOLFSSL*);
  4115. WOLFSSL_LOCAL int AddSession(WOLFSSL*);
  4116. WOLFSSL_LOCAL int DeriveKeys(WOLFSSL* ssl);
  4117. WOLFSSL_LOCAL int StoreKeys(WOLFSSL* ssl, const byte* keyData, int side);
  4118. WOLFSSL_LOCAL int IsTLS(const WOLFSSL* ssl);
  4119. WOLFSSL_LOCAL int IsAtLeastTLSv1_2(const WOLFSSL* ssl);
  4120. WOLFSSL_LOCAL int IsAtLeastTLSv1_3(const ProtocolVersion pv);
  4121. WOLFSSL_LOCAL int TLSv1_3_Capable(WOLFSSL* ssl);
  4122. WOLFSSL_LOCAL void FreeHandshakeResources(WOLFSSL* ssl);
  4123. WOLFSSL_LOCAL void ShrinkInputBuffer(WOLFSSL* ssl, int forcedFree);
  4124. WOLFSSL_LOCAL void ShrinkOutputBuffer(WOLFSSL* ssl);
  4125. WOLFSSL_LOCAL int VerifyClientSuite(WOLFSSL* ssl);
  4126. WOLFSSL_LOCAL int SetTicket(WOLFSSL*, const byte*, word32);
  4127. WOLFSSL_LOCAL int wolfSSL_GetMaxRecordSize(WOLFSSL* ssl, int maxFragment);
  4128. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  4129. WOLFSSL_LOCAL int SetECKeyInternal(WOLFSSL_EC_KEY* eckey);
  4130. WOLFSSL_LOCAL int SetECKeyExternal(WOLFSSL_EC_KEY* eckey);
  4131. #endif
  4132. WOLFSSL_LOCAL WC_RNG* WOLFSSL_RSA_GetRNG(WOLFSSL_RSA *rsa, WC_RNG **tmpRNG,
  4133. int *initTmpRng);
  4134. #ifndef NO_CERTS
  4135. #ifndef NO_RSA
  4136. #ifdef WC_RSA_PSS
  4137. WOLFSSL_LOCAL int CheckRsaPssPadding(const byte* plain, word32 plainSz,
  4138. byte* out, word32 sigSz, enum wc_HashType hashType);
  4139. WOLFSSL_LOCAL int ConvertHashPss(int hashAlgo,
  4140. enum wc_HashType* hashType, int* mgf);
  4141. #endif
  4142. WOLFSSL_LOCAL int VerifyRsaSign(WOLFSSL* ssl, byte* verifySig,
  4143. word32 sigSz, const byte* plain, word32 plainSz, int sigAlgo,
  4144. int hashAlgo, RsaKey* key, DerBuffer* keyBufInfo);
  4145. WOLFSSL_LOCAL int RsaSign(WOLFSSL* ssl, const byte* in, word32 inSz,
  4146. byte* out, word32* outSz, int sigAlgo, int hashAlgo, RsaKey* key,
  4147. DerBuffer* keyBufInfo);
  4148. WOLFSSL_LOCAL int RsaVerify(WOLFSSL* ssl, byte* in, word32 inSz,
  4149. byte** out, int sigAlgo, int hashAlgo, RsaKey* key,
  4150. buffer* keyBufInfo);
  4151. WOLFSSL_LOCAL int RsaDec(WOLFSSL* ssl, byte* in, word32 inSz, byte** out,
  4152. word32* outSz, RsaKey* key, DerBuffer* keyBufInfo);
  4153. WOLFSSL_LOCAL int RsaEnc(WOLFSSL* ssl, const byte* in, word32 inSz, byte* out,
  4154. word32* outSz, RsaKey* key, buffer* keyBufInfo);
  4155. #endif /* !NO_RSA */
  4156. #ifdef HAVE_ECC
  4157. WOLFSSL_LOCAL int EccSign(WOLFSSL* ssl, const byte* in, word32 inSz,
  4158. byte* out, word32* outSz, ecc_key* key, DerBuffer* keyBufInfo);
  4159. WOLFSSL_LOCAL int EccVerify(WOLFSSL* ssl, const byte* in, word32 inSz,
  4160. const byte* out, word32 outSz, ecc_key* key, buffer* keyBufInfo);
  4161. WOLFSSL_LOCAL int EccSharedSecret(WOLFSSL* ssl, ecc_key* priv_key,
  4162. ecc_key* pub_key, byte* pubKeyDer, word32* pubKeySz, byte* out,
  4163. word32* outlen, int side);
  4164. #endif /* HAVE_ECC */
  4165. #ifdef HAVE_ED25519
  4166. WOLFSSL_LOCAL int Ed25519CheckPubKey(WOLFSSL* ssl);
  4167. WOLFSSL_LOCAL int Ed25519Sign(WOLFSSL* ssl, const byte* in, word32 inSz,
  4168. byte* out, word32* outSz, ed25519_key* key, DerBuffer* keyBufInfo);
  4169. WOLFSSL_LOCAL int Ed25519Verify(WOLFSSL* ssl, const byte* in,
  4170. word32 inSz, const byte* msg, word32 msgSz, ed25519_key* key,
  4171. buffer* keyBufInfo);
  4172. #endif /* HAVE_ED25519 */
  4173. #ifdef HAVE_ED448
  4174. WOLFSSL_LOCAL int Ed448CheckPubKey(WOLFSSL* ssl);
  4175. WOLFSSL_LOCAL int Ed448Sign(WOLFSSL* ssl, const byte* in, word32 inSz,
  4176. byte* out, word32* outSz, ed448_key* key, DerBuffer* keyBufInfo);
  4177. WOLFSSL_LOCAL int Ed448Verify(WOLFSSL* ssl, const byte* in,
  4178. word32 inSz, const byte* msg, word32 msgSz, ed448_key* key,
  4179. buffer* keyBufInfo);
  4180. #endif /* HAVE_ED448 */
  4181. #ifdef WOLFSSL_TRUST_PEER_CERT
  4182. /* options for searching hash table for a matching trusted peer cert */
  4183. #define WC_MATCH_SKID 0
  4184. #define WC_MATCH_NAME 1
  4185. WOLFSSL_LOCAL TrustedPeerCert* GetTrustedPeer(void* vp, byte* hash,
  4186. int type);
  4187. WOLFSSL_LOCAL int MatchTrustedPeer(TrustedPeerCert* tp,
  4188. DecodedCert* cert);
  4189. #endif
  4190. WOLFSSL_LOCAL Signer* GetCA(void* cm, byte* hash);
  4191. #ifndef NO_SKID
  4192. WOLFSSL_LOCAL Signer* GetCAByName(void* cm, byte* hash);
  4193. #endif
  4194. #endif /* !NO_CERTS */
  4195. WOLFSSL_LOCAL int BuildTlsHandshakeHash(WOLFSSL* ssl, byte* hash,
  4196. word32* hashLen);
  4197. WOLFSSL_LOCAL int BuildTlsFinished(WOLFSSL* ssl, Hashes* hashes,
  4198. const byte* sender);
  4199. WOLFSSL_LOCAL void FreeArrays(WOLFSSL* ssl, int keep);
  4200. WOLFSSL_LOCAL int CheckAvailableSize(WOLFSSL *ssl, int size);
  4201. WOLFSSL_LOCAL int GrowInputBuffer(WOLFSSL* ssl, int size, int usedLength);
  4202. #ifndef NO_TLS
  4203. WOLFSSL_LOCAL int MakeTlsMasterSecret(WOLFSSL*);
  4204. #ifndef WOLFSSL_AEAD_ONLY
  4205. WOLFSSL_LOCAL int TLS_hmac(WOLFSSL* ssl, byte* digest, const byte* in,
  4206. word32 sz, int padSz, int content, int verify, int epochOrder);
  4207. #endif
  4208. #endif
  4209. #ifndef NO_WOLFSSL_CLIENT
  4210. WOLFSSL_LOCAL int SendClientHello(WOLFSSL*);
  4211. #ifdef WOLFSSL_TLS13
  4212. WOLFSSL_LOCAL int SendTls13ClientHello(WOLFSSL*);
  4213. #endif
  4214. WOLFSSL_LOCAL int SendClientKeyExchange(WOLFSSL*);
  4215. WOLFSSL_LOCAL int SendCertificateVerify(WOLFSSL*);
  4216. #endif /* NO_WOLFSSL_CLIENT */
  4217. #ifndef NO_WOLFSSL_SERVER
  4218. WOLFSSL_LOCAL int SendServerHello(WOLFSSL*);
  4219. WOLFSSL_LOCAL int SendServerHelloDone(WOLFSSL*);
  4220. #endif /* NO_WOLFSSL_SERVER */
  4221. #ifdef WOLFSSL_DTLS
  4222. WOLFSSL_LOCAL DtlsMsg* DtlsMsgNew(word32, void*);
  4223. WOLFSSL_LOCAL void DtlsMsgDelete(DtlsMsg*, void*);
  4224. WOLFSSL_LOCAL void DtlsMsgListDelete(DtlsMsg*, void*);
  4225. WOLFSSL_LOCAL void DtlsTxMsgListClean(WOLFSSL* ssl);
  4226. WOLFSSL_LOCAL int DtlsMsgSet(DtlsMsg*, word32, word16, const byte*, byte,
  4227. word32, word32, void*);
  4228. WOLFSSL_LOCAL DtlsMsg* DtlsMsgFind(DtlsMsg*, word32, word32);
  4229. WOLFSSL_LOCAL void DtlsMsgStore(WOLFSSL*, word32, word32, const byte*, word32,
  4230. byte, word32, word32, void*);
  4231. WOLFSSL_LOCAL DtlsMsg* DtlsMsgInsert(DtlsMsg*, DtlsMsg*);
  4232. WOLFSSL_LOCAL int DtlsMsgPoolSave(WOLFSSL*, const byte*, word32, enum HandShakeType);
  4233. WOLFSSL_LOCAL int DtlsMsgPoolTimeout(WOLFSSL*);
  4234. WOLFSSL_LOCAL int VerifyForDtlsMsgPoolSend(WOLFSSL*, byte, word32);
  4235. WOLFSSL_LOCAL int VerifyForTxDtlsMsgDelete(WOLFSSL* ssl, DtlsMsg* head);
  4236. WOLFSSL_LOCAL void DtlsMsgPoolReset(WOLFSSL*);
  4237. WOLFSSL_LOCAL int DtlsMsgPoolSend(WOLFSSL*, int);
  4238. #endif /* WOLFSSL_DTLS */
  4239. #if defined(HAVE_SECURE_RENEGOTIATION) && defined(WOLFSSL_DTLS)
  4240. WOLFSSL_LOCAL int DtlsSCRKeysSet(WOLFSSL* ssl);
  4241. WOLFSSL_LOCAL int IsDtlsMsgSCRKeys(WOLFSSL* ssl);
  4242. WOLFSSL_LOCAL int DtlsUseSCRKeys(WOLFSSL* ssl);
  4243. WOLFSSL_LOCAL int DtlsCheckOrder(WOLFSSL* ssl, int order);
  4244. #endif
  4245. WOLFSSL_LOCAL int IsSCR(WOLFSSL* ssl);
  4246. WOLFSSL_LOCAL void WriteSEQ(WOLFSSL* ssl, int verifyOrder, byte* out);
  4247. #if defined(WOLFSSL_TLS13) && (defined(HAVE_SESSION_TICKET) || !defined(NO_PSK))
  4248. WOLFSSL_LOCAL word32 TimeNowInMilliseconds(void);
  4249. #endif
  4250. WOLFSSL_LOCAL word32 LowResTimer(void);
  4251. #ifndef NO_CERTS
  4252. WOLFSSL_LOCAL void InitX509Name(WOLFSSL_X509_NAME*, int, void*);
  4253. WOLFSSL_LOCAL void FreeX509Name(WOLFSSL_X509_NAME* name);
  4254. WOLFSSL_LOCAL void InitX509(WOLFSSL_X509*, int, void* heap);
  4255. WOLFSSL_LOCAL void FreeX509(WOLFSSL_X509*);
  4256. WOLFSSL_LOCAL int CopyDecodedToX509(WOLFSSL_X509*, DecodedCert*);
  4257. #endif
  4258. #ifndef MAX_CIPHER_NAME
  4259. #define MAX_CIPHER_NAME 50
  4260. #endif
  4261. #ifdef WOLFSSL_NAMES_STATIC
  4262. typedef char cipher_name[MAX_CIPHER_NAME];
  4263. #else
  4264. typedef const char* cipher_name;
  4265. #endif
  4266. typedef struct CipherSuiteInfo {
  4267. cipher_name name;
  4268. #ifndef NO_ERROR_STRINGS
  4269. cipher_name name_iana;
  4270. #endif
  4271. byte cipherSuite0;
  4272. byte cipherSuite;
  4273. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || \
  4274. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_NGINX)
  4275. byte minor;
  4276. byte major;
  4277. #endif
  4278. byte flags;
  4279. } CipherSuiteInfo;
  4280. WOLFSSL_LOCAL const CipherSuiteInfo* GetCipherNames(void);
  4281. WOLFSSL_LOCAL int GetCipherNamesSize(void);
  4282. WOLFSSL_LOCAL const char* GetCipherNameInternal(const byte cipherSuite0, const byte cipherSuite);
  4283. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  4284. /* used in wolfSSL_sk_CIPHER_description */
  4285. #define MAX_SEGMENTS 5
  4286. #define MAX_SEGMENT_SZ 20
  4287. WOLFSSL_LOCAL int wolfSSL_sk_CIPHER_description(WOLFSSL_CIPHER*);
  4288. WOLFSSL_LOCAL const char* GetCipherProtocol(const byte minor);
  4289. WOLFSSL_LOCAL const char* GetCipherKeaStr(char n[][MAX_SEGMENT_SZ]);
  4290. WOLFSSL_LOCAL const char* GetCipherAuthStr(char n[][MAX_SEGMENT_SZ]);
  4291. WOLFSSL_LOCAL const char* GetCipherEncStr(char n[][MAX_SEGMENT_SZ]);
  4292. WOLFSSL_LOCAL const char* GetCipherMacStr(char n[][MAX_SEGMENT_SZ]);
  4293. WOLFSSL_LOCAL int SetCipherBits(const char* enc);
  4294. #endif
  4295. WOLFSSL_LOCAL const char* GetCipherNameIana(const byte cipherSuite0, const byte cipherSuite);
  4296. WOLFSSL_LOCAL const char* wolfSSL_get_cipher_name_internal(WOLFSSL* ssl);
  4297. WOLFSSL_LOCAL const char* wolfSSL_get_cipher_name_iana(WOLFSSL* ssl);
  4298. WOLFSSL_LOCAL int GetCipherSuiteFromName(const char* name, byte* cipherSuite0,
  4299. byte* cipherSuite, int* flags);
  4300. enum encrypt_side {
  4301. ENCRYPT_SIDE_ONLY = 1,
  4302. DECRYPT_SIDE_ONLY,
  4303. ENCRYPT_AND_DECRYPT_SIDE
  4304. };
  4305. WOLFSSL_LOCAL int SetKeysSide(WOLFSSL*, enum encrypt_side);
  4306. /* Set*Internal and Set*External functions */
  4307. WOLFSSL_LOCAL int SetDsaInternal(WOLFSSL_DSA* dsa);
  4308. WOLFSSL_LOCAL int SetDsaExternal(WOLFSSL_DSA* dsa);
  4309. #ifndef HAVE_USER_RSA
  4310. WOLFSSL_LOCAL int SetRsaExternal(WOLFSSL_RSA* rsa);
  4311. WOLFSSL_LOCAL int SetRsaInternal(WOLFSSL_RSA* rsa);
  4312. #endif
  4313. WOLFSSL_LOCAL int SetDhInternal(WOLFSSL_DH* dh);
  4314. WOLFSSL_LOCAL int SetDhExternal(WOLFSSL_DH *dh);
  4315. #ifndef NO_DH
  4316. WOLFSSL_LOCAL int DhGenKeyPair(WOLFSSL* ssl, DhKey* dhKey,
  4317. byte* priv, word32* privSz,
  4318. byte* pub, word32* pubSz);
  4319. WOLFSSL_LOCAL int DhAgree(WOLFSSL* ssl, DhKey* dhKey,
  4320. const byte* priv, word32 privSz,
  4321. const byte* otherPub, word32 otherPubSz,
  4322. byte* agree, word32* agreeSz);
  4323. #endif /* !NO_DH */
  4324. #ifdef HAVE_ECC
  4325. WOLFSSL_LOCAL int EccMakeKey(WOLFSSL* ssl, ecc_key* key, ecc_key* peer);
  4326. WOLFSSL_LOCAL word16 GetCurveByOID(int oidSum);
  4327. #endif
  4328. WOLFSSL_LOCAL int InitHandshakeHashes(WOLFSSL* ssl);
  4329. WOLFSSL_LOCAL void FreeHandshakeHashes(WOLFSSL* ssl);
  4330. #ifndef WOLFSSL_NO_TLS12
  4331. WOLFSSL_LOCAL void FreeBuildMsgArgs(WOLFSSL* ssl, BuildMsgArgs* args);
  4332. #endif
  4333. WOLFSSL_LOCAL int BuildMessage(WOLFSSL* ssl, byte* output, int outSz,
  4334. const byte* input, int inSz, int type, int hashOutput,
  4335. int sizeOnly, int asyncOkay, int epochOrder);
  4336. #ifdef WOLFSSL_TLS13
  4337. int BuildTls13Message(WOLFSSL* ssl, byte* output, int outSz, const byte* input,
  4338. int inSz, int type, int hashOutput, int sizeOnly, int asyncOkay);
  4339. #endif
  4340. WOLFSSL_LOCAL int AllocKey(WOLFSSL* ssl, int type, void** pKey);
  4341. WOLFSSL_LOCAL void FreeKey(WOLFSSL* ssl, int type, void** pKey);
  4342. #ifdef WOLFSSL_ASYNC_CRYPT
  4343. WOLFSSL_LOCAL int wolfSSL_AsyncInit(WOLFSSL* ssl, WC_ASYNC_DEV* asyncDev, word32 flags);
  4344. WOLFSSL_LOCAL int wolfSSL_AsyncPop(WOLFSSL* ssl, byte* state);
  4345. WOLFSSL_LOCAL int wolfSSL_AsyncPush(WOLFSSL* ssl, WC_ASYNC_DEV* asyncDev);
  4346. #endif
  4347. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  4348. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  4349. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR)
  4350. WOLFSSL_LOCAL int LoadCertByIssuer(WOLFSSL_X509_STORE* store,
  4351. X509_NAME* issuer, int Type);
  4352. #endif
  4353. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR)
  4354. WOLFSSL_LOCAL WOLFSSL_BY_DIR_HASH* wolfSSL_BY_DIR_HASH_new(void);
  4355. WOLFSSL_LOCAL void wolfSSL_BY_DIR_HASH_free(WOLFSSL_BY_DIR_HASH* dir_hash);
  4356. WOLFSSL_LOCAL WOLFSSL_STACK* wolfSSL_sk_BY_DIR_HASH_new_null(void);
  4357. WOLFSSL_LOCAL int wolfSSL_sk_BY_DIR_HASH_find(
  4358. WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH)* sk, const WOLFSSL_BY_DIR_HASH* toFind);
  4359. WOLFSSL_LOCAL int wolfSSL_sk_BY_DIR_HASH_num(const WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH) *sk);
  4360. WOLFSSL_LOCAL WOLFSSL_BY_DIR_HASH* wolfSSL_sk_BY_DIR_HASH_value(
  4361. const WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH) *sk, int i);
  4362. WOLFSSL_LOCAL WOLFSSL_BY_DIR_HASH* wolfSSL_sk_BY_DIR_HASH_pop(
  4363. WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH)* sk);
  4364. WOLFSSL_LOCAL void wolfSSL_sk_BY_DIR_HASH_pop_free(WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH)* sk,
  4365. void (*f) (WOLFSSL_BY_DIR_HASH*));
  4366. WOLFSSL_LOCAL void wolfSSL_sk_BY_DIR_HASH_free(WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH) *sk);
  4367. WOLFSSL_LOCAL int wolfSSL_sk_BY_DIR_HASH_push(WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH)* sk,
  4368. WOLFSSL_BY_DIR_HASH* in);
  4369. /* WOLFSSL_BY_DIR_entry stuff */
  4370. WOLFSSL_LOCAL WOLFSSL_BY_DIR_entry* wolfSSL_BY_DIR_entry_new(void);
  4371. WOLFSSL_LOCAL void wolfSSL_BY_DIR_entry_free(WOLFSSL_BY_DIR_entry* entry);
  4372. WOLFSSL_LOCAL WOLFSSL_STACK* wolfSSL_sk_BY_DIR_entry_new_null(void);
  4373. WOLFSSL_LOCAL int wolfSSL_sk_BY_DIR_entry_num(const WOLF_STACK_OF(WOLFSSL_BY_DIR_entry) *sk);
  4374. WOLFSSL_LOCAL WOLFSSL_BY_DIR_entry* wolfSSL_sk_BY_DIR_entry_value(
  4375. const WOLF_STACK_OF(WOLFSSL_BY_DIR_entry) *sk, int i);
  4376. WOLFSSL_LOCAL WOLFSSL_BY_DIR_entry* wolfSSL_sk_BY_DIR_entry_pop(
  4377. WOLF_STACK_OF(WOLFSSL_BY_DIR_entry)* sk);
  4378. WOLFSSL_LOCAL void wolfSSL_sk_BY_DIR_entry_pop_free(WOLF_STACK_OF(wolfSSL_BY_DIR_entry)* sk,
  4379. void (*f) (WOLFSSL_BY_DIR_entry*));
  4380. WOLFSSL_LOCAL void wolfSSL_sk_BY_DIR_entry_free(WOLF_STACK_OF(wolfSSL_BY_DIR_entry) *sk);
  4381. WOLFSSL_LOCAL int wolfSSL_sk_BY_DIR_entry_push(WOLF_STACK_OF(wolfSSL_BY_DIR_entry)* sk,
  4382. WOLFSSL_BY_DIR_entry* in);
  4383. #endif /* OPENSSL_ALL && !NO_FILESYSTEM && !NO_WOLFSSL_DIR */
  4384. #ifdef __cplusplus
  4385. } /* extern "C" */
  4386. #endif
  4387. #endif /* wolfSSL_INT_H */