internal.h 210 KB

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