internal.h 241 KB

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