internal.h 256 KB

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