internal.h 196 KB

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